Syntax
public static bool CooledOff(this WealthScript obj, int bar, int time)
public bool CooledOff(int bar, int time)
Parameter Description
bar | Bar number |
time | The number of bars since last position is exited to inhibit a new entry |
Description
This function, created by
Dion Kurczek, will cause a Strategy to wait for a certain period of time before entering a new position once the preceding position is closed.
Example
Below is a demo Strategy that shows how to use the function. Drag the StrategyParameter slider to vary the number of bars since last position is exited.
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 CooledOffDemo : WealthScript
{
private StrategyParameter paramBars;
public CooledOffDemo()
{
paramBars = CreateParameter("Delay entry", 20, 1, 50, 1);
}
protected override void Execute()
{
for(int bar = 20; bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
SellAtStop( bar+1, LastPosition, Lowest.Series( Low, 20 )[bar] );
else
if( this.CooledOff( bar, paramBars.ValueInt ) )
BuyAtStop( bar+1, Highest.Series( High, 20 )[bar] );
}
}
}
}
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 CooledOffDemo : WealthScript
{
private StrategyParameter paramBars;
public CooledOffDemo()
{
paramBars = CreateParameter("Delay entry", 20, 1, 50, 1);
}
protected override void Execute()
{
/* Create an instance of the clas that contains the CooledOff function,
passing WealthScript as "this" */
PositionHelper ph = new PositionHelper( this );
for(int bar = 20; bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
SellAtStop( bar+1, LastPosition, Lowest.Series( Low, 20 )[bar] );
else
if( ph.CooledOff( bar, paramBars.ValueInt ) )
BuyAtStop( bar+1, Highest.Series( High, 20 )[bar] );
}
}
}
}