Page History: ZigZag Class
Compare Page Revisions
Page Revision: 2014/04/02 12:04
Syntax
public ZigZag(WealthScript ws, double reversalAmount, bool initializeAsTrough, PeakTroughMode ptmode)
public ZigZag(WealthScript ws, DataSeries singleSeries, double reversalAmount, bool initializeAsTrough, PeakTroughMode ptmode)
public DataSeries PeakSeries()
public DataSeries PeakBarSeries()
public DataSeries TroughSeries()
public DataSeries TroughBarSeries()
public DataSeries PeakTroughSeries()
public void Draw(Color upColor, Color downColor, LineStyle style, int width)
public void PlotPeakTrough(Color plotColor, int width)
public Dictionary<int, ZZ> ZZs
ws | A WealthScript reference. Pass this |
reversalAmount | The amount of price reversal in percentage or points per the ptmode parameter that determines when a peak or trough as formed. |
initializeAsTrough | Pass true or false to initialize the data series as a peak or a trough. Generally it does not matter how you initialize the method, but for short series in which the first assumption is important, you can control that. |
PeakTroughMode | Enumeration that determines if the reversalAmount parameter is measured in percentage or points. |
singleSeries | The second overload for ZigZag() allows you to specify a single series on which the ZigZag is calculated. In the other method, the ZigZag is formed between ws.Bars.High and ws.Bars.Low. |
reversalAmount | The amount of price reversal in percentage or points per the ptmode parameter that determines when a peak or trough as formed. |
Public Members
public Dictionary
ZZs
Dictionary containing a reference to a ZZ object for each bar.
ZZ object | Properties: |
int lastPeakBar | Returns the bar number of the most recently detected peak. |
int lastTroughBar | Returns the bar number of the most recently detected trough. |
int lastPeakOrTroughBar | Returns the bar number of the most recently detected peak or trough. |
double lastPeakPrice | Returns the price of the most recently detected peak. |
double lastTroughPrice | Returns the price of the most recently detected trough. |
double lastPeakOrTroughPrice | Returns the price of the most recently detected peak or trough. |
bool peakDetected | Returns true when a peak of the ZigZag reversal percentage has been detected. The value remains true until a new trough is detected. |
bool troughDetected | Returns true when a trough of the ZigZag reversal percentage has been detected. The value remains true until a new peak is detected. |
Information from the ZZ object should be used when backtesting strategies involving peaks/troughs as it allows you to know when a peak/trough had been detected on a particular without peeking. Although you can manipulate the values of a ZZ object, you should not do it. Access a ZZ object at a particular bar from the Dictionary and use the information from its properties to identify the most recent peak/trough bars/prices or if a peak/trough has been detected.
Description
This ZigZag class simplifies creating, plotting, and indicator creation for strategies that require a zigzag method.
Example
The example demonstrates the simplicity of creating and plotting zigzags as well as shows the difference between a zigzag based on a High/Low and one that uses the Close series only.
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Components;
namespace WealthLab.Strategies
{
public class ZZdemo : WealthScript
{
protected override void Execute()
{
// Zigzag Bars.High/Low default
ZigZag zg = new ZigZag(this, 8, true, PeakTroughMode.Percent);
zg.Draw(Color.Gray, Color.Gray, LineStyle.Solid, 2);
// ZigZag for a single series
ZigZag zz = new ZigZag(this, Close, 8, true, PeakTroughMode.Percent);
zz.Draw( Color.Blue, Color.Red, LineStyle.Solid, 2);
zz.PlotPeakTrough(Color.Blue, 3);
// Zigzags aren't just for the standard price series. You can apply them to any DataSeries like an indicator
DataSeries rsi = RSI.Series(Close, 14);
ChartPane rsiPane = CreatePane(50, true, true);
PlotSeries(rsiPane, rsi, Color.Black, LineStyle.Solid, 2);
ZigZag zzrsi = new ZigZag(this, rsi, 20, true, PeakTroughMode.Value);
zzrsi.Draw(rsiPane, Color.Blue, Color.Red, LineStyle.Solid, 2);
// Highlight the bars on which the most-recent peak or trough was detected for the High/Low ZigZag object, zg
for (int bar = 1; bar < Bars.Count; bar++)
{
ZZ zzo = zg.ZZs[bar];
if (zzo.peakDetected)
SetBackgroundColor(bar, Color.FromArgb(40, Color.Blue));
if (zzo.troughDetected)
SetBackgroundColor(bar, Color.FromArgb(40, Color.Red));
}
}
}
}