MACD와 SMA 200 콤보 전략

저자:차오장, 날짜: 2023-09-11 17:32:34
태그:

이 전략은 전통적인 MACD 지표와 200주기 SMA 이동 평균을 결합하여 거래 신호를 생성합니다.

특히, MACD 히스토그램과 모멘텀이 모두 0보다 높을 때 길어집니다. 빠른 MA는 느린 MA보다 높습니다. 200 기간 SMA 이상의 가격은 상승 편향의 두 번째 필터로 사용됩니다. 반대 논리는 쇼트를 유발합니다.

이 전략의 장점은 MACD를 단기 트렌드 및 리듬, SMA를 장기 트렌드 방향에 활용하는 것입니다. 조합은 정확성을 향상시키고 윙사우를 피합니다. 그러나 MACD와 SMA 모두 지연 문제가 있으며 즉시 반전을 감지 할 수 없습니다.

요약하자면, MACD 및 SMA 200 컴보 전략은 중장기 보유에 적합합니다. 주요 트렌드 변화 지점을 효과적으로 포착합니다. 그러나 상위 / 하위 추격을 피하기 위해 지표 신호의 타이밍에주의가 필요합니다.


/*backtest
start: 2023-08-11 00:00:00
end: 2023-09-10 00:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy("MACD + SMA 200 Strategy (by ChartArt)", shorttitle="CA_-_MACD_SMA_strategy", overlay=true)

// ChartArt's MACD + SMA 200 Strategy
//
// Version 1.0
// Idea by ChartArt on November 30, 2015.
//
// Here is a combination of the MACD with the
// slow moving average SMA 200 as a strategy.
//
// This strategy goes long if the MACD histogram
// and the MACD momentum are both above zero and
// the fast MACD moving average is above the
// slow MACD moving average. As additional long filter
// the recent price has to be above the SMA 200.
// If the inverse logic is true, the strategy
// goes short. For the worst case there is a
// max intraday equity loss of 50% filter.


// Input
source = input(close)
fastLength = input(12, minval=1, title="MACD fast moving average")
slowLength=input(26,minval=1, title="MACD slow moving average")
signalLength=input(9,minval=1, title="MACD signal line moving average")
veryslowLength=input(200,minval=1, title="Very slow moving average")
switch1=input(true, title="Enable Bar Color?")
switch2=input(true, title="Enable Moving Averages?")
switch3=input(true, title="Enable Background Color?")

// Calculation
fastMA = sma(source, fastLength)
slowMA = sma(source, slowLength)
veryslowMA = sma(source, veryslowLength)
macd = fastMA - slowMA
signal = sma(macd, signalLength)
hist = macd - signal

// Colors
MAtrendcolor = change(veryslowMA) > 0 ? green : red
trendcolor = fastMA > slowMA and change(veryslowMA) > 0 and close > slowMA ? green : fastMA < slowMA and change(veryslowMA) < 0 and close < slowMA ? red : blue
bartrendcolor = close > fastMA and close > slowMA and close > veryslowMA and change(slowMA) > 0 ? green : close < fastMA and close < slowMA and close < veryslowMA and change(slowMA) < 0 ? red : blue
backgroundcolor = slowMA > veryslowMA and crossover(hist, 0) and macd > 0 and fastMA > slowMA and close[slowLength] > veryslowMA ? green : slowMA < veryslowMA and crossunder(hist, 0) and macd < 0 and fastMA < slowMA and close[slowLength] < veryslowMA ? red : na
bgcolor(switch3?backgroundcolor:na,transp=80)
barcolor(switch1?bartrendcolor:na)

// Output
F=plot(switch2?fastMA:na,color=trendcolor)
S=plot(switch2?slowMA:na,color=trendcolor,linewidth=2)
V=plot(switch2?veryslowMA:na,color=MAtrendcolor,linewidth=4)
fill(F,V,color=gray)

// Strategy
buyprice = low
sellprice = high
cancelLong = slowMA < veryslowMA
cancelShort = slowMA > veryslowMA

if (cancelLong)
    strategy.cancel("MACDLE")

if crossover(hist, 0) and macd > 0 and fastMA > slowMA and close[slowLength] > veryslowMA 
    strategy.entry("MACDLE", strategy.long, stop=buyprice, comment="Bullish")

if (cancelShort)
    strategy.cancel("MACDSE")

if crossunder(hist, 0) and macd < 0 and fastMA < slowMA and close[slowLength] < veryslowMA 
    strategy.entry("MACDSE", strategy.short, stop=sellprice, comment="Bearish")

maxIdLossPcnt = input(50, "Max Intraday Loss(%)", type=float)
// strategy.risk.max_intraday_loss(maxIdLossPcnt, strategy.percent_of_equity)

//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)

더 많은