PDA

View Full Version : Can't access 1 bar ago in custom indicator


AlohaBob
01-06-2007, 08:49 PM
In a custom indicator, I cannot access a value 1 bar ago. For example EMA(13)[1] will not print to the output window and causes the indicator not to work at all.

I thought maybe you couldn't refer to bars ago on indicators, so I set up a DataSeries to keep the values and that doesn't work either.

In both cases, if you refer to a value 1 bar ago, the value will not print and causes the indicator to totally fail (i.e. nothing printed to output window, doesn't plot on chart, and doesn't show up in databox). As soon as you take the reference to 1 bar ago out, it works perfectly.

I created a simple test program that shows the behaviour and is basically the same as the one shown in documenation on DataSeries. The program is attached. I can send you screen shots as well if needed.

Building this indicator is critical to a strategy I'm developing, so I'd appreciate any possible escalation on either fixing this if it's a bug or letting me know what I'm doing wrong.

Best regards,

Bob

NinjaTrader_Ray
01-07-2007, 03:42 AM
Hi Bob,

Problem is a simple one. You will get indexout of range exceptions (in the Control Center Log tab) when you attempt to access a value that does not exist.

Change your code to the following:

myDataSeries.Set(Close[0]);

// Make sure thereare more than 1 value in myDataSeries before printing
if (CurrentBar > 0)
Print("The values are" + myDataSeries[0] + " " + myDataSeries[1]);