PDA

View Full Version : Managing Plots for Strategy vs Presentation


whitmark
06-13-2007, 05:52 AM
I have a custom indicator that drives out only one value but uses two plots to implement differential coloring based on certain conditions. For example, If the indicator value is moving up or flat, the green plot1 is set, else the red plot2 is set. Now, if I want to use that value from the indicator in a strategy, I would need to merge the values from both plots 1 and 2 into a single dataseries to get a single value for each bar. Alternatively, I could push a 3rd plot from the indicator where the value is set at the close of each bar, but the plot color would need to be set to transparent. Hopefully this shows that plotting techniques for visual presentation may differ from those used to pass a data series to a strategy.

Can you offer any best practices, over and above what I have shared here, for how best to address these two objectives simultaneously? I assume it is better to have fewer plots and fewer dataseries for processing efficiency. For example, is overriding a single Plot to manage plot color and push out a single dataseries more efficient than bifurcating several plots to do the same, when ultimately strategy processing and optimization will be involved. Thanks.

Regards,

Whitmark

NinjaTrader_Ray
06-13-2007, 07:18 AM
Adding an additional plot likely will not have a performance impact. However, what I would do is have a new DataSeries object and expose that.

For example:

private DataSeries mySeries;

In Initialize():
mySeries = new DataSeries(this);

Set the values for each bar in OnBarUpdate()

Then expose a property for it:

public DataSeries MySeries
{
get
{
Update(); // This is important
return mySeries;
}
}

See here for info on Update() http://www.ninjatrader-support.com/HelpGuideV6/Update.html

whitmark
06-14-2007, 06:36 AM
Thanks Ray . . . this is just the technique I was looking for to be able to pass dataseries values between indicators and strategies without necessarily adding more plots that would appear in the indicator panel.

One follow-up question, however. When I compare the approach you recommend with the example in the help under update() that is shown below, I see that the latter did not require a dataseries to be passed. Are there instances where you would prefer to use one approach vs the other? In my case, I would like to be able to refer back to previous barsago values in the dataseries from within the strategy. Thanks.


tripleValue = 0;

private double
protected override void OnBarUpdate()
{
if (CurrentBar < 20)
return;

tripleValue = SMA(20)[0] * 3;
Values[0].Set(SMA(20)[0]);
}

public double TripleValue
{
get
{
Update();
return tripleValue;
}
}

NinjaTrader_Ray
06-14-2007, 07:25 AM
Rule of thumb is if you need to store data on each bar then use a DataSeries, if you only need to know the current state, use any data type.