Syntax
public static Indicators.TroughBar Series(DataSeries source, double reversalAmount, Indicators.PeakTroughMode mode)
public static double Value(int bar, DataSeries source, double reversalAmount, Indicators.PeakTroughMode mode)
Parameter Description
source |
Price series |
reversalAmount |
How much of a percentage/point (see mode) decline is required to trigger a new Trough |
mode |
PeakTroughMode enum: (PeakTroughMode.Value, PeakTroughMode.Percent)
|
Description
Returns the bar number at which the last Trough that was identified for the specified Price Series as of the specified Bar. The Reversal parameter determines how much of a percentage (default) or point decline is required to trigger a new Trough. It typically requires a few bars of upward price movement to reach the Reversal level and qualify a new Trough. The Trough function never "looks ahead" in time, but always returns the Trough value as it would have been determined as of the specified bar. For this reason, the return value of the Trough function will lag, and report troughs 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
See
Trough
Remarks
- TroughBar returns -1 if a trough 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
Trough
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()
{
// Flag bars that are 5% Troughs
int n = -1; int nPrev = -1;
for(int bar = 0; bar < Bars.Count; bar++)
{
n = (int)TroughBar.Value( bar, Low, 5, PeakTroughMode.Percent );
if( ( n != nPrev ) && ( n > -1 ) )
{
DrawCircle( PricePane, 6, n, Lown, Color.Green, LineStyle.Solid, 2, true );
nPrev = n;
}
}
}
}
}