AlphaTrend use mfi

Author: 发明者量化, Date: 2022-04-28 17:53:04
Tags: ATR

img


/*backtest
start: 2021-05-05 00:00:00
end: 2022-05-04 23:59:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
*/


indicator('AlphaTrend', shorttitle='AT', overlay=true)

coeff = input.float(5, 'Multiplier')
AP = input(14, 'Common Period')
ATR = ta.sma(ta.tr, AP)
src = input.source(close, "source")
upT = low - ATR * coeff
downT = high + ATR * coeff
AlphaTrend = 0.0
AlphaTrend := ta.mfi(hlc3, 14) >= 50 ? upT < nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : upT : downT > nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : downT

plot(AlphaTrend)

if ta.crossover(low, AlphaTrend)
    strategy.entry("BUY", strategy.long)
else if ta.crossunder(high, AlphaTrend)
    strategy.entry("SELL", strategy.short, when=ta.crossunder(high, AlphaTrend))



Related

More