범위 볼륨을 통한 포지션 증가를 위한 DCA 전략


생성 날짜: 2023-09-21 10:41:52 마지막으로 수정됨: 2023-09-21 10:41:52
복사: 0 클릭수: 806
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

개요

이 전략은 범위량 지표와 DCA 포장 로봇의 전략을 결합하여, 범위량 지표가 신호를 발산할 때 DCA 로봇의 파라미터를 사용하여 포장을 만든다. 이 전략은 낮은 비용으로 포장을 추격하는 경향에서 이익을 얻으려고 한다.

전략 원칙

  1. 범위를 측정하여 판단하는 것은 획기적입니다.
  2. 파격에 더 많은 입장을 취하고, 하락에 더 많은 입장을 취합니다.
  3. DCA 로봇의 매개 변수를 계산합니다. 보안 주문 가격, 수, 최대 보안 주문 수 등이 포함됩니다.
  4. 가격이 보안 주문 가격을 촉발할 때 포지션을 추가합니다.
  5. 이윤 목표가 달성되거나 최대 안전 주문을 초과했을 때 정지

구체적으로, 이 전략은 범주량 지표의 양력 분석과 DCA 로봇의 부가 메커니즘을 결합한다. 그 양량이 근래 최고점을 초과할 때 여러 신호를 생성하고 출장하고, 이후 DCA 파라미터에 따라 가격이 하락할 때 각 층의 안전 주문 가격으로 부가한다. 이 전략은 추세를 추적할 수 있지만, 손해 중지 제한이 있다.

우위 분석

  1. 범위량 지표 판단 능력과 결합하여 입시 정확도를 높인다.
  2. 가증기계는 낮은 비용으로 트렌드를 추적할 수 있습니다.
  3. 시장 환경에 맞게 DCA 파라미터를 유연하게 구성할 수 있다
  4. 제약 및 손해 방지 장치로 위험을 통제할 수 있습니다.

위험 분석

  1. “기준은 실패의 위험을 판단하고, 잘못된 방향으로 진출할 수 있다”.
  2. 너무 많은 DCA 가설, 비용, 위험 증가
  3. DCA 파라미터를 적절하게 조정해야 합니다. 그렇지 않으면 효과가 좋지 않을 수 있습니다.
  4. 단위 손실을 확대할 수 있는 잘못된 정지 위치 설정

최적화된 파라미터 구성, 트렌드 필터 도입 등의 방법으로 위험을 줄일 수 있다.

최적화 방향

  1. 다양한 양변수 조합을 테스트하여 최적의 변수를 찾습니다.
  2. DCA 파라미터를 최적화하여 다양한 품종과 주기에 적합하다
  3. 모바일 스톱로스를 추가하여 실시간 가격 변화를 추적합니다.
  4. 트렌드가 커지면 재입학 조건이 추가됩니다.
  5. 트렌드 필터링을 사용하여 잘못된 진입을 방지합니다.
  6. 다른 손해 방지 알고리즘의 우수성과 약점을 비교하여 최적의 구성을 찾습니다.

요약하다

이 전략은 범위량과 DCA 메커니즘을 결합하여 수량으로 신호 입력을 확대하고, 낮은 비용으로 포지션을 따라가는 경향이 있다. 장점은 자금 사용 효율이 높고, 구성성이 강하다. 단점은 매개 변수 최적화에 크게 의존한다. 매개 변수 최적화, 손해 중지 최적화 등의 방법으로 우위를 유지하면서 위험을 줄일 수 있다. 이 전략은 거래자가 지표와 로봇 조정 거래 전략을 작동하는 방법을 습득할 수 있다.

