PDA

View Full Version : Refresh problem


MrBaffalo
01-16-2007, 03:01 AM
Hello there,

I'm building and testing a new indicator, it's a swing indicator. What I observed is that before and after refreshing the chart (where for refreshing I mean applying again that indicator w/o deleting) Indicator plots change.

I coded it various times,, debugged several times, code seems to be working finebut the output is the same, when condition is verified I have a dbl plot on two consecutive bars.

Attached images about that. Calcolate on bar close is set to true.

Maybe I'm loosing something or some tricks about refreshing indicators (nt6).

Thanks in advance,

best regards

Marcello

MrBaffalo
01-16-2007, 03:02 AM
Second image after indicato refresh

NinjaTrader_Ray
01-16-2007, 03:47 AM
This happens each time? If yes, please send me the indicator code to ray at ninjatrader dot com and reference this post.

Thanks

NinjaTrader_Ray
01-16-2007, 06:56 AM
The problem is that for indicators, OnBarUpdate() currently isnot guaranteed to be only called once per bar when CalculateOnBarClose = true. Do not code your indicator script assuming that you will only see one call per bar.

What you can do is addsome code like the following:

private int lastBarSeen = -1;

protected override void OnBarUpdate()
{
if (CurrentBar <= lastBarSeen)
return;
lastBarSeen = CurrentBar;

// Do something here
}


Ray

tquinn
01-23-2007, 10:28 AM
Ray,
It seems that CalculateOnBarClose is misnamed. If one can't trust it to calculate only on bar close should indicator code be wrapped like this?

protected override void OnBarUpdate()
{
if(Bars.PercentComplete ==1)
{
// Do something here
}
}

What is the difference in this, and your code below?

NinjaTrader_Ray
01-23-2007, 11:32 AM
We will address this issue later this year, its not critical and only is shows up on low value tick based intervals. The only impact this has is if you are managing internal counters and incrementing them on each call to OnBarUpdate(), otherwise, the logic within OnBarUpdate() is irrelevant no matter how many times this method is called. That being said, we do realize that its better if its guaranteed to be called once for each bar or tick.

The code you provided is not the same as what I provided. My code checks on the actual bar index that is calling OnBarUpdate() where yours just checks if the bar is completed. The problem with yours is that the bar can be complete on a specified index and OnBarUpdate() is called more than once on that index.

Ray