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/
Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?
//@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")