Facing problem in supertrend scanner

Screenshot 2026-07-21 181212

Hello Imran sir,

I am facing with the Supertrend flip logic in my trading code.

I am using the standard condition where Supertrend changes from red to green for a buy signal, and green to red for a sell signal. However, the signals I am receiving are not accurate.

Many times, the Supertrend green, but instead of giving a buy signal, the code triggers a sell signal. In other cases, the signal comes very late. Sometimes the Supertrend flips, but the code gives me the signal 5 candles later, and occasionally even 10 candles after the actual flip.

I would appreciate your help in reviewing the Supertrend logic how to ensure the signal is generated exactly when the Supertrend flips, without delay or false triggers.

Thank you, Ajit