- ago
I'm trying to understand the lookback parameter of the UpDown indicator. Could someone explain exactly what happens within this indicator during the lookback period? The docs really don't explain anything.

Also, why does it take four bars until the indicator recognizes that the sine wave has changed direction? Why is four a magic number?



CODE:
      public override void Initialize(BarHistory bars)       {          TimeSeries sine = new TimeSeries(bars.DateTimes);          sine.Description = "Sine";          for (int bar = 0; bar < bars.Count; bar++)             sine[bar] = Math.Sin(bar/10.0*Math.PI);          PlotTimeSeries(sine, "Sine", "sinePane");          IndicatorBase upDown = UpDown.Series(sine, 6);          PlotIndicator(upDown);       }
0
198
Solved
5 Replies

Reply

Bookmark

Sort
Cone8
 ( 6.63% )
- ago
#1
Here's the current "inaccurate" definition:
The number of consecutive bars where the value has moved up or down. Down moves result in negative indicator values. You can specify a lookback (default 1 bar) and a percentage amount that the move must exceed to qualify (default 0).

Let's change it to this:
The number of consecutive bars where the source has moved up or down with respect to its value lookback bars ago. Down moves result in negative indicator values. You can specify a lookback (default 1 bar) and a percentage amount that the move must exceed to qualify (default 0).

With qualifyPct = 0, UpDown is equivalent to ConsecUp - ConsecDown.


CODE:
      public override void Initialize(BarHistory bars)       {          TimeSeries sine = new TimeSeries(bars.DateTimes);          sine.Description = "Sine";          for (int bar = 0; bar < bars.Count; bar++)             sine[bar] = Math.Sin(bar / 10.0 * Math.PI);          PlotTimeSeries(sine, "Sine", "sinePane");          IndicatorBase upDown = UpDown.Series(sine, _period.AsInt);          PlotIndicator(upDown);          IndicatorBase cu = ConsecUp.Series(sine, _period.AsInt);          IndicatorBase cd = ConsecDown.Series(sine, _period.AsInt);          TimeSeries ts = cu - cd;          PlotTimeSeriesHistogramTwoColor(ts, "CU - CD", "Consec2");                }
1
- ago
#2
This doesn't answer my question. And your definition doesn't describe how four is determined. Are you saying the beginning of the slope change (peak or trough) isn't relevant to this indicator? ... But it's suppose to be assaying Up and Down behavior, right?

What's weird it that it starts its recount (of 10) away from the slope change and away from the zero crossing. Explain why there's a value of 10 and why it starts its recount somewhere between the slope change (peak or trough) and the zero crossing?

Off topic, but I don't understand how the lookback period works for ConsecUp and ConsecDown either, so answering this question with two other indicators I don't understand isn't helping. (But ConsecUp and ConsecDown have an interesting relationship with this UpDown indicator; thanks for pointing that out.)
0
- ago
#3
Forget about 4. Look at this the simple way. Assuming a lookback of 6:

If the current value is greater than the value of 6 bars ago, add one to the count if we're already counting up. If not already counting up then set the count to 1.

If the current value is less than the value of 6 bars ago, subtract one from the count if we're already counting down. If not already counting down then set the count to -1.
1
Cone8
 ( 6.63% )
- ago
#4
It precisely answers the question, and I can't explain it any better or more concisely.

An important detail (it's in the definition) that you're probably overlooking is if the value isn't exceeded then it continues to add to the count.

Let's paint a picture. Say the lookback is 4 ...

CODE:
idx value consec up 0 0.0 1 0.1 2 0.3 3 0.4 4 0.5 1 (compare to value at idx 0) 5 0.8 2 (compare to idx 1) 6 0.9 3 (compare to idx 2) 7 1.0 4 (compare to idx 3) 8 0.9 5 (compare to idx 4) - still rising 9 0.8 6 (compare to idx 5) - still rising (0.8 == 0.8) 10 0.5 X (compare to idx 6) - falling; 0.5 < 0.9

1
- ago
#5
QUOTE:
If the current value is greater than the value of 6 bars ago, add one to the count if we're already counting up. If not already counting up then set the count to 1.

So this UpDown indicator has nothing to do with slopes or slope changes. I think I would have called it a RangeChange indicator instead. Let me suggest a new definition then:

The number of consecutive bars where the source value has moved above its past value (when going up) or moved below its past value (when going down) as determined by the lookback period.

I think the problem with the original definition is that its too terse to describe the process accurately. Thanks for all the clarification.
3
Best Answer

Reply

Bookmark

Sort