yongyuth.rootwararit

MTF MACD 2 By Yuthavithi

If you want a good strategy without repaint. This one might be for you. Excellent profitable for BTCUSD3M for OKCoin.
It uses multiple time frame MACD for trading decision. To avoid repaint, set the delay period = 1 for both long term and midterm.

The idea is that, if long term, mid term and current time frame all agree on traidng direction, the trade will take place.

I also uses it in my automated trading bot with good result.

www.tradingview.com/chart/bqTqDbEw/
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?
//@version=2
strategy("MTF MACD 2", title = "MultiMACD2", overlay=true)

longTermTimeFrame = input(1440, minval=1, title = "Long Term Time Frame")
longTermDelayPeriod = input(0, minval = 0, title = "Long Term Delay Period")
midTermTimeFrame = input(240, minval=1, title = "Mid Term Time Frame")
midTermDelayPeriod = input(1, minval = 0, title = "Mid Term Delay Period")
tradeOnLongTermTrendDirection = input(true, type = bool, title = "Trade On LongTerm Trend Direction")

//shortTermTimeFrame = input(60, minval=1, title="Short Term Time Frame")
tpPercent = input(5, type=float, title = "Take Profit Percent")
slPercent = input(10, type=float, title = "Stop Loss Percent")
useTP = input(false, type=bool, title = "Use Take Profit / Stop Loss")

tp = (close * tpPercent / 100) / syminfo.mintick
sl = (close * slPercent / 100) / syminfo.mintick

fastMA = ema(ohlc4, 12)
slowMA = ema(ohlc4, 26)
macd = fastMA - slowMA
signal = sma(macd, 9)
hist = macd - signal

lMACD = security(tickerid, tostring(longTermTimeFrame), macd)
lSignal = security(tickerid, tostring(longTermTimeFrame), signal)
lHistLine = security(tickerid, tostring(longTermTimeFrame), hist)
lIdx = round(longTermTimeFrame / interval)

mMACD = security(tickerid, tostring(midTermTimeFrame), macd)
mSignal = security(tickerid, tostring(midTermTimeFrame), signal)
mHistLine = security(tickerid, tostring(midTermTimeFrame), hist)
mIdx = round(midTermTimeFrame / interval)

lUp = lHistLine[longTermDelayPeriod * lIdx] > lHistLine[(longTermDelayPeriod + 1) * lIdx]
lDn = lHistLine[longTermDelayPeriod * lIdx] < lHistLine[(longTermDelayPeriod + 1) * lIdx]

mUp = mHistLine[midTermDelayPeriod * mIdx] > mHistLine[(midTermDelayPeriod + 1) * mIdx]
mDn = mHistLine[midTermDelayPeriod * mIdx] < mHistLine[(midTermDelayPeriod + 1) * mIdx]

sUp = hist[midTermDelayPeriod] > hist[midTermDelayPeriod + 1]
sDn = hist[midTermDelayPeriod] < hist[midTermDelayPeriod + 1]

trendUp = lSignal[longTermDelayPeriod * lIdx] > 0
trendDown = lSignal[longTermDelayPeriod * lIdx] < 0

longExit = lDn and mDn and sDn 
shortExit = lUp and mUp and sUp

long = (lUp and mUp and sUp) and (tradeOnLongTermTrendDirection ? trendUp : true)
short = (lDn and mDn and sDn) and (tradeOnLongTermTrendDirection ? trendDown : true)


barcolor(lUp and mUp and sUp ? lime : lUp and mUp and sDn ?  green : lUp and mDn and sDn ? teal : lUp and mDn and sUp ? blue : lDn and mDn and sDn ? red : lDn and mDn and sUp ? orange : lDn and mUp and sUp ? yellow : lDn and mUp and sDn ? maroon : white)


if (long)
    strategy.entry("Long", strategy.long) //comment = tostring(hisline[macdTimeFrame / interval]))
    if (useTP)
        strategy.exit("Exit Long", "Long", profit =  tp, loss = sl)

        
if (longExit)
    strategy.close("Long")
    
if (short)
    strategy.entry("Short", strategy.short)
    if (useTP)
        strategy.exit("Exit Short", "Short", profit =  tp, loss =  sl)


if (shortExit)
    strategy.close("Short")