# Indicator alert showing different result

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

Many thanks

That is repainting indicator

Use some correctly coded stoch crossing indicator

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?