I am trying to get the output of a trendline crossing indicator (i.e. whether a line has been breached) to show up as a 1 or a 0 in the Market Analyzer. If I do it the usual way then the Analyzer thinks the trendline indicator is a normal one that just calculates without any human intervention. I think there may be a way around this by creating a Boolean data series in a primary indicator, and then using a second indicator to read in the Boolean series from the first indicator and converrt it to a plot. Is this doable or is there a smarter way ?
The Market Analyzer (and the Strategy Builder) can only read PlotSeries. So what you need to do is to create an additional plot within your indicator. Please set that plot to Color.Transparent because you do not want to see the output on your chart. If you use Color.Transparent NinjaTrader will also not use the plot for the AutoScale property. If the plot is set to Color.Empty, the plot will not be shown, but it will affect the AutoScale properties.
The PlotSeries contains objects of type double. This is a bit luxurious for a BoolSeries, but it will solve our problem.
Attributing values to the PlotSeries
For a trendline cross you would like to know when a signal has occured. So you could for example use the following values:
-> bullish cross = 2.0 (first bar after the fast line has crossed above the slow line)
-> bullish fillter = 1.0 (all other bars when the fast line is above the slow line)
-> bearish cross = -2.0 (first bar after the fast line has crossed below the slow line)
-> bearish filter = -1.0 (all other bars when the fast line is below the slow line)
These values will not be plotted, but they can be accessed via the Market Analyzer.
Accessing the values via the Market Analyzer
I have often made bad experiences when I have checked a double for a specific value. I am only using conditions such as
when x is an integer. Many NinjaTrader system indicators use the formula
instead. But this is no solution, as the error can be larger than double.Epsilon, depending on which calculations were performed. In our case we have set the value of the DataSeries field to 2, so there should be no problem checking for 2, but as a general habit, when working with objects of the data type double, I would rather check for the value being greater than 1.5, as this is not affected by any rounding error.
The following 4 users say Thank You to Fat Tails for this post: