거래량에 따른 DCA 전략의 동적 조정

QFL DCA TP SL ATR ADX EMA SMA RSI MACD
생성 날짜: 2024-04-12 17:12:07 마지막으로 수정됨: 2024-04-12 17:12:07
복사: 5 클릭수: 995
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

거래량에 따른 DCA 전략의 동적 조정

개요

이 전략은 거래량과 가격 돌파구를 기반으로 한 동적 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)