PDA

View Full Version : How do I get 'barsAgo" info for a variable I create?


BradB
01-26-2007, 04:51 AM
((EMA(20)[0] - EMA(20)[3]) / (EMA(20)[0])) gives me a ROC of a EMA20. How do I get that value from a preceding bar? If I try to apply the 'barsAgo' to the formula I get the following error:

Cannot apply indexing with[] to an expression of type 'double'.

Creating a variable to hold the above formula gives the same error.

Can I compile a custom indicator using the formula and then reference it with a 'barsAgo'?

NinjaTrader_Ray
01-26-2007, 05:50 AM
Two things -

If you want to store user generated calculations, create a variable of type DataSeries. See documentation on this class. It would look something like:



private DataSeries myRoc = null;

protected override void Initialize()
{
myRoc = new DataSeries(this);
}

protected override void OnBarUpdate()
{
myRoc.Set(calculatedValue);
Print("Current myRoc value is: " + myRoc[0]);
}

or you could do something like the following instead:

protected override void OnBarUpdate()
{
Print("ROC of EMA20 is: " + ROC(EMA(20), periodValue, smoothValue)[0]);
}



Ray

BradB
01-26-2007, 06:54 AM
THat's what I needed, thanks!