fred99998
 ( 19.71% )
- ago
I see a lot of different functions for PeakTroughCalculator, like HasRisingTroughs, GetPeak, GetPrevPeak, etc. But without examples, I cannot apply them. Could you give the simplest examples of how to translate from WL6 to WL7.

For example:

CODE:
if (Trough.Value(bar, Low, 5, PeakTroughMode.Percent) > Trough.Value(bar-1, Low, 5, PeakTroughMode.Percent)) BuyAtMarket(bar + 1); if (Close[bar] > Peak.Value(bar, High, 5, PeakTroughMode.Percent)) BuyAtMarket(bar + 1);
0
1,305
20 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.62% )
- ago
#1
Yes, we'll assign a task to document each of those methods with an example in the QuickRef.
0
- ago
#2
Specifically, I'm interested in how to translate the WL6 code below to WL7 code.
CODE:
DataSeries peaks = Peak.Series(dsTimingBeacon, peakReboundMin, PeakTroughMode.Value);
0
- ago
#3
Could you please help with this?

Being at idx==1125 e.g., I want to get the nearest 10 PeakTrough object to the left of this bar so I could get the type of every one of them and indexes and values and so on.
0
- ago
#4
E.g. there is a PeakTroughs property of PeakTroughsCalculator, but how can I get the exact index of the PeakTrough object found with e.g. pt.GetPeak(1275);
0
- ago
#5
See "Previous Peaks & Troughs", GetPrevPeak / GetPrevTrough
https://www.wealth-lab.com/Support/ApiReference/PeakTroughCalculator

Is this close to what you're looking for?
0
- ago
#6
Does a list of peaks and troughs always look like ptptptptptpt, I mean if I know the type of PeakTrough object to get the previous object is there always a determined way to do this?

If the object type is Peak, can I be sure that PreviousTrough will return the prior PeakTrough object?
0
Cone8
 ( 4.98% )
- ago
#7
See the examples in the QuickRef > PeakTrough class.

You can determine if it's a peak or trough by the Type property, its index is the PeakTroughIndex property, and the index at detection is the DetectedAtIndex property.

Also, see the example for PeakTroughCalculator > PeakTroughs, which is the list of peaks and troughs, not just one or the other. Use the PeakTrough.Type to determine which it is.

To iterate through just one or the other, it's easy to set up a loop for that - see the example for GetPeak.
0
- ago
#8
Thanks, Cone

I looked through all these info about related classes and methods before asking my question).

Now my code for my question looks like this, still not sure whether it's ok:

CODE:
pt = new PeakTroughCalculator(bars, reversePercent, PeakTroughReversalTypes.Percent); PeakTrough cur_pt = pt.GetPeak(1275); for (int ind = 0; ind < 10; ind++) { WriteToDebugLog(string.Format("{0} - {1}, {2}", cur_pt.XIndex, cur_pt.Value, cur_pt.Type)); if (cur_pt.Type == PeakTroughTypes.Peak) cur_pt = pt.GetPrevTrough(cur_pt); else cur_pt = pt.GetPrevPeak(cur_pt); }
0
- ago
#9
Your FOR loop is not referencing the "ind" loop variable. You need to fix that before we can evaluate it.
1
- ago
#10
@superticker, it's just for getting 10 iterations only. I use GetPrevPeak or GetPrevTrough for getting previous PeakTrough object.

So I didn't get the idea of what exactly did you mean.
0
- ago
#11
It's confusing to me not to employ the indexer. Accessing the elements via the indexer would be faster than searching for each peak individually.
CODE:
pt = new PeakTroughCalculator(bars, reversePercent, PeakTroughReversalTypes.Percent); PeakTrough cur_pt = pt.GetPeak(1275); int indInitial = pt.IndexOf(cur_pt); for (int ind = indInitial; ind > indInitial-10; ind--) WriteToDebugLog(string.Format("{0} - {1}, {2}", pt[ind].XIndex, pt[ind].Value, pt[ind].Type);
I haven't tried this code, so you may need to fix any bugs. Be sure to turn the inequality around, "<" becomes ">".
0
- ago
#12
Thanks @superticker!

That's just exactly I was looking for).

Debugged code looks like this:
CODE:
pt = new PeakTroughCalculator(bars, reversePercent, PeakTroughReversalTypes.Percent); PeakTrough cur_pt = pt.GetPeak(1275); int indInitial = pt.PeakTroughs.IndexOf(cur_pt); WriteToDebugLog(indInitial); for (int ind = indInitial; ind > indInitial - 10; ind--) WriteToDebugLog(string.Format("{0} - {1}, {2}", pt.PeakTroughs[ind].XIndex, pt.PeakTroughs[ind].Value, pt.PeakTroughs[ind].Type));
1
- ago
#13
I like the Idea of Peaks and Troughs classes and all that trend lines and that kind of stuff.

But what about improving of peaks and troughs calculations. Now you define the only one percent value for the whole bar series. What about adjusting of this calculation with some kind of indicator? For example ATR (but let it be up to user).

0
Glitch8
 ( 10.62% )
- ago
#14
We could add a new PeakTroughType ATR and ATRPercent. I’m not sure how it could work with a generalized indicator? Sounds like a new feature request is in order.
0
- ago
#15
It resembles an old notion of event-driven Peak/Trough. A peak or trough is drawn when an event happens. An event could be any: ATR value exceeded as Replikant_m suggests, indicator crossover (crossunder), M Top (or W bottom) etc.
0
Glitch8
 ( 10.62% )
- ago
#16
But that’s all so user specific I question the utility of building it into a generalized peak trough support class.
0
- ago
#17
After reading your comments I’m not sure you got me right. So I’ll try to develop the idea a little.

As I’ve already said, I like the whole idea and the interface you provide (all those methods and properties).

So you give us this interface and built-in methods to mark all those peaks and troughs. Actually, it’s the only one method now (with a small variety – percent or points). What I was talking about is about increasing this variety a little – letting this percent be not constant but depending on volatility (ATR e.g.), so on higher volatility 7% change is needed, at the same time if volatility is small – 2.5 will be enough etc. (depending on ATR for example), so yes – “add a new PeakTroughType ATR and ATRPercent.” – something like this.

But what I didn’t talk about is using different methods to mark peaks and troughs. Something @Eugene was talking about. But I’m not sure about adding this wide range of abilities. But there can be built-in extra methods of labeling peaks and troughs – something using fractals or other methods (with a controlled variety withing the method). All with the same interface.
0
- ago
#18
I think that adding PeakTroughType ATR and ATRPercent as Dion suggested would be a welcome improvement.
0
- ago
#19
QUOTE:
I think that adding PeakTroughType ATR and ATRPercent as Dion suggested would be a welcome improvement.


Should I create a feature request topic for this?)
0
Glitch8
 ( 10.62% )
- ago
#20
Please do, and don't forget to vote for it!
0

Reply

Bookmark

Sort