0% found this document useful (0 votes)
27 views

X2-ALGO

This document contains a TradingView script for a technical indicator designed to identify highly accurate reversal signals based on various market conditions. It incorporates filters such as trend direction, RSI levels, and support/resistance levels to enhance signal reliability. The script also includes non-repainting features and alert conditions for bullish and bearish reversals.

Uploaded by

Aj Deshmukh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

X2-ALGO

This document contains a TradingView script for a technical indicator designed to identify highly accurate reversal signals based on various market conditions. It incorporates filters such as trend direction, RSI levels, and support/resistance levels to enhance signal reliability. The script also includes non-repainting features and alert conditions for bullish and bearish reversals.

Uploaded by

Aj Deshmukh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

// This source code is subject to the terms of the Mozilla Public License 2.

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

var bullActiveCandle = false


var bullActiveCandleLow = 0.0
var bullActiveCandleHigh = 0.0
var bullSignalActive = false
var bullCandleCount = 0

var bearActiveCandle = false


var bearActiveCandleLow = 0.0
var bearActiveCandleHigh = 0.0
var bearSignalActive = false
var bearCandleCount = 0

// Trend Filter (200-period EMA)


emaTrend = ta.ema(close, trendFilterPeriod)
isBullishTrend = close > emaTrend
isBearishTrend = close < emaTrend

// RSI Filter for Momentum (More signals by relaxing RSI thresholds)


rsi = ta.rsi(close, rsiPeriod)
isBullishRSI = rsi < rsiThreshold
isBearishRSI = rsi > (100 - rsiThreshold)

// Volatility Filter using ATR


atr = ta.atr(atrPeriod)

// Support and Resistance Calculation (based on highest/lowest prices over a


lookback period)
resistance = ta.highest(high, srLookback)
support = ta.lowest(low, srLookback)

// Plot Dynamic Support and Resistance Levels


plot(resistance, title="Resistance", color=color.red, linewidth=1,
style=plot.style_line)
plot(support, title="Support", color=color.green, linewidth=1,
style=plot.style_line)

// Lookback for Reversal Detection


for i = 0 to (lookback - 1)
if close < low[i]
bullCandle += 1
if close > high[i]
bearCandle += 1

// 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

// Cancel Bullish Reversal if low is broken


if close < bullActiveCandleLow
bullActiveCandle := false

// Cancel Bearish Reversal if high is broken


if close > bearActiveCandleHigh
bearActiveCandle := false

// Confirmation logic for bullish reversal (non-repainting mode)


if nonRepaint
if bullActiveCandle[1] == true and close[1] > bullActiveCandleHigh[1] and
bullSignalActive[1] == false and bullCandleCount[1] <= (confirmation+1)
bullSignalActive := true
vup := true
else if bullActiveCandle == true and close > bullActiveCandleHigh and
bullSignalActive == false and bullCandleCount <= (confirmation+1)
bullSignalActive := true
vup := true

// Confirmation logic for bearish reversal (non-repainting mode)


if nonRepaint
if bearActiveCandle[1] == true and close[1] < bearActiveCandleLow[1] and
bearSignalActive[1] == false and bearCandleCount[1] <= (confirmation+1)
bearSignalActive := true
vdn := true
else if bearActiveCandle == true and close < bearActiveCandleLow and
bearSignalActive == false and bearCandleCount <= (confirmation+1)
bearSignalActive := true
vdn := true

// Plot Buy and Sell signals with enhanced accuracy


plotshape(vup, title = "Bullish Reversal", style = shape.triangleup, location =
location.belowbar, color = color.lime, size = size.small)
plotshape(vdn, title = "Bearish Reversal", style = shape.triangledown, location =
location.abovebar, color = color.red, size = size.small)

// Plot additional signal when price nears support/resistance


nearSupport = close <= support + atr
nearResistance = close >= resistance - atr

plotshape(nearSupport and vup, title="Reversal Near Support",


style=shape.triangleup, location=location.belowbar, color=color.green,
size=size.large, offset=-1)
plotshape(nearResistance and vdn, title="Reversal Near Resistance",
style=shape.triangledown, location=location.abovebar, color=color.red,
size=size.large, offset=-1)

// Alert conditions
alertcondition(vup, "Bullish Reversal", "Bullish Reversal detected")
alertcondition(vdn, "Bearish Reversal", "Bearish Reversal detected")

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy