캔틸레버 라인 종료 거래 전략과 결합된 제로 래그 중첩 이동 평균


생성 날짜: 2024-01-22 10:03:05 마지막으로 수정됨: 2024-01-22 10:03:05
복사: 0 클릭수: 1897
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

캔틸레버 라인 종료 거래 전략과 결합된 제로 래그 중첩 이동 평균

개요

이 전략의 주요 아이디어는 0 지연 중첩 이동 평균 ((ZLSMA) 지표가 트렌드 방향을 판단하고, 허브 라인 출구 ((CE) 지표가 더 정확한 진입 및 출구 시기를 찾기 위한 것이다. ZLSMA는 트렌드 지표이며, 트렌드의 변화를 일찍 판단할 수 있다.

전략 원칙

  1. ZLSMA 부분:

    • 선형 회귀 방법을 사용하여 각각 130주기 길이의 LMA선을 계산한다.
    • 두 LMA 줄을 겹쳐서 eq에 부여된 차수를 얻는다.
    • 마지막으로, 원래의 LMA 라인을 통해 eq 차원을 더하여, 0 지연 중첩 이동 평균 ZLSMA 을 구성한다.
  2. CE 부분:

    • ATR 지수를 계산하고, 계수 ((설정 2) 로 가장 가까운 최고점 또는 최저점으로부터의 동적 거리를 결정한다.
    • 클로즈오프가 가장 가까운 다단계 스톱라인이나 공수 스톱라인보다 높을 때 스톱라인을 적절히 조정한다.
    • 클로즈 가격에 대한 스톱 라인의 위치 변화를 판단하여 더 많은 코어 방향을 선택하십시오.
  3. 출입시간:

    • ZLSMA는 트렌드 방향을 판단하고, CE는 신호를 내면 출전한다.
  4. 출전 손실:

    • 장선에는 고정된 스피드 및 스프레이가 있다.
    • 단선으로 CE의 동적 출력을 대체하여 고정 상쇄한다.

우위 분석

  1. ZLSMA는 트렌드를 조기에 판단하여 가짜 돌파구를 피할 수 있습니다.
  2. CE는 시장의 변동에 따라 수출 지점을 유연하게 조정할 수 있다.
  3. 전략적 리스크/이익 비율을 사용자 정의할 수 있습니다.
  4. 장단선은 스톱로스 스을 사용하는 방식이 다르지만, 동시에 위험을 조절할 수 있다.

위험 분석

  1. 파라미터를 잘못 설정하면 출력율이 증가하거나 스톱로스 범위가 넓어질 수 있다.
  2. 그러나, 만약 상황이 급격히 바뀐다면, 제약이 깨질 위험이 있습니다.

최적화 방향

  1. 다른 시장과 시간 주기에서의 파라미터 최적화를 테스트할 수 있다.
  2. 변동률이나 특정 주기에 따라 스톱 스톱 손실 파라미터를 조정하는 것이 고려될 수 있다.
  3. 다른 지표나 모델과 결합하여 수익률을 높일 수 있습니다.

요약하다

이 전략은 주로 트렌드 방향을 판단하기 위해 이동 평균의 0 지연을 겹쳐 사용하며, 낙선 라인 출구 지표와 결합하여 더 정확한 출구 출구 타이밍을 찾습니다. 전략의 장점은 사용자 정의 가능한 스톱 스톱 비율과 낙선 라인 출구의 동적 조정이 시장 상황에 따라 위험을 제어 할 수 있다는 것입니다. 다음 단계는 변수 최적화 및 전략 조합을 시도하여 안정성과 수익률을 더욱 높일 수 있습니다.

전략 소스 코드
/*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")