Coding trigger signals based on peak-trough
Author: sofia
Creation Date: 2/3/2014 1:04 PM
profile picture

sofia

#1
Hello,

Is it possible to create a boolian trigger based on peak-trough?
Please refer to comments in example below
CODE:
Please log in to see this code.

profile picture

Eugene

#2
Don't code what you can beg, borrow or steal. This is guaranteed to keep you busy for awhile:

ZigZag Class
ZigZag
Peak & Trough Based ZigZag

TASC 2013-06 | The 1-2-3 Wave Count (Vervoort)
TASC 2013-07 | The Step Candle Pattern (Vervoort)
profile picture

sofia

#3
Thanks Eugene.

Regards,

Sofia
profile picture

innertrader

#4
Although the Peak/Trough source is not available can you describe the rule by which the Peak / Trough indicators identify *candidate* new peaks and troughs to test % or value movement to qualify the next new peak / trough? I have researched and looked closely at the charts, but I can't identify a simple rule such as number of bars / % up or down after a confirmed peak or trough, or a pattern for a new point to begin testing against again, after a new peak or trough is confirmed. I originally thought a new peak could not be established until a new trough was established (and vice-versa for a a trough) but that does not seem to be the case.

Basically I'm asking how the peak / trough indicators "decide" that a bar qualifies to test for a trigger value to confirm a new peak / trough.

In some cases, even with a visual peak or trough (such as with 2 consecutive lower lows), movement up beyond the specified value will not necessarily qualify that last low as a trough. So I'm wondering if there's something else at work here that I can't see.


With additional testing I found an additional clue, but not sure where it leads..Bars that I think should be peaks, based on visual interpretation, will only become peaks when I reduce the percent down value. There are already qualifying low points that follow these based on the initial value. i don't understand why value selected is affecting peak candidate selection (in addition to confirmation). Is the trigger value being used in some additional way than simply to trigger on a down value, such as being used to filter candidate peaks (before they are confirmed)?


CODE:
Please log in to see this code.

I am running ^NDX with Yahoo data (10 years)

Examples of issue raised above:

Bar on 2/8/16 will only become a peak when value is decreased to 2 (%)
Bars on 1/13/16 and 1/25/16 will only become a peaks when value is decreased to 1 (%)
profile picture

Eugene

#5
It's documented here in "Calculation" section:

http://www2.wealth-lab.com/WL5WIKI/Peak.ashx
http://www2.wealth-lab.com/WL5WIKI/Trough.ashx

In Value mode, a peak is reached at the point when the value of the DataSeries is at or below its highest value minus the reversal value (and vice versa for trough). Remember, consecutive highs/lows are not considered by the indicators.

QUOTE:
Bar on 2/8/16 will only become a peak when value is decreased to 2 (%)

Makes no sense. The 2/8/16 bar is a clear trough by any input value, not a peak.
profile picture

innertrader

#6
QUOTE:
It's documented here in "Calculation" section:

http://www2.wealth-lab.com/WL5WIKI/Peak.ashx


Thank you, Eugene. That's the first thing I read before doing additional research.

QUOTE:
Bar on 2/8/16 will only become a peak when value is decreased to 2 (%)

QUOTE:
Makes no sense. The 2/8/16 bar is a clear trough by any input value, not a peak.

It doesn't make sense because it's a typo. It should be 2/1/16. The 2/8/16 bar is the down bar that validates the 2/1/16 peak. Sorry about that.
QUOTE:
Remember, consecutive highs/lows are not considered by the indicators.

Not sure I understand what this means. Do you mean that an intervening peak (for new trough) or trough (for new peak) is required? I see many examples where that is not the case. Can you define "consecutive" technically or by logic rules, please?
CODE:
Please log in to see this code.

Note that with the above code, 1/13/16, 1/25/16, and 2/1/16 are *not* identified as peaks.
CODE:
Please log in to see this code.

But with the code above (only changed the value), they are *all* identified as peaks. And it is not just because the required move down was reduced.

If I set the Peak value at 4, then I would expect the bar at 1/13/16 to be a peak, confirmed by bar at 1/15/16 (4184.69 / 4359.50 = 95,8%) which is greater down value than 4%. But yet it does not show the bar at 1/13/16 as a peak.

Similarly with my original setting of 7, I would expect the bar at 2/1/16 to be a peak, confirmed by the bar at 2/18/16 (3979.09 / 4301.63 = 92.5%) exceeding the down value of 7%. But it does not show as a peak. (All values are Highs).

What am I missing?
profile picture

Eugene

#7
QUOTE:
It should be 2/1/16. The 2/8/16 bar is the down bar that validates the 2/1/16 peak

No, this should not be a peak. There was neither a 7% nor 4% (depending on your settings) preceding High-to-High move during Jan'16 to qualify for a peak on 1-Feb-2016. The best match was a 2.9% move from the High of 20-Jan-2016 which is still less than your threshold of 4%.

QUOTE:
Not sure I understand what this means.

It was said in relation to your sentence "a visual peak or trough (such as with 2 consecutive lower lows)" which reminded me of swing highs and lows or Gann swings. This has nothing to do with determining Peak/Trough as you understand.

QUOTE:
Do you mean that an intervening peak (for new through) or trough (for new peak) is required?

No, one (Peak) doesn't depend on another (Trough).
profile picture

innertrader

#8
QUOTE:
No, this should not be a peak. There was neither a 7% nor 4% (depending on your settings) preceding High-to-High move during Jan'16 to qualify for a peak on 1-Feb-2016.

Thank you @Eugene. This explains the discrepancy I thought I was seeing that I couldn't figure out and describes the full rule set. This *additional* rule that the threshold setting affects not only the qualification of a peak (or trough, I assume) based on data that *follows* the peak, but also on data that *precedes* the peak is an undocumented rule, as far as I can tell. And not obvious, at least to me. Possibly, you could include what you wrote here in the documentation for these indicators.

Robert
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).