I have a bug for you. It was driving me absolutely nuts in developing an indicator, until I realised it was a bug and not my coding.
I have written a simplified indicator which does nothing other than demonstrate the bug (attached).
I have also pasted the code below for a quick look-see while you read this post.
The bug is that when writing a value to a plot intra-bar, on the next tick of the same bar the data has been thrown away. Instead of the data, the Plot1[0] now contains the latest closing price of the instrument, and Plot1.ContainsValue(0) shows as FALSE.
In the attached indicator, you will see I write to the indicator's plot with
Plot1.Set(...value...)
Then I Print() to the Output Window the value I just wrote (by reading it back from Plot1[0]) and also Print() Plot1.ContainsValue(0). Results are as they should be; I get the correct value back and a boolean value of TRUE.
NEXT TICK, though, the value is corrupted and the boolean value is FALSE.
Please tell me if you can replicate the bug at your end.
I re-installed NinjaTrader this afternoon, deleting my user's data folder as well. I re-installed .Net only a fortnight ago. I am on Vista, fully up to date.
saltminer.
protected override void OnBarUpdate()
{
if (Close[0] != LastPrice)
{ // this is just a simple technique to occasionally write a value to a plot intra-bar
LastPrice = Close[0];
PriceChangeCount++;
if (PriceChangeCount <10)
return;
PlotSomeValue(); // write to the plot in a Method
PriceChangeCount = 0;
}
// each tick, display what is in the plot
Print("At bar "+CurrentBar+", Tick by tick check: Value is "+Plot1[0]+" and ContainsValue is "+Plot1.ContainsValue(0));
}
private void PlotSomeValue()
{
Plot1.Set(CurrentBar); // just put some value in here
// prove its in by reading the value back
Print("At bar "+CurrentBar+", Value of "+CurrentBar+" written to Plot1... Reading back, value is "+Plot1[0]+" and ContainsValue is "+Plot1.ContainsValue(0));
Plot2.Set(SMA(Plot1,20)[0]); // and generate a second plot that is a moving average of the first
}
Comment