Log in to see Cloud of Tags

Wealth-Lab Wiki

Pattern Recognition

RSS

Syntax


public static MTop CheckTop(this WealthScript obj, int bar, DataSeries ds, int lookback, double pctRetrace, double threshold)
public static WBottom CheckBottom(this WealthScript obj, int bar, DataSeries ds, int lookback, double pctRetrace, double threshold)

public MTop CheckTop(int bar, DataSeries ds, int lookback, double pctRetrace, double threshold) public WBottom CheckBottom(int bar, DataSeries ds, int lookback, double pctRetrace, double threshold)

public enum WBottom { None, Detected, PreviousDetection }; public enum MTop { None, Detected, PreviousDetection };

Parameter Description

Enumerations:
WBottomNone (no detection), Detected (occurs only on the bar of detection for a trigger condition),
and PreviousDetection (lets you use the detection as a "set up" for other entry/exit conditions)
MTopNone (no detection), Detected (occurs only on the bar of detection for a trigger condition),
and PreviousDetection (lets you use the detection as a "set up" for other entry/exit conditions)

Methods:
barThe bar of detection: function returns true if MTop (WBottom) is detected on bar
dsData Series, e.g. High, Close, etc.
lookbackThe top(bottom) must be a peak(trough) in the lookback period
pctRetraceMax percentage difference between the two peaks/troughs

Description

Created by Robert Sucher, this is a framework for pattern recognition in Wealth-Lab 6. Detects the following chart patterns: M Top, W Bottom (i.e. Double Top/Bottom).

Example

Image

Here is an example illustrating how to use the method in your Strategy code:

Example using C# extension methods:


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() { int lookback = 200; for(int bar = lookback; bar < Bars.Count; bar++) { CommonSignalsEx.WBottom cb = this.CheckBottom(bar, Low, lookback, 8, 1.5); CommonSignalsEx.MTop ct = this.CheckTop(bar, High, lookback, 8, 1.5); if ( cb == CommonSignalsEx.WBottom.Detected ) { BuyAtClose(bar); ExitAtMarket(bar + 1, LastPosition); } else if ( ct == CommonSignalsEx.MTop.Detected ) { ShortAtClose(bar); ExitAtMarket(bar + 1, LastPosition); } if ( cb == CommonSignalsEx.WBottom.PreviousDetection ) SetBackgroundColor(bar, Color.LightBlue); if ( ct == CommonSignalsEx.MTop.PreviousDetection ) SetBackgroundColor(bar, Color.LightBlue); } } } }

Legacy syntax example:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Components; /*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { //before Wealth-Lab 6.2: //Calculate c = new Calculate( this );

//from Wealth-Lab 6.2+ PatternRecognition c = new PatternRecognition( this ); int lookback = 200; for(int bar = lookback; bar < Bars.Count; bar++) { WBottom cb = c.CheckBottom(bar, Low, lookback, 8, 1.5); MTop ct = c.CheckTop(bar, High, lookback, 8, 1.5); if ( cb == WBottom.Detected ) { BuyAtClose(bar); ExitAtMarket(bar + 1, LastPosition); } else if ( ct == MTop.Detected ) { ShortAtClose(bar); ExitAtMarket(bar + 1, LastPosition); } if ( cb == WBottom.PreviousDetection ) SetBackgroundColor(bar, Color.LightBlue); if ( ct == MTop.PreviousDetection ) SetBackgroundColor(bar, Color.LightBlue); } } } }

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.