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:
WBottom | None (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) |
MTop | None (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:
bar | The bar of detection: function returns true if MTop (WBottom) is detected on bar |
ds | Data Series, e.g. High, Close, etc. |
lookback | The top(bottom) must be a peak(trough) in the lookback period |
pctRetrace | Max 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
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);
}
}
}
}