들리어 출구 거래 전략과 함께 제로 레이그 중복 이동 평균

저자:차오장, 날짜: 2024-01-22 10:03:05
태그:

img

전반적인 설명

이 전략의 주요 아이디어는 트렌드 방향을 판단하기 위해 제로 라그 오버라핑 이동 평균 (ZLSMA) 지표와 좀 더 정확한 진입점과 출구점을 찾기 위해 캔들리어 출구 (CE) 지표를 결합하는 것입니다. ZLSMA는 트렌드 변화를 일찍 식별 할 수있는 트렌드 지표입니다. CE는 ATR을 계산하여 출구점을 동적으로 조정하여 효과적으로 스톱 로스를 제어합니다. 이 전략은 주로 중단기 운영에 적합합니다.

전략 원칙

  1. ZLSMA 부분:

    • 선형 회귀 방법을 사용하여 각각 130기 LMA 라인을 계산합니다.
    • 두 LMA 직선을 겹쳐서
    • 마지막으로, 원래 LMA 선과 eq 차이를 합한 ZLSMA의 제로 레이그 중복 이동 평균을 구성합니다.
  2. CE 부분:

    • ATR 지표를 계산하고 요인으로 곱하여 (예정 2) 가장 최근의 최고 또는 최저 지점으로부터의 동적 거리를 결정합니다.
    • 종료 가격이 가장 최근의 긴 또는 짧은 스톱 로스 라인을 초과하면 그에 따라 스톱 로스 라인을 조정합니다.
    • 스톱 로스 라인에 대한 클로징 가격의 변화에 따라 긴 또는 짧은 방향을 결정합니다.
  3. 입력 신호:

    • ZLSMA는 트렌드 방향을 판단합니다. CE가 신호를 내면 입력합니다.
  4. 출구 스톱 손실:

    • 고정된 스톱 로스 및 장기 포지션에서 수익을 취합니다.
    • 짧은 포지션의 경우, 고정 스톱 로스를 대체하기 위해 CE의 동적 출구를 사용하십시오.

이점 분석

  1. ZLSMA는 잘못된 파장을 피하기 위해 트렌드를 더 일찍 식별할 수 있습니다.
  2. CE는 시장 변동성에 따라 출구 지점을 유연하게 조정할 수 있습니다.
  3. 전략의 맞춤형 위험/이익 비율
  4. 위험 통제를 위해 긴 포지션과 짧은 포지션에서 사용되는 다른 스톱 로스 및 수익을 취하는 방법.

위험 분석

  1. 부적절한 매개 변수 설정은 손실율을 증가시키거나 중지 손실 범위를 확장시킬 수 있습니다.
  2. 시장이 급격히 뒤집어지면 여전히 스톱 로스가 깨질 위험이 있습니다.

최적화 방향

  1. 매개 변수는 다른 시장과 시간 프레임에 최적화 될 수 있습니다.
  2. 변동성이나 특정 주기에 따라 수익/정지 매개 변수를 조정하는 것을 고려하십시오.
  3. 이윤률을 높이기 위해 다른 지표나 모델과 결합해보세요.

요약

이 전략은 주로 트렌드 방향을 결정하기 위해 제로 라그 오버라핑 이동 평균을 사용하고, 더 정확한 입출점과 출출점을 찾기 위해 들리어 출출 지표와 결합합니다. 이점은 사용자 정의 가능한 스톱 / 이윤 비율에 있으며 들리어 출출의 동적 조정으로 시장 조건에 따라 위험을 제어 할 수 있습니다. 다음 단계는 매개 변수 최적화 및 전략 조합으로 안정성과 수익성을 더욱 향상시킬 수 있습니다.


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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © GGkurg

//@version=5

strategy(title = "ZLSMA + Chandelier Exit", shorttitle="ZLSMA + CE", overlay=true)


var GRP1 = "take profit / stop loss"
TP = input(title='long TP%', defval=2.0,   inline = "1", group = GRP1) 
SL = input(title='long SL%', defval=2.0,    inline = "1", group = GRP1) 
TP2 = input(title='short TP', defval=2.0,    inline = "2", group = GRP1) 
SL2 = input(title='short SL', defval=2.0,    inline = "2", group = GRP1) 
//-------------------------------------------------calculations
takeProfitPrice = strategy.position_avg_price * (1+(TP/100))
stopLossPrice = strategy.position_avg_price * (1-(SL/100))
takeProfitPrice2 = strategy.position_avg_price * (1-(TP2/100))
stopLossPrice2 = strategy.position_avg_price * (1+(SL2/100))


