
이 전략은 다중 주기 이동 평균 대역과 MACD 지표를 결합한 거래 시스템입니다. 전략은 주로 단기 및 장기 이동 평균의 교차와 MACD 지표의 신호를 통해 시장 추세와 거래 시간을 결정합니다. 이 전략은 일일 거래 재설치 논리를 통합하여 야간 위험을 효과적으로 방지합니다.
전략의 핵심 논리는 3개의 주요 부분을 포함합니다: 이동 평균 줄무늬 시스템, MACD 지표 시스템 및 일일 거래 재설정 메커니즘. 이동 평균 줄무늬는 두 개의 다른 주기 ((9 및 21) 의 평행선을 구성하며, SMA, EMA, SMMA, WMA 및 VWMA를 포함한 여러 가지 평행선 유형을 선택할 수 있습니다. MACD 시스템은 표준의 12/26/9 파라미터 설정을 채택하여, 빠른 선과 느린 선의 차치 신호 및 선을 통해 트렌드 움직임의 양을 판단합니다.
이 전략은 평평선띠와 MACD 지표를 결합하여 비교적 완벽한 거래 시스템을 구축한다. 약간의 뒤처짐 위험이 있지만, 합리적인 매개 변수 최적화 및 위험 관리를 통해 전략은 트렌드 시장에서 좋은 효과를 얻을 수 있다. 거래자는 실장에 사용하기 전에 충분한 피드백을 수행하고 특정 시장 특성에 따라 매개 변수 설정을 조정하는 것이 좋습니다.
/*backtest
start: 2024-02-22 00:00:00
end: 2025-02-19 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("Daily MA Ribbon + MACD Crossover with Buy/Sell Signals", overlay=true)
// === Daily Reset Logic ===
var bool newDay = false // Initialize newDay as a boolean variable
newDay := bool(ta.change(time("D"))) // Cast the result of ta.change to boolean
// === Moving Average Ribbon ===
ma(source, length, type) =>
type == "SMA" ? ta.sma(source, length) :
type == "EMA" ? ta.ema(source, length) :
type == "SMMA (RMA)" ? ta.rma(source, length) :
type == "WMA" ? ta.wma(source, length) :
type == "VWMA" ? ta.vwma(source, length) :
na
// MA1 (Short-term MA)
show_ma1 = input(true, "MA №1", inline="MA #1")
ma1_type = input.string("EMA", "", inline="MA #1", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
ma1_source = input(close, "", inline="MA #1")
ma1_length = input.int(9, "", inline="MA #1", minval=1) // Short-term MA (e.g., 9-period)
ma1_color = input(color.blue, "", inline="MA #1")
ma1 = ma(ma1_source, ma1_length, ma1_type)
plot(show_ma1 ? ma1 : na, color = ma1_color, title="MA №1")
// MA2 (Long-term MA)
show_ma2 = input(true, "MA №2", inline="MA #2")
ma2_type = input.string("EMA", "", inline="MA #2", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
ma2_source = input(close, "", inline="MA #2")
ma2_length = input.int(21, "", inline="MA #2", minval=1) // Long-term MA (e.g., 21-period)
ma2_color = input(color.red, "", inline="MA #2")
ma2 = ma(ma2_source, ma2_length, ma2_type)
plot(show_ma2 ? ma2 : na, color = ma2_color, title="MA №2")
// === MACD ===
fast_length = input(12, "Fast Length")
slow_length = input(26, "Slow Length")
signal_length = input.int(9, "Signal Smoothing", minval=1, maxval=50)
sma_source = input.string("EMA", "Oscillator MA Type", options=["SMA", "EMA"])
sma_signal = input.string("EMA", "Signal Line MA Type", options=["SMA", "EMA"])
// Calculate MACD
fast_ma = sma_source == "SMA" ? ta.sma(close, fast_length) : ta.ema(close, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(close, slow_length) : ta.ema(close, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
// Plot MACD
hline(0, "Zero Line", color = color.new(#787B86, 50))
plot(hist, title = "Histogram", style = plot.style_columns, color = (hist >= 0 ? (hist[1] < hist ? #26A69A : #B2DFDB) : (hist[1] < hist ? #FFCDD2 : #FF5252)))
plot(macd, title = "MACD", color = #2962FF)
plot(signal, title = "Signal", color = #FF6D00)
// === Buy/Sell Signal Logic ===
// Condition 1: MA1 (Short-term) crosses above MA2 (Long-term)
ma_crossover = ta.crossover(ma1, ma2)
// Condition 2: MACD line crosses above Signal line
macd_crossover = ta.crossover(macd, signal)
// Buy Signal: Both conditions must be true
buy_signal = ma_crossover and macd_crossover
// Sell Signal: MA1 crosses below MA2 or MACD crosses below Signal
sell_signal = ta.crossunder(ma1, ma2) or ta.crossunder(macd, signal)
// Reset signals at the start of each new day
if (newDay)
buy_signal := false
sell_signal := false
// Plot Buy/Sell Signals
plotshape(buy_signal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(sell_signal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Strategy Entry/Exit
if (buy_signal)
strategy.entry("Buy", strategy.long)
if (sell_signal)
strategy.close("Buy", comment="Sell")