이중 철도 돌파구 이동 평균 크로스오버 전략

저자:차오장, 날짜: 2023-12-07 15:32:51
태그:

img

전반적인 설명

이중 철도 돌파구 이동 평균 크로스오버 전략은 트렌드를 따르는 양적 거래 전략이다. 이 전략은 시장 트렌드 방향을 판단하기 위해 이중 철도 메커니즘을 사용하여 이동 평균 크로스오버 신호를 결합하여 시장에 진출합니다. 구체적으로 이 전략은 이중 철도를 구축하기 위해 다른 주기의 이동 평균을 사용하여 가격이 상부 또는 하부 철도를 뚫고 있는지에 따라 추세를 판단합니다. 다음으로 진입 시기를 필터링하기 위해 빠르고 느린 이동 평균 크로스오버 신호를 결합합니다.

전략 원칙

이중 철도 돌파구 이동 평균 크로스오버 전략은 다음 부분으로 구성됩니다.

  1. 트렌드 판단 모듈: 이중 레일을 만들기 위해 다른 사이클의 이동 평균을 사용하십시오. 가격이 상단 레일을 통과하면 상승 추세로 판단됩니다. 하단 레일을 통과하면 하향 추세로 판단됩니다.

  2. 입력 모듈: 빠른 이동 평균이 중간 및 긴 이동 평균을 넘을 때 길게 이동하고, 아래로 넘을 때 짧게 이동합니다. 또한 트렌드 방향을 결정해야합니다.

  3. 출구 모듈: 빠른 이동 평균이 중간 및 긴 이동 평균 아래로 넘어가면 포지션을 닫습니다.

이 전략은 우선 트렌드 요구되는 매개 변수를 사용하여 필요한 트렌드 강도를 설정합니다. 가격이 상부 또는 하부 레일을 뚫을 때 트렌드가 형성되었다고 결정됩니다. 그 후, 빠른 이동 평균이 중간 및 긴 이동 평균을 넘을 때 길게 이동합니다. 빠른 이동 평균이 아래를 넘을 때 짧게 이동하십시오. 입력 후 출구 신호로 중간 및 긴 이동 평균 아래를 넘는 빠른 이동 평균을 사용하십시오.

또한 전략에는 스톱 로스 및 영업모듈도 있습니다. 특정 매개 변수를 조정하고 최적화하여 위험과 수익을 제어 할 수 있습니다.

이점 분석

단일 레일 또는 단일 이동 평균 전략에 비해, 이중 레일 돌파구 이동 평균 크로스오버 전략은 트렌드 판단과 입시 시점 선택을 결합하여 시장 리듬을 더 잘 파악 할 수 있습니다. 구체적인 장점은 다음과 같습니다.

  1. 이중 레일 설정은 추세를 더 정확하게 파악하고 놓친 기회를 피할 수 있습니다.

  2. 이동 평균 크로스오버 필터는 잘못된 파열로 인해 역작업의 가능성을 줄일 수 있습니다.

  3. 위험과 수익은 매개 변수를 조정함으로써 최적화 될 수 있습니다.

  4. 전략 논리는 간단하고 명확하고 이해하기 쉽고 추적하기 쉽습니다.

위험 분석

이중 철도 돌파구 이동 평균 크로스오버 전략은 또한 몇 가지 위험을 가지고 있습니다. 주로:

  1. 이중 레일 설정은 여전히 트렌드 잘못된 판단의 가능성을 완전히 제거 할 수 없습니다.

  2. 이동평균 매개 변수들의 부적절한 설정은 과도하게 높은 거래 빈도 또는 역전 거래로 이어질 수 있습니다.

  3. 너무 느슨한 스톱 손실 포인트는 단일 손실을 효과적으로 제어 할 수 없습니다.

이에 대응하는 해결책은 다음과 같습니다.

  1. 이중 레일 매개 변수를 적절하게 조정해

  2. 적당한 거래 빈도를 보장하기 위해 이동 평균 주기 포트폴리오를 최적화합니다.

  3. 최적의 매개 변수를 찾기 위해 다른 Stop Loss 포인트 레벨을 테스트합니다.

최적화 방향

