Profile Picture

Indicator problem

Posted By mark0419 6 Years Ago
QuestionMark Posted Thursday January 17 2013
I'm having some trouble with one of my indicators, I can't seem to figure out why it is always returning NaN. The indicator that is having issues is at the end of a chain of several other custom indicators.

At the root, I have an "averaging" indicator which is based on the IndicatorBase class.
Next in the chain is a "line" class which is based on the SeriesCalculatorBaseWithValues class and uses the "averaging" indicator as it's input.
After the "line" class is a "trend" detection indicator, again based on the SeriesCalculatorBaseWithValues. The "trend" indicator uses the "line" indicator and the Close price series as inputs.

The problem I'm having is with the final indicator in the chain, a "range" price indicator. This indicator uses the "trend" indicator and the High price series as inputs.

In the code I've attached, both the "RangeHighDebug" and "RangeHighChained" indicators are using the same basic CalcNewValue() logic. The weird thing is that the "RangeHighDebug" should not ever return NaN because the logic that would normally handle this case has been replaced by the 'return 2.0' line. When I apply these indicators to a chart the debug version shows several NaN values, and no values of 2.0. Also, the breakpoint in the chained version is never hit.

Something weird is happening here. I suspect I'm just doing something dumb, but I can't seem to figure it out. Any thoughts on what's wrong?


PS : I've been able to workaround the problem by pushing the trend calculations down into the range indicator.

RangeIndicatorProblem.png (241 views, 60.00 KB)
RangeIndicator.cs (297 views, 3.00 KB)
Posted Sunday January 20 2013
I think that in your RangeHighChainedIndicator, your double.IsNaN check is backwards. Shouldn't this line:

if (!double.IsNaN(last_tv)) { break; }

be replaced with this?

if (double.IsNaN(last_tv)) { break; }

You are starting with the most recent value, and working backwards. When you get to a NaN value in the trend series you want to stop the loop and return the high_p value found so far, but with the current logic you are exiting out of the loop if the trend series does have a valid value.

Posted Sunday January 20 2013
Hi Daniel,

Thanks for taking a look. I believe the logic is correct, unless my thinking is really off here.

The trend indicator will return 1.0 when the market is trending up, -1.0 when trending down,
and NaN when no trend is detected.

The goal of the range high indicator is to find the highest price over a non-trending (aka ranging) period.

Thus the range high indicator should be looking for the high price across a sequence of trend==NaN values.
When trend!=NaN the market is in a trending state again, and the range high indicator should return the value it found.

Posted Sunday January 20 2013
In that case I think the problem is using NaN to indicate no trend. NaN has a special meaning for RightEdge indicators, it means that there is not enough data yet to calculate the indicator value. Once an indicator has a valid (non-NaN) value, it isn't supposed to return NaN for subsequent bars.

Can you change your indicator so you use 0 to indicate "no trend" and see if that fixes the problem?

Posted Sunday January 20 2013
Thanks Daniel!

I figured it would end up being something simple. I changed the trend indicator to report 0 in a non-trend state and adjusted the range price indicators accordingly and now everything is working as expected. Smile


Similar Topics

Reading This Topic

2005-2019 © RightEdge Systems