OPEN-SOURCE SCRIPT

Donchian Reversal Scanner by Hitesh2603

How It Works:
Bearish Side Logic:

If the price is falling with bearish candles and touching the lower Donchian Channel, the bearishCondition flag is set to true.

When a bullish candle appears afterward, the flag is reset, and the bullishReversalSquare condition becomes true.

Bullish Side Logic:

If the price is rising with bullish candles and touching the upper Donchian Channel, the bullishCondition flag is set to true.

When a bearish candle appears afterward, the flag is reset, and the bearishReversalSquare condition becomes true.

Plotting Squares:

A green square is plotted below the candle when bullishReversalSquare is true.

A red square is plotted above the candle when bearishReversalSquare is true.

Scanner Output:

The scanCondition variable is true when either bullishReversalSquare or bearishReversalSquare is true.

How to Use the Script:
On the Chart:
Add the script to your chart.

You will see squares plotted on the chart when the conditions are met:

Green squares below the candle for bullish reversals.

Red squares above the candle for bearish reversals.

In the Scanner:
Open the Scanner tab in TradingView.

Click on "Create New Scanner".

In the "Condition" field, select the script you just created.

Choose the market or watchlist you want to scan (e.g., "NYSE", "NASDAQ", or a custom watchlist).

Run the scan. The Scanner will return a list of instruments where the scanCondition is true.

Why This Works:
The scanCondition variable is now properly declared and used.

The plotchar function explicitly outputs the scanCondition variable as a plot, which the Scanner can recognize.

Penafian