Reversal Algo
Reversal Algo
// Input parameters
alertLong = input.bool(true, title="Long Alert", group="Alerts")
alertShort = input.bool(true, title="Short Alert", group="Alerts")
// Calculate MACD
[macd, signal, hist] = ta.macd(macd_src, macd_fast, macd_slow, macd_signal_ema)
cross_UP = ta.crossover(macd, signal)
cross_DN = ta.crossunder(macd, signal)
// RSI
rsiPeriod = input.int(14, "RSI Length", group="RSI Settings")
rsisrc = input.source(close, "RSI Source", group="RSI Settings")
rsi = ta.rsi(rsisrc, rsiPeriod)
rsisignal = rsi - 50
// Color Settings
gradientRange = input.int(2000, title="Gradient Range", minval=500, step=500,
group="Colors")
// Calculate volatility
atr = ta.atr(volatilityPeriod)
upperBand = (high + low) / 2 + atr * multiplier
lowerBand = (high + low) / 2 - atr * multiplier
// Change bar color based on MACD histogram power and RSI signal
barcolor(na(histPower) ? color.purple :
bullishTrend ? color.from_gradient(histPower, 0, gradientRange,
color.rgb(0, 255, 0), color.rgb(0, 150, 0)) :
bearishTrend ? color.from_gradient(histPower, 0, gradientRange,
color.rgb(255, 0, 0), color.rgb(150, 0, 0)) :
color.from_gradient(histPower, 0, gradientRange, color.rgb(150, 0 , 0),
color.rgb(0, 150, 0)))
plotshape(showDots and cross_UP and rsisignal <= 0 and (not signalFilter or close >
smoothedSupportZoneEnd), title="Buy", color=color.rgb(0, 255, 0),
style=shape.triangleup, location=location.belowbar, size=size.tiny, text="Buy",
textcolor=color.white)
plotshape(showDots and cross_DN and rsisignal >= 0 and (not signalFilter or close <
smoothedResistanceZoneStart), title="Sell", color=color.rgb(255, 0, 0),
style=shape.triangledown, location=location.abovebar, size=size.tiny, text="Sell",
textcolor=color.white)
// Alerts
if alertLong and cross_UP and (not signalFilter or close > smoothedSupportZoneEnd)
alert(alertMessage("Buy"), alert.freq_once_per_bar_close)