X2-ALGO
X2-ALGO
0 at
https://mozilla.org/MPL/2.0/
// © HasanRifat
//@version=5
indicator("Highly Accurate Reversal with More Signals and Support/Resistance",
overlay = true)
// Input settings
lookback = input.int(defval = 20, title = "Candle Lookback")
confirmation = input.int(defval = 3, title = "Confirm Within")
nonRepaint = input.bool(defval = false, title = "Non-Repainting Mode")
trendFilterPeriod = input.int(defval = 128, title = "Trend Filter Period (EMA)")
rsiPeriod = input.int(14, title="RSI Period")
rsiThreshold = input.int(30, title="RSI Oversold Threshold (More signals)",
minval=1, maxval=50)
atrPeriod = input.int(14, title="ATR Period")
srLookback = input.int(50, title="Support/Resistance Lookback")
// Initialize variables
bullCandle = 0
bearCandle = 0
vup = false
vdn = false
// Detect Bullish Reversal (only in a bearish trend and with oversold RSI)
bullCondition = bullCandle == (lookback - 1) and isBearishTrend and isBullishRSI
and close <= support + atr
if bullCondition
bullActiveCandle := true
bullActiveCandleLow := low
bullActiveCandleHigh := high
bullSignalActive := false
bullCandleCount := 0
if bullActiveCandle
bullCandleCount += 1
// Detect Bearish Reversal (only in a bullish trend and with overbought RSI)
bearCondition = bearCandle == (lookback - 1) and isBullishTrend and isBearishRSI
and close >= resistance - atr
if bearCondition
bearActiveCandle := true
bearActiveCandleLow := low
bearActiveCandleHigh := high
bearSignalActive := false
bearCandleCount := 0
if bearActiveCandle
bearCandleCount += 1
// Alert conditions
alertcondition(vup, "Bullish Reversal", "Bullish Reversal detected")
alertcondition(vdn, "Bearish Reversal", "Bearish Reversal detected")