Signals arriving about 5 bars late

This might be related to the request for help I had earlier regarding missing signals. I tried to run the replay on the code and I am getting late signals on both the chart and the Analisys.
I'm getting the signal in Analysis window about 5 bars after the chart displays the signal. The chart displays the signal about 1 or 2 bars late, and displays after a refresh, in the correct location.
Any help or direction would be very much appreciated.

without the code it is difficult to tell.

One thing i discovered was that many functions like EMA / WMA etc required a lot of bars before the period specified to get a smooth or true value.
so you can check by using ALL the bars in the formula with the function SetBarsRequired()

Secondly, when debugging, just don't look at the signal date or bar. Plot all the values of the indicators and confirm they are the same for each bar, same with many columns in Explore.

Thanks for your reply. I believe I'm using about 10 previous bars. I've also set settradedelays=0. The code is in spaghetti mode still. I'm just trying to study a vanilla supertrend trigger. Nothing as creative as some of the code I've seen here.
But the question I have is ... If I'm at 1m bar doing 10s refresh and the signal triggers and goes away in 1 second or so, actually a few ms, it seems. Will LastValue( ) still catch it? Is there an Option that'll preserve the signal at least untill I've read it, at 10s?

LastValue() will not catch it in every update.

LastValue() will tell you the state for every latest update. ( Signal or no signal )

In theory, you could store a "1" in another static variable only if a signal was generated for that bar. This would prevent overwrite if there is no signal.

So Something like?

if( fleetingsignal  )
    StaticVarSet( "fleet" + Name(), 1 ); 
buy =     StaticVarGet( "fleet" + Name() ); 

if( NewBar ) 
     StaticVarSet( "fleet" + Name(), 0 ); 

Sounds like a plan... I'll give it a try.
Thank you much.

1 Like