PDA

View Full Version : Exposing a non DataSeries property in an indicator


tquinn
01-11-2007, 12:40 PM
Is there a way in an indicator to have a DataSeries which is made public but is not plotted?

Example, HeikinAshi, I would like to assign a "bias" based on the body color, +1 for Close>Open, -1 for the opposite, which could be accessed from a strategy.

If this is done using Add(new plot) it plots a line at +-1 which messes up the scale. Of course the AutoScale can be set to false. I was wondering if there was a more elegant approach.

NinjaTrader_Ray
01-11-2007, 01:51 PM
Good question Tom, absolutely there is a more elegant approach. You will want to add a property to your strategy.

Following is a partial sample code:

// Under variables
private bool bullish = false;

//Within OnBarUpdate()
bullish = Close[0] > Open[0] ? true : false;

// Under properties, create the public property that can be accessed from the strategy
public bool Bullish
{
get
{
Update();
return bullish;
}
}



Calling the Update() method is a key step. Indicators embedded in a strategy are optimized andonly call their OnBarUpdate() method when the indicator is called from the strategy, not every bar or tick. The indicator knows that when a DataSeries value is being accessed, it needs to call the OnBarUpdate() method. Since all you need is to know when a value is true or false, there is not need to store this data in a DataSeries object so we just create a basic property. To ensure this property has the most current value, we call the Update() method withing the property getter to force the indicator to call the OnBarUpdateI() method.


Ray

tquinn
01-11-2007, 03:16 PM
If I wanted a DataSeries with no plot then:

// Under variables
private DataSeries noPlotData;

//Within Initialize()
noPlotData = new DataSeries(this);

//Within OnBarUpdate()
NoPlotData = { expression}

// Under properties, create the public property that can be accessed from the strategy
public DataSeries NoPlotData
{
get
{
// Update(); // Not used for series ???
return noPlotData;
}
}

tquinn
01-11-2007, 03:17 PM
I assume this is need for backtesting?

NinjaTrader_Ray
01-11-2007, 03:29 PM
Yes, same principlesapply.