API documentation, members, signatures, and C# examples.
Search the framework
Find classes, members, and documentation.
NamespaceWealthLab.Indicators
Parent
Object
The PeakTrough class represents a peak or trough detected in time series data by the PeakTroughCalculator utility class. It implements the IChartPoint interface, so its XIndex and YValue properties can be used wherever chart points are accepted.
The index where the peak or trough was actually detected.
Because a peak or trough can only be confirmed after a reversal occurs, DetectedAtIndex will generally be later than the actual peak or trough index represented by PeakTroughIndex.
C# example
using WealthLab.Backtest;
using WealthLab.Core;
using WealthLab.Indicators;
namespace WealthScript
{
public class DetectedAtIndexExample : UserStrategyBase
{
public override void Initialize(BarHistory bars)
{
double swingPct = 5.0;
ZigZagHL zz = new ZigZagHL(
bars,
swingPct,
PeakTroughReversalType.Percent,
false);
PlotIndicator(zz);
PeakTroughCalculator ptc = new PeakTroughCalculator(
bars,
swingPct,
PeakTroughReversalType.Percent);
foreach (PeakTrough pt in ptc.PeakTroughs)
{
int detectionBar = pt.DetectedAtIndex;
SetBarColor(bars, detectionBar, WLColor.Blue);
DrawLine(
detectionBar,
bars.Close[detectionBar],
pt.XIndex,
bars.Close[detectionBar],
WLColor.Blue,
2);
double change = bars.Close[detectionBar] / pt.YValue - 1.0;
double bump = pt.Type == PeakTroughType.Peak ? 0.995 : 1.005;
DrawText(
change.ToString("0.00%"),
pt.XIndex,
bars.Close[detectionBar] * bump,
WLColor.Black,
10);
}
}
public override void Execute(BarHistory bars, int idx)
{
}
}
}
public Dictionary<string, TrendLine> TrendLineCache
Contains a Dictionary of previously calculated TrendLine instances, keyed by string.
This cache can be used to associate calculated trendlines with the PeakTrough and avoid recalculating them.