Syntax
public static PeakBar Series(DataSeries source, double reversalAmount, PeakTroughMode mode)
public static double Value(int bar, DataSeries source, double reversalAmount, PeakTroughMode mode)
Parameter Description
source |
Price series |
reversalAmount |
How much of a percentage/point (see mode) decline is required to trigger a new Peak |
mode |
PeakTroughMode enum: (PeakTroughMode.Value, PeakTroughMode.Percent)
|
Description
Returns the bar number at which the last Peak that was identified for the specified Price Series as of the specified Bar. The Reversal parameter determines how much of a percentage (default) decline is required to trigger a new Peak. It typically requires a few bars of downward price movement to reach the Reversal level and qualify a new Peak. The Peak function never "looks ahead" in time, but always returns the Peak value as it would have been determined as of the specified bar. For this reason, the return value of the Peak function will lag, and report peaks a few bars later than they actually occurred in hindsight. This is intentional, and allows peak/trough detection to be used when back-testing trading systems.
Interpretation
- Peaks/Troughs of highs and lows are often used as support and resistance levels. These points have historical significance because they have proven to be important levels of price reversal.
- Peaks and troughs are a convenient way of detecting chart patterns. For example, one aspect of a Head & Shoulders Top is a series of 3 Peaks, the second higher than the outer two.
- PeakBar is particularly useful with working with chart patterns. You can store the bar number of the most recent peak, then use this as an anchor bar to retrieve the bar number for the previous peak, and so on.
Remarks
- PeakBar returns -1 if a peak has not yet been detected at the beginning of the chart.
- To base reversals on point/absolute movement, pass the PeakTroughMode.Value constant as the required parameter.
- Calculating peaks/troughs based on percentage moves is not allowed on data series that contains negative or zero values. For these data series you must use PeakTroughMode.Value to base the reversal amount on a point value.
Calculation
See
Peak
Example
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
protected override void Execute()
{
//Draw a trendline from the 2 most recent 10% Peaks
bool Detected2Peaks = false;
int bar = Bars.Count-1;
int p2 = -1;
int p1 = (int)PeakBar.Value( bar, Close, 10, PeakTroughMode.Percent );
if( p1 > -1 )
{
p2 = (int)PeakBar.Value( p1, Close, 10, PeakTroughMode.Percent );
if( p2 > -1 )
{
DrawLine( PricePane, p1, Closep1, p2, Closep2, Color.Red, WealthLab.LineStyle.Solid, 1 );
Detected2Peaks = true;
}
}
if( !Detected2Peaks )
DrawText( PricePane, "2 peaks not detected. Try another symbol or load more data.", 0, 5, Color.Red );
}
}
}