부피 기반의 동적 DCA 전략

저자:차오장, 날짜: 2024-04-12 17:12:07
태그:QFLDCATPSLATRADXEMASMARSIMACD

img

전반적인 설명

이 전략은 가격 브레이크아웃을 사용하는 볼륨 기반의 동적 DCA 전략이다. 가장 최근의 가격 최저치를 식별하고 가격이 그 최저치를 넘어서 거래량이 증가할 때 포지션을 구축하기 시작합니다. 가격이 계속 떨어질수록 전략은 설정된 총 포지션 수에 도달할 때까지 부동 손실의 크기에 따라 각 포지션의 양을 동적으로 조정합니다. 동시에 전략은 역사적 가격 하락 비율의 중간에 기반하여 수익을 취하는 가격을 설정합니다.

전략 원칙

  1. ta.pivotlow (() 함수를 사용하여 가장 최근의 가격 최저치를 식별하고 지지 수준으로 처리합니다.
  2. 지지 수준을 깨고 후의 역사적인 가격 하락 비율을 계산하고 안전 거리와 수익률 비율을 기준으로 중간값을 사용합니다.
  3. 포지션 구축 신호를 트리거할 때 가격이 지원 수준을 넘어서서 상대적인 거래 부피가 설정된 배수보다 크다.
  4. 설정된 총 포지션 수에 따라 총 자금을 동등한 비율로 나누고 포지션이 생성될 때마다 현재 포지션 수에 따라 포지션 크기를 동적으로 조정하여 포지션 크기의 기하급수적인 성장을 달성합니다.
  5. 포지션 구축 과정에서 변동 손실이 설정된 임계값에 도달하면 전체 포지션 수가 도달할 때까지 포지션을 추가합니다.
  6. 가격이 영업 가격으로 올라갈 때 모든 포지션을 닫습니다.

전략적 장점

  1. 역동적인 포지션 크기 조정: 가격 하락 기간 동안 부동 손실에 따라 각 포지션 크기를 역동적으로 조정함으로써 전략은 위험을 제어하면서 가격 반등 시 더 큰 이익을 허용합니다.
  2. 역사적인 데이터에 기초한 매개 변수 설정: 지원 수준을 깨고 후의 역사적인 가격 하락 비율의 중심을 계산하고 안전 거리와 수익률 비율을 기준으로 사용함으로써 전략 매개 변수는 실제 시장 조건에 더 가깝게 조정됩니다.
  3. 전체 포지션 수 제한: 전체 포지션 수를 설정함으로써 전략은 전체 위험 노출을 제어하고 과도한 포지션으로 인한 과도한 손실을 피합니다.

전략 위험

  1. 지원 수준 실패 위험: 시장이 극단적인 조건에 직면하고 지원 수준을 넘어서도 가격이 계속 급격히 떨어지면 전략의 위치 추가 메커니즘은 상당한 손실을 초래할 수 있습니다.
  2. 매개 변수 설정 위험: 전략의 성능은 매개 변수 설정에 크게 의존합니다. 매개 변수 설정이 잘못되면 전략 성능이 떨어질 수 있습니다.
  3. 영업 가격 설정 위험: 영업 가격이 너무 높게 설정되면 잠재적 인 이익이 놓칠 수 있습니다. 너무 낮게 설정되면 포지션이 너무 일찍 닫히고 가격 리바운드를 완전히 활용 할 수있는 기회를 놓칠 수 있습니다.

전략 최적화 방향

  1. 더 많은 지표를 도입: 포지션 구축 신호를 결정할 때 신호 정확성을 향상시키기 위해 RSI와 MACD와 같은 더 많은 기술적 지표를 도입 할 수 있습니다.
  2. 자금 관리 최적화: 시장 변동성 및 계정 위험 용도와 같은 요소를 기반으로 각 포지션에 대한 자금 비율을 역동적으로 조정하여 위험을 더 잘 제어합니다.
  3. 적응성 있는 취득 및 중지 손실: 시장 변화에 더 잘 적응하기 위해 시장 변동성의 변화에 따라 취득 및 중지 손실 비율을 동적으로 조정합니다.

요약

역동적으로 포지션 크기를 조정하고 역사적 데이터에 기반한 매개 변수를 설정함으로써, 이 전략은 가격 리바운드를 통해 더 큰 수익을 추구하면서 위험을 제어하는 것을 목표로 한다. 그러나 전략의 성능은 매개 변수 설정과 시장 조건에 크게 의존하고 있으며, 위험은 여전히 존재한다. 더 많은 지표를 도입하고, 자금 관리를 최적화하고, 적응적인 영리 및 스톱 로스를 사용하여 전략의 성능을 더욱 향상시킬 수 있다.


/*backtest
start: 2024-04-04 00:00:00
end: 2024-04-11 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AHMEDABDELAZIZZIZO

//@version=5

strategy("Qfl Dca strategy", overlay=true)

// Parameters
swing = input(3 , title = "Swing Points")
mediandropmult = input.float(1.1, "Median drop Mult", step=0.1 , tooltip = "The script Calculate The Median Drop for all last Bases That Was cracked you can Increase or decrease it")
floatinglossvalue = input(-5 , "Floating Loss" , tooltip = "Position Floating Loss to start firs DCA order")
num_orders = input(5 , "Number of all orders" , tooltip = " The number of orders is including the base order and the DCA orders the script will alculate every order qty based on the orders number So that the position size doubles with every order")
length = input(20, title="Length of relative volume" ,tooltip =  " the length of relative volume indicator")
mult = input(2.0, title="Volume Multiplier" , tooltip = "you can adjust the relative volume multiplier to find best parameter")
tpmult = input.float(1, step=0.1 ,title = "Take Profit Multiplier" ,tooltip =  " By default, the script is set to take profits based on the same median drop percent you can adjust it as you like")



// Pivot Calculation
p = ta.pivotlow(low, swing, swing)
v = ta.valuewhen(p, low[swing], 0)

// Variables
var float[] lows = array.new_float()
var float chn = na

// Calculate drops
if v < v[1]
    chn := (v[1] - v) / v[1] * 100
    if array.size(lows) < 4000
        array.push(lows, chn)
    else
        array.shift(lows)
        array.push(lows, chn)

mediandrop = array.avg(lows)
maxdrop = array.max(lows)
mindrop = array.min(lows)

// Table display
textcolor = color.white
// tabl = table.new(position=position.top_right, columns=4, rows=4)
// table.cell(table_id=tabl, column=1, row=1, text="Avg Drop %", width=15, text_color=textcolor)
// table.cell(table_id=tabl, column=2, row=1, text="Min Drop %", width=15, text_color=textcolor)
// table.cell(table_id=tabl, column=3, row=1, text="Max Drop %", width=15, text_color=textcolor)
// table.cell(table_id=tabl, column=1, row=2, text=str.tostring(mediandrop), width=10, text_color=textcolor)
// table.cell(table_id=tabl, column=2, row=2, text=str.tostring(mindrop), width=10, text_color=textcolor)
// table.cell(table_id=tabl, column=3, row=2, text=str.tostring(maxdrop), width=10, text_color=textcolor)

// Plot support
t = fixnan(ta.pivotlow(low, swing, swing))
plot(t, color=ta.change(t) ? na : #03f590b6, linewidth=3, offset=-(swing), title="Support")

// Calculate relative volume
avgVolume = ta.sma(volume, length)
relVolume = volume / avgVolume

// Base Activation
var bool baseisactive = na
if not na(p)
    baseisactive := true

// Buy Signal Calculation
buyprice = v * (1 - (mediandrop / 100) * mediandropmult)
signal = close <= buyprice and relVolume > mult and baseisactive

// Take Profit Calculation
tpsl = (mediandrop / 100)
tp = (strategy.position_avg_price * (1 + (tpsl * tpmult)))

// Position Sizing
capital_per_order(num_orders, equity) =>
    equity / math.pow(2, (num_orders - 1))

equity_per_order = capital_per_order(num_orders, strategy.equity)

qty_per_order(equity_per_order, order_number) =>
    equity_per_order * order_number / close

// Calculate floating loss
floatingLoss = ((close - strategy.position_avg_price) / strategy.position_avg_price) * 100

// Strategy Entries
if signal and strategy.opentrades == 0
    strategy.entry("Buy", strategy.long, qty=qty_per_order(equity_per_order, 1))
    baseisactive := false

for i = 1 to num_orders -1
    if signal and strategy.opentrades == i and floatingLoss <= floatinglossvalue
        strategy.entry("Buy", strategy.long, qty=qty_per_order(equity_per_order, i), comment="DCA Order" + str.tostring(i))
        baseisactive := false

// Strategy Exit
strategy.exit("exit", "Buy", limit=tp)

// Plot
plot(strategy.position_avg_price, color=color.rgb(238, 255, 0), style=plot.style_linebr, linewidth=2)


관련

더 많은