Indicator alert showing different result

I have downloaded a stochastic cross alert indicator, but I don’t get my expected result.

On a M15 chart, I literally have signal every 15 mins, and the buy and sell signal is just totally wrong.

I have attached the code, and someone please help me to debug this.

Many thanks

That is repainting indicator

Use some correctly coded stoch crossing indicator

Thank you for your quick reply.

What do you mean exactly please? I don’t quite understand why it is not a correctly coded stoch crossing indicator.

I understand the code in this way, when K cross D, it draws an arrow on the chart, and at the same time sends out alert. However, I don’t understand why the drawing is done outside the if condition of the newbar.

stochastic1now      = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,0,i);
stochastic1previous = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,0,i+1);
stochastic1after    = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,0,i-1);

stochastic2now      = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,1,i);
stochastic2previous = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,1,i+1);
stochastic2after    = iStochastic(NULL,0,KPeriod1,DPeriod1,Slowing1,MAMethod1,PriceField1,1,i-1);

diff = stochastic1after - stochastic2after;

It is a repainting indicator. For any specific candle, it uses the stochastic before, current, and after. What you get at the start of a new bar is different than what you get at the end of the bar. Therefor it is useless for trading.

So how does it iStochastic function work?

how can I create a useful stochastic cross alert please?

Look at the real Stochastic indicator