이중 이동 평균 크로스오버 내일 선물 거래 전략

저자:차오장, 날짜: 2023-11-15 16:48:02
태그:

img

전반적인 설명

이 전략은 이중 이동 평균 크로스오버의 원리를 활용하고, 스톱 로스 및 리프트를 위한 ATR 지표를 통합하고, 선물 계약에 적합한 내일 거래 전략을 설계하기 위해 거래 시간 제어를 추가합니다. 전략은 간단하고 이해하기 쉽기 때문에 초보자에게 이상적입니다.

전략 논리

이 전략은 5주기 및 20주기 WMA 라인 크로스오버를 입점 신호로 사용합니다. 5주기 라인이 20주기 라인 이상에서 깨지면 긴 거리로 이동하고, 5주기 라인이 20주기 라인 아래로 깨지면 짧은 거리로 이동합니다. 또한 50주기 WMA 라인을 사용하여 트렌드 방향을 결정합니다. 거래 신호는 가격 브레이크 방향이 주요 트렌드와 일치할 때만 시작됩니다.

또한, 전략은 동적 스톱 로스 및 수익 수치를 설정하기 위해 ATR 지표를 활용합니다. ATR은 시장의 변동성을 반영합니다. 전략은 스톱 로스 및 수익을 결정하기 위해 ATR 값을 인수 (예를 들어 3) 로 곱하여 거래 손실을 제어합니다.

마지막으로, 이 전략은 잘못된 신호가 쉽게 형성되는 시장 개장 및 폐쇄 주변에서 높은 변동성을 피하기 위해 미국 거래 시간 (9:00-14:30 CST) 에만 거래를 시작합니다.

이점 분석

이 전략은 다음과 같은 장점을 가지고 있습니다.

  1. 이중 이동 평균의 크로스오버는 트렌드 전환점을 적시에 입력하기 위해 효과적으로 포착합니다.

  2. 트렌드 필터는 주요 트렌드에 반하는 거래를 피하고 잘못된 신호를 줄입니다.

  3. 다이내믹한 ATR 기반의 스톱 로스 컨트롤은 트레이드 로스당

  4. 거래시간을 제한하면 변동적인 오픈 및 클로즈 기간을 피할 수 있습니다.

  5. 단순하고 명확한 규칙, 초보자도 쉽게 이해하고 실행할 수 있습니다.

  6. MA 기간, ATR 곱셈, 거래 시간 등 최적화를 위한 사용자 정의 가능한 매개 변수.

위험 분석

이 전략은 또한 다음과 같은 위험을 가지고 있습니다.

  1. 범위 시장에서 더 많은 스톱 로즈 트리거가 발생합니다.

  2. 듀얼 MA 크로스오버는 지연이 있고 단기적인 발병을 놓칠 수 있습니다.

  3. 부적절한 ATR 매개 변수 설정으로 인해 큰 또는 작은 스톱 손실이 발생합니다.

  4. 근본적인 분석 없이 기술적인 지표에만 의존해야 합니다.

  5. 효과는 적절한 상징과 시간 틀에 달려 있습니다.

  6. 기계 시스템은 중재될 위험이 있습니다.

  7. 다른 거래 세션에 따라 변수를 조정해야 합니다.

이러한 것들은 매개 변수 조정, 지표 조합, 선택적 수동 개입 등을 통해 개선될 수 있습니다.

최적화 방향

이 전략은 다음과 같은 측면에서 향상될 수 있습니다.

  1. EMA, DMA 등과 같은 다른 MA 시스템을 테스트합니다.

  2. MACD, RSI 등과 같은 다른 기술적 필터를 추가합니다.

  3. ATR 매개 변수를 최적화하여 더 나은 스톱 손실/이익을 얻습니다.

  4. 고품질의 입력 신호를 찾기 위해 볼륨 지표를 포함합니다.

  5. 기호 특성에 따라 매개 변수를 조정합니다.

  6. 시장에 대한 거래를 피하기 위해 근본적인 요소를 통합합니다.

  7. 시장 모델링을 위해 신경망과 같은 기계 학습을 도입해야 합니다.

  8. 더 많은 기회를 위해 여러 시간 프레임 조합을 탐구하십시오.

  9. 탄력성을 높이기 위한 전략 집합을 구축합니다.

결론