전략 소스 코드
/*backtest
start: 2022-09-20 00:00:00
end: 2023-09-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
args: [["v_input_8",500]]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Ranged Volume DCA Strategy - R3c0nTrader ver 2022-04-19
// For backtesting with 3Commas DCA Bot settings
// Thank you "EvoCrypto" for granting me permission to use "Ranged Volume" to create this strategy
// Thank you "junyou0424" for granting me permission to use "DCA Bot with SuperTrend Emulator" which I used for adding bot inputs, calculations, and strategy
//@version=5
strategy("Ranged Volume DCA Strategy - R3c0nTrader", shorttitle="Ranged Vol DCA Strategy", format=format.volume, overlay=true, pyramiding=999, default_qty_type=strategy.cash, initial_capital=50000, commission_value=0.0)

// INPUTS {
// Start and End Dates
i_startTime = input(defval=timestamp('01 Jan 2015 00:00 +0000'), title='Start Time')
i_endTime = input(defval=timestamp('31 Dec 2050 23:59 +0000'), title='End Time')
inDateRange = true

//Ranged Volume Settings
Range_Length    =   input.int(5,        title="Volume Range Length",                       minval=1)

Heikin_Ashi     =   input(true,     title="Heikin Ashi  (Try toggling for different results)")
Display_Bars    =   input(true,     title="Show Bar Colors")
Display_Break   =   input(true,     title="Show Break-Out")
Display_Range   =   input(true,     title="Show Range")

truncate(number, decimals) =>
    factor = math.pow(10, decimals)
    int(number * factor) / factor

// Strategy Inputs
//sourceInput = input.source(close, "Source")
sourceInput = close
price_deviation = input.float(6.0, title='Price deviation to open safety orders (%)', step=0.25, minval=0.0) / 100
take_profit = input.float(22.0, title='Target Take Profit (%)', step=0.5, minval=0.0) / 100
trailing = input.float(0.0, title='Trailing deviation. Default= 0.0 (%)', step=0.5, minval=0.0) / 100
base_order = input(100.0, title='Base order')
safe_order = input(500.0, title='Safety order')
safe_order_volume_scale = input.float(2.0, step=0.5, title='Safety order volume scale')
safe_order_step_scale = input.float(1.4, step=0.1, title='Safety order step scale')
max_safe_order = input(5, title='Max safety orders')

var current_so = 0
var initial_order = 0.0
var previous_high_value = 0.0
var original_ttp_value = 0.0
// Calculate our key levels
take_profit_level = strategy.position_avg_price * (1 + take_profit)

// }


// SETTINGS {
Close = Heikin_Ashi ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close) : close
//Close = Heikin_Ashi ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close) : sourceInput
Open = Heikin_Ashi ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open) : open


Positive        =    volume
Negative        =   -volume

Highest         =   ta.highest(volume, Range_Length)
Lowest          =   ta.lowest(-volume, Range_Length)

Up              =   Highest > Highest[1] and Close > Open
Dn              =   Highest > Highest[1] and Close < Open

Volume_Color = 
 Display_Break and Up ? color.new(#ffeb3b, 20) : 
 Display_Break and Dn ? color.new(#f44336, 20) : 
 Close > Open ? color.new(#00c0ff, 20) : 
 Close < Open ? color.new(#0001f6, 20) : na
// }

//Plot bar color for volume range indicator
barcolor(Volume_Color, title='Ranged Volume Bar Coloring: (You must disable bar coloring in any studies you added or this may not work properly)')
//barcolor(Display_Bars ? Volume_Color : na)

//

// First Position
if strategy.position_size == 0 and sourceInput > 0 and (Up) and inDateRange
    strategy.entry('Long @' + str.tostring(sourceInput)+'💎✋🤚', strategy.long, qty=base_order / sourceInput)
    initial_order := sourceInput
    current_so := 1
    previous_high_value := 0.0
    original_ttp_value := 0
    original_ttp_value

threshold = 0.0

if safe_order_step_scale == 1.0
    threshold := initial_order - initial_order * price_deviation * safe_order_step_scale * current_so
    threshold

else if current_so <= max_safe_order
    threshold := initial_order - initial_order * ((price_deviation * math.pow(safe_order_step_scale, current_so) - price_deviation) / (safe_order_step_scale - 1))
    threshold

else if current_so > max_safe_order
    threshold := initial_order - initial_order * ((price_deviation * math.pow(safe_order_step_scale, max_safe_order) - price_deviation) / (safe_order_step_scale - 1))
    threshold
    

// Average Down
if current_so > 0 and sourceInput <= threshold and current_so <= max_safe_order and previous_high_value == 0.0
    strategy.entry('😨🙏 SO ' + str.tostring(current_so) + '@' + str.tostring(sourceInput), direction=strategy.long, qty=safe_order * math.pow(safe_order_volume_scale, current_so - 1) / sourceInput)
    current_so += 1
    current_so

// Take Profit!
if take_profit_level <= sourceInput and strategy.position_size > 0 or previous_high_value > 0.0
    if trailing > 0.0
        if previous_high_value > 0.0
            if sourceInput >= previous_high_value
                previous_high_value := sourceInput
                previous_high_value
            else
                previous_high_percent = (previous_high_value - original_ttp_value) * 1.0 / original_ttp_value
                current_high_percent = (sourceInput - original_ttp_value) * 1.0 / original_ttp_value
                if previous_high_percent - current_high_percent >= trailing
                    strategy.close_all(comment='Close (trailing) @' + str.tostring(truncate(current_high_percent * 100, 3)) + '%')
                    current_so := 0
                    previous_high_value := 0
                    original_ttp_value := 0
                    original_ttp_value
        else
            previous_high_value := sourceInput
            original_ttp_value := sourceInput
            original_ttp_value
    else
        strategy.close_all(comment='💰 Close @' + str.tostring(sourceInput))
        current_so := 0
        previous_high_value := 0
        original_ttp_value := 0
        original_ttp_value

// Plot TP
plot(strategy.position_size > 0 ? take_profit_level : na, style=plot.style_linebr, color=color.green, linewidth=2, title="Take Profit")

// Plot All Safety Order lines except for last one as bright blue
plot(strategy.position_size > 0 and current_so <= max_safe_order and current_so > 0 ? threshold : na, style=plot.style_linebr, color=color.new(#00ffff,0), linewidth=2, title="Safety Order")

// Plot Last Safety Order Line as Red
plot(strategy.position_size > 0 and current_so > max_safe_order ? threshold : na, style=plot.style_linebr, color=color.red, linewidth=2, title="No Safety Orders Left")

// Plot Average Position Price Line as Orange
plot(strategy.position_size > 0 ? strategy.position_avg_price : na, style=plot.style_linebr, color=color.orange, linewidth=2, title="Avg Position Price")

// Fill TP Area and SO Area
h1 = plot(strategy.position_avg_price, color=color.new(#000000,100), title="Avg Price Plot Area", display=display.none, editable=false)
h2 = plot(take_profit_level, color=color.new(#000000,100), title="Take Profit Plot Area", display=display.none, editable=false)
h3 = plot(threshold, color=color.new(#000000,100), title="SO Plot Area", display=display.none, editable=false)

// TP Area
fill(h1,h2,color=color.new(#38761d,70), title="Take Profit Plot Area")
// Current SO Area
fill(h1,h3,color=color.new(#3d85c6,70), title="SO Plot Area")