Log in to see Cloud of Tags

Wealth-Lab Wiki

Page History: ZigZag Class

Compare Page Revisions



« Older Revision - Back to Page History - Current Revision


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

wsA WealthScript reference. Pass this
reversalAmountThe amount of price reversal in percentage or points per the ptmode parameter that determines when a peak or trough as formed.
initializeAsTroughPass 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.
singleSeriesThe 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.
reversalAmountThe 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 objectProperties:
int lastPeakBar Returns the bar number of the most recently detected peak.
int lastTroughBarReturns the bar number of the most recently detected trough.
int lastPeakOrTroughBarReturns the bar number of the most recently detected peak or trough.
double lastPeakPriceReturns the price of the most recently detected peak.
double lastTroughPriceReturns the price of the most recently detected trough.
double lastPeakOrTroughPriceReturns the price of the most recently detected peak or trough.
bool peakDetectedReturns true when a peak of the ZigZag reversal percentage has been detected. The value remains true until a new trough is detected.
bool troughDetectedReturns 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)); } } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.


ScrewTurn Wiki. Some of the icons created by FamFamFam.