PureBytes Links
Trading Reference Links
|
So, after an important assist from John CW and an "Aha!" moment about constants (0.1 vs. 0.25) here is the snippet of code that I am using. I am satisfied that it captures Mr. Ehlers' intentions, but I think it might be interesting to average the peak and trough values discretely. To wit, store the past n troughs (peaks) in a ring buffer and use the average of the buffer.
Many thanks to those who helped out.
John
"""
Peaks = Valleys = 0.0;
for ( i = 2; i < BarCount; i++ ) {
BP0 = BP[i];
BP1 = BP[i-1];
BP2 = BP[i-2];
if ( BP1 > BP0 && BP1 > BP2 )
Peaks[i] = BP1;
else
Peaks[i] = Peaks[i-1];
if ( BP1 < BP0 && BP1 < BP2 )
Valleys[i] = BP1;
else
Valleys[i] = Valleys[i-1];
}
AvgPeak = MA( Peaks, 50 );
AvgValley = MA( Valleys, 50 );
if ( ParamToggle( "Mode", "Cycle|Trend", 0 ) == 0 ){
Plot( BP, "BP" + _PARAM_VALUES(), colorRed );
} else {
Plot( Trend, "Trend" + _PARAM_VALUES(), colorBlue );
Plot( AvgPeak*fraction, "Peak", colorBlack, styleLine );
Plot( AvgValley*fraction, "Valley", colorBlack, styleLine );
}
"""
------------------------------------
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
amibroker-digest@xxxxxxxxxxxxxxx
amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|