이중 철도 돌파구 이동 평균 크로스오버 전략은 또한 다음과 같은 최적화 가능한 방향을 가지고 있습니다.

  1. 최적의 포트폴리오를 찾기 위해 다른 이동 평균 사이클 매개 변수를 테스트합니다.

  2. 더 많은 이동평균을 추가하여 여러 이동평균 필터링 시스템을 만들 수 있습니다.

  3. 트레일링 스톱 로스, 오시일레이팅 스톱 로스 등 다양한 스톱 로스 알고리즘을 테스트합니다.

  4. 자본 활용 효율을 최적화하기 위해 복합 메커니즘을 추가합니다.

  5. 볼링거 밴드, KDJ 등 필터링을 위한 다른 지표와 결합합니다.

요약

이중 철도 돌파구 이동 평균 크로스오버 전략은 시장 리듬을 효과적으로 파악 할 수있는 트렌드 판단과 엔트리 타이밍 선택을 포괄적으로 고려합니다. 단일 지표와 비교하면이 전략은 더 정확한 판단과 더 나은 필터링의 장점이 있습니다. 매개 변수 및 모듈을 최적화함으로써 전략의 안정성과 수익성을 더욱 향상시킬 것으로 예상됩니다.


/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-12 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
//Author = Dustin Drummond https://www.tradingview.com/u/Dustin_D_RLT/
//Strategy based in part on original 10ema Basic Swing Trade Strategy by Matt Delong: https://www.tradingview.com/u/MattDeLong/
//Link to original 10ema Basic Swing Trade Strategy: https://www.tradingview.com/script/8yhGnGCM-10ema-Basic-Swing-Trade-Strategy/
//This is the Original EMAC - Exponential Moving Average Cross Strategy built as a class for reallifetrading dot com and so has all the default settings and has not been optimized
//I would not recomend using this strategy with the default settings and is for educational purposes only
//For the fully optimized version please come back around the same time tomorrow 6/16/21 for the EMAC - Exponential Moving Average Cross - Optimized
//EMAC - Exponential Moving Average Cross
strategy(title="EMAC - Exponential Moving Average Cross", shorttitle = "EMAC", overlay = true, calc_on_every_tick=false, default_qty_value = 100, initial_capital = 100000, default_qty_type = strategy.fixed, pyramiding = 0, process_orders_on_close=true)
//creates a time filter to prevent "too many orders error" and allows user to see Strategy results per year by changing input in settings in Stratey Tester
startYear = input(2015, title="Start Year", minval=1980, step=1)
timeFilter = (year >= startYear) and (month >= 1) and (dayofmonth >= 1)
//R Size (Risk Amount)
rStaticOrPercent = input(title="R Static or Percent", defval="Static", options=["Static", "Percent"])
rSizeStatic = input(2000, title="R Size Static", minval=1, step=100)
rSizePercent = input(3, title="R Size Percent", minval=.01, step=.01)
rSize = rStaticOrPercent == "Static" ? rSizeStatic : rStaticOrPercent == "Percent" ? (rSizePercent * .01 * strategy.equity) : 1
//Recent Trend Indicator "See the standalone version for detailed description"
res = input(title="Trend Timeframe", type=input.resolution, defval="W")
trend = input(26, minval=1, title="# of Bars for Trend")
trendMult = input(15, minval=0, title="Trend Growth %", step=.25) / 100
currentClose = security(syminfo.tickerid, res, close)
pastClose = security(syminfo.tickerid, res, close[trend])
//Trend Indicator
upTrend = (currentClose >= (pastClose * (1 + trendMult)))
downTrend = (currentClose <= (pastClose * (1 - trendMult)))
sidewaysUpTrend = (currentClose < (pastClose * (1 + trendMult)) and (currentClose > pastClose))
sidewaysDownTrend = (currentClose > (pastClose * (1 - trendMult)) and (currentClose < pastClose))
//Plot Trend on Chart
plotshape(upTrend, "Up Trend", style=shape.square, location=location.top, color=color.green, size=size.small)
plotshape(downTrend, "Down Trend", style=shape.square, location=location.top, color=color.red, size=size.small)
plotshape(sidewaysUpTrend, "Sideways Up Trend", style=shape.square, location=location.top, color=color.yellow, size=size.small)
plotshape(sidewaysDownTrend, "Sideways Down Trend", style=shape.square, location=location.top, color=color.orange, size=size.small)
//What trend signals to use in entrySignal
trendRequired = input(title="Trend Required", defval="Orange", options=["Green", "Yellow", "Orange", "Red"])
goTrend = trendRequired == "Orange" ? upTrend or sidewaysUpTrend or sidewaysDownTrend : trendRequired == "Yellow" ? upTrend or sidewaysUpTrend : trendRequired == "Green" ? upTrend : trendRequired == "Red" ? upTrend or sidewaysUpTrend or sidewaysDownTrend or downTrend : na
//MAs Inputs Defalt is 10 EMA, 20 EMA, 50 EMA, 100 SMA and 200 SMA
ma1Length = input(10, title="MA1 Period", minval=1, step=1)
ma1Type = input(title="MA1 Type", defval="EMA", options=["SMA", "EMA", "WMA"])
ma2Length = input(20, title="MA2 Period", minval=1, step=1)
ma2Type = input(title="MA2 Type", defval="EMA", options=["SMA", "EMA", "WMA"])
ma3Length = input(50, title="MA3 Period", minval=1, step=1)
ma3Type = input(title="MA3 Type", defval="EMA", options=["SMA", "EMA", "WMA"])
ma4Length = input(100, title="MA4 Period", minval=1, step=1)
ma4Type = input(title="MA4 Type", defval="SMA", options=["SMA", "EMA", "WMA"])
ma5Length = input(200, title="MA5 Period", minval=1, step=1)
ma5Type = input(title="MA5 Type", defval="SMA", options=["SMA", "EMA", "WMA"])
//MAs defined
ma1 = ma1Type == "EMA" ? ema(close, ma1Length) : ma1Type == "SMA" ? sma(close, ma1Length) : wma(close, ma1Length)
ma2 = ma2Type == "EMA" ? ema(close, ma2Length) : ma2Type == "SMA" ? sma(close, ma2Length) : wma(close, ma2Length)
ma3 = ma3Type == "EMA" ? ema(close, ma3Length) : ma3Type == "SMA" ? sma(close, ma3Length) : wma(close, ma3Length)
ma4 = ma4Type == "SMA" ? sma(close, ma4Length) : ma4Type == "EMA" ? ema(close, ma4Length) : wma(close, ma4Length)
ma5 = ma5Type == "SMA" ? sma(close, ma5Length) : ma5Type == "EMA" ? ema(close, ma5Length) : wma(close, ma5Length)
//Plot MAs
plot(ma1, title="MA1", color=color.yellow, linewidth=1, style=plot.style_line)
plot(ma2, title="MA2", color=color.purple, linewidth=1, style=plot.style_line)
plot(ma3, title="MA3", color=#00FFFF, linewidth=1, style=plot.style_line)
plot(ma4, title="MA4", color=color.blue, linewidth=2, style=plot.style_line)
plot(ma5, title="MA5", color=color.orange, linewidth=2, style=plot.style_line)
//Allows user to toggle on/off ma1 > ma2 filter
enableShortMAs = input(title="Enable Short MA Cross Filter", defval="Yes", options=["Yes", "No"])
shortMACross = enableShortMAs == "Yes" and ma1 > ma2 or enableShortMAs == "No"
//Allows user to toggle on/off ma4 > ma5 filter
enableLongMAs = input(title="Enable Long MA Cross Filter", defval="Yes", options=["Yes", "No"])
longMACross = enableLongMAs == "Yes" and ma4 >= ma5 or enableLongMAs == "No"
//Entry Signals
entrySignal = (strategy.position_size <= 0 and close[1] < ma1[1] and close > ma1 and close > ma2 and close > ma3 and shortMACross and ma1 > ma3 and longMACross and goTrend)
secondSignal = (strategy.position_size > 0 and close[1] < ma1[1] and close > ma1 and close > ma2 and close > ma3 and shortMACross and ma1 > ma3 and longMACross and goTrend)
plotshape(entrySignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(secondSignal, style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.small)
//ATR for Stops
atrValue = (atr(14))
//to test ATR enable next line
//plot(atrValue, linewidth=1, color=color.black, style=plot.style_line)
atrMult = input(2.5, minval=.25, step=.25, title="Stop ATR Multiple")
//Only target3Mult is used in current strategy target1 and target2 might be used in the future with pyramiding
//target1Mult = input(1.0, minval=.25, step=.25, title="Targert 1 Multiple")
//target2Mult = input(2.0, minval=.25, step=.25, title="Targert 2 Multiple")
target3Mult = input(3.0, minval=.25, step=.25, title="Target Multiple")
enableAtrStop = input(title="Enable ATR Stops", defval="Yes", options=["Yes", "No"])
//Intitial Recomended Stop Location
atrStop = entrySignal and ((high - (atrMult * atrValue)) < low) ? (high - (atrMult * atrValue)) : low
//oneAtrStop is used for testing only enable next 2 lines to test
//oneAtrStop = entrySignal ? (high - atrValue) : na
//plot(oneAtrStop, "One ATR Stop", linewidth=2, color=color.orange, style=plot.style_linebr)
initialStop = entrySignal and enableAtrStop == "Yes" ? atrStop : entrySignal ? low : na
//Stops changed to stoploss to hold value for orders the next line is old code "bug"
//plot(initialStop, "Initial Stop", linewidth=2, color=color.red, style=plot.style_linebr)
//Set Initial Stop and hold value "debug code"
stoploss = valuewhen(entrySignal, initialStop, 0)
plot(stoploss, title="Stop", linewidth=2, color=color.red)
enableStops = input(title="Enable Stops", defval="Yes", options=["Yes", "No"])
yesStops = enableStops == "Yes" ? 1 : enableStops == "No" ? 0 : na
//Calculate size of trade based on R Size
//Original buggy code: 
//positionSize = (rSize/(close - initialStop))
//Added a minimum order size of 1 "debug code"
positionSize = (rSize/(close - initialStop)) > 1 ? (rSize/(close - initialStop)) : 1
//Targets
//Enable or Disable Targets
enableTargets = input(title="Enable Targets", defval="Yes", options=["Yes", "No"])
yesTargets = enableTargets == "Yes" ? 1 : enableTargets == "No" ? 0 : na
//Only target3 is used in current strategy target1 and target2 might be used in the future with pyramiding
//target1 = entrySignal ? (close + ((close - initialStop) * target1Mult)) : na
//target2 = entrySignal ? (close + ((close - initialStop) * target2Mult)) : na
target3 = entrySignal ? (close + ((close - initialStop) * target3Mult)) : na
//plot(target1, "Target 1", linewidth=2, color=color.green, style=plot.style_linebr)
//plot(target2, "Target 2", linewidth=2, color=color.green, style=plot.style_linebr)
plot(target3, "Target 3", linewidth=2, color=color.green, style=plot.style_linebr)
//Set Target and hold value "debug code"
t3 = valuewhen(entrySignal, target3, 0)
//To test t3 and see plot enable next line
//plot(t3, title="Target", linewidth=2, color=color.green)
//MA1 Cross Exit
enableEarlyExit = input(title="Enable Early Exit", defval="Yes", options=["Yes", "No"])
earlyExit = enableEarlyExit == "Yes" ? 1 : enableEarlyExit == "No" ? 0 : na
ma1CrossExit = strategy.position_size > 0 and close < ma1
//Entry Order
strategy.order("Entry", long = true, qty = positionSize, when = (strategy.position_size <= 0 and entrySignal and timeFilter))
//Early Exit Order
strategy.close_all(when = ma1CrossExit and timeFilter and earlyExit, comment = "MA1 Cross Exit")
//Stop and Target Orders
//strategy.cancel orders are needed to prevent bug with Early Exit Order
strategy.order("Stop Loss", false, qty = strategy.position_size, stop=stoploss, oca_name="Exit",when = timeFilter and yesStops, comment = "Stop Loss")
strategy.cancel("Stop Loss", when = ma1CrossExit and timeFilter and earlyExit)
strategy.order("Target", false, qty = strategy.position_size, limit=t3, oca_name="Exit",  when = timeFilter and yesTargets, comment = "Target")
strategy.cancel("Target", when = ma1CrossExit and timeFilter and earlyExit)

더 많은