//---------------------------------------ZLSMA - Zero Lag LSMA
var GRP2 = "ZLSMA settings"
length1 = input(title='Length', defval=130, inline = "1", group = GRP2) 
offset1 = input(title='Offset', defval=0, inline = "2", group = GRP2) 
src = input(close, title='Source', inline = "3", group = GRP2) 
lsma = ta.linreg(src, length1, offset1)
lsma2 = ta.linreg(lsma, length1, offset1)
eq = lsma - lsma2
zlsma = lsma + eq

plot(zlsma, color=color.new(color.yellow, 0), linewidth=3)


//---------------------------------------ZLSMA conditisions 
//---------long
longc1 = close > zlsma
longclose1 = close < zlsma
//---------short
shortc1 = close < zlsma
shortclose1 = close > zlsma


//---------------------------------------Chandelier Exit
var string calcGroup = 'Chandelier exit settings'
length = input.int(title='ATR Period', defval=1, group=calcGroup)
mult = input.float(title='ATR Multiplier', step=0.1, defval=2.0, group=calcGroup)
useClose = input.bool(title='Use Close Price for Extremums', defval=true, group=calcGroup)

var string visualGroup = 'Visuals'
showLabels = input.bool(title='Show Buy/Sell Labels', defval=true, group=visualGroup)
highlightState = input.bool(title='Highlight State', defval=true, group=visualGroup)

var string alertGroup = 'Alerts'
awaitBarConfirmation = input.bool(title="Await Bar Confirmation", defval=true, group=alertGroup)

atr = mult * ta.atr(length)

longStop = (useClose ? ta.highest(close, length) : ta.highest(length)) - atr
longStopPrev = nz(longStop[1], longStop)
longStop := close[1] > longStopPrev ? math.max(longStop, longStopPrev) : longStop

shortStop = (useClose ? ta.lowest(close, length) : ta.lowest(length)) + atr
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := close[1] < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop

var int dir = 1
dir := close > shortStopPrev ? 1 : close < longStopPrev ? -1 : dir

var color longColor = color.green
var color shortColor = color.red
var color longFillColor = color.new(color.green, 90)
var color shortFillColor = color.new(color.red, 90)
var color textColor = color.new(color.white, 0)

longStopPlot = plot(dir == 1 ? longStop : na, title='Long Stop', style=plot.style_linebr, linewidth=2, color=color.new(longColor, 0))
buySignal = dir == 1 and dir[1] == -1
plotshape(buySignal ? longStop : na, title='Long Stop Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(longColor, 0))
plotshape(buySignal and showLabels ? longStop : na, title='Buy Label', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(longColor, 0), textcolor=textColor)

shortStopPlot = plot(dir == 1 ? na : shortStop, title='Short Stop', style=plot.style_linebr, linewidth=2, color=color.new(shortColor, 0))
sellSignal = dir == -1 and dir[1] == 1
plotshape(sellSignal ? shortStop : na, title='Short Stop Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(shortColor, 0))
plotshape(sellSignal and showLabels ? shortStop : na, title='Sell Label', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(shortColor, 0), textcolor=textColor)

midPricePlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0, display=display.none, editable=false)

longStateFillColor = highlightState ? dir == 1 ? longFillColor : na : na
shortStateFillColor = highlightState ? dir == -1 ? shortFillColor : na : na
fill(midPricePlot, longStopPlot, title='Long State Filling', color=longStateFillColor)
fill(midPricePlot, shortStopPlot, title='Short State Filling', color=shortStateFillColor)

await = awaitBarConfirmation ? barstate.isconfirmed : true
alertcondition(dir != dir[1] and await, title='Alert: CE Direction Change', message='Chandelier Exit has changed direction!')
alertcondition(buySignal and await, title='Alert: CE Buy', message='Chandelier Exit Buy!')
alertcondition(sellSignal and await, title='Alert: CE Sell', message='Chandelier Exit Sell!')




//---------------------------------------Chandelier Exit conditisions 
//---------long
longc2 = buySignal
longclose2 = sellSignal
//---------short
shortc2 = sellSignal
shortclose2 = buySignal



//---------------------------------------Long entry and exit
if longc1 and longc2 
    strategy.entry("long", strategy.long)

if strategy.position_avg_price > 0
    strategy.exit("close long", "long", limit = takeProfitPrice, stop = stopLossPrice, alert_message = "close all orders")

if longclose1 and longclose2 and strategy.opentrades == 1
    strategy.close("long","ema long cross", alert_message = "close all orders")


//---------------------------------------Short entry and exit
if shortc1 and shortc2 
    strategy.entry("short", strategy.short)

if strategy.position_avg_price > 0
    strategy.exit("close short", "short", limit = takeProfitPrice2, stop = stopLossPrice2, alert_message = "close all orders")

if shortclose1 and shortclose2 and strategy.opentrades == 1
    strategy.close("close short","short", alert_message = "close all orders")




더 많은