요약하자면, 이것은 라이브 트레이딩을 연습하는 초보자에게 적합한 간단하고 직관적인 전략입니다. 동시에, 더 많은 기술적 지표 또는 기계 학습을 통해 최적화를 위해 엄청난 공간이 남아 있습니다. 기호 및 시장 역학에 기반한 매개 변수 조정도 중요합니다. 전략은 양 거래 초보자에게 참조 프레임워크를 제공하지만 안정적인 이익을 위해 끊임없는 테스트와 향상이 필요합니다.


/*backtest
start: 2023-10-15 00:00:00
end: 2023-11-14 00:00:00
period: 1h
basePeriod: 15m
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/
// © james4392010

//@version=4

strategy(title="DayTradingFutures Cross-Strategy", overlay=true)




// === GENERAL INPUTS ===
Periods = input(title="ATR Period", type=input.integer, defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
//highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2
up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn



wmaFastSource   = input(defval = close, title = "Fast WMA Source")
wmaFastLength   = input(defval = 5, title = "Fast WMA Period")
wmaSlowSource   = input(defval = close, title = "Slow WMA Source")
wmaSlowLength   = input(defval = 20, title = "Slow WMA Period")
wmaDirectionSource  = input(defval = close, title = "Trend 50 Period Source")
wmaDirectionLength  = input(defval = 50, title = "Trend 50 Period")
timeinrange(res, sess) => time(res, sess) != 0



// === SERIES SETUP ===
/// a couple of ma's..
wmaFast = wma(close, 5)
wmaSlow = wma(close, 20)
wmaDirection = wma(close, 50)





// === PLOTTING ===
fast = plot(series=wmaFast, color=color.white, linewidth=2)
slow = plot(series=wmaSlow, color=color.yellow, linewidth=2)
direction = plot(series=wmaDirection, color=color.red, linewidth=2)


// === INPUT BACKTEST RANGE ===

//fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
//fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
//fromYear = input(defval = 2022, title = "From Year", minval = 2022)
 
// To Date Inputs
//toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
//toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
//toYear = input(defval = 2022, title = "To Year", minval = 2022)
//startDate = timestamp(fromYear, fromMonth, fromDay)
//finishDate = timestamp(toYear, toMonth, toDay)
//inDateRange= (time >= fromDay, fromMonth, fromYear and time <= toDay, toMonth, toYear) 



// === FUNCTION EXAMPLE ===
//inDateRange = (time >= fromDay, fromMonth, fromYear) and (time <= toDay, toMonth, toYear)


// === LOGIC ===

enterLong = crossover(wmaFast, wmaSlow) and close > wmaDirection and timeinrange(timeframe.period, "0900-1430")
enterShort = crossunder(wmaFast, wmaSlow) and close < wmaDirection and timeinrange(timeframe.period, "0900-1430")

//trend := nz(trend[1], trend)
//trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
//upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)

buySignal = enterLong 
//plotshape(enterLong ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green)
plotshape(enterLong and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white)
//dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)

sellSignal = enterShort
//plotshape(enterShort ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red)
plotshape(enterShort and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white)
//mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
//longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
//shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
//fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
//fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
alertcondition(buySignal, title="Buy", message="Buy!")
alertcondition(sellSignal, title="Sell", message="Sell!")
//changeCond = trend != trend[1]
//alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")



// Entry for strategy //

//tp=input(25,title="TakeProfit")
//sl=input(40,title="StopLoss")

strategy.entry("Long",1, when=buySignal)
//strategy.exit("Exit",profit=tp,loss=sl)
//strategy.exit("TakeProfit",profit=tp)
//strategy.exit("StopLoss",loss=sl)

strategy.entry("Short",1, when=sellSignal)
//strategy.exit("Exit",profit=tp,loss=sl)
//strategy.exit("TakeProfit",profit=tp)
//strategy.exit("StopLoss",loss=sl)
//strategy.exit("Exit", wmaFastwmaSlow)

//Buy and Sell Signals

//strategy.close_all(when =not timeinrange(timeframe.period, "1000-1430"))   


// === FILL ====

fill (fast, slow, color = wmaSlow > wmaDirection ? color.green : color.red)
//fill(when=enterLong, tp, color = color.new(color.green, 90), title = "Profit area")
//fill(when=enterLong, sl, color = color.new(color.red, 90), title = "Loss area")
//fill(when=enterShort, tp, color = color.new(color.green, 90), title = "Profit area")
//fill(when=enterShort, sl, color = color.new(color.red, 90), title = "Loss area")






더 많은