WL5 code - Bollinger Band breakout-anticipation system (Futures & Options Trader 01-2008)
published by Eugene. on 2/23/2008
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;
namespace WealthLab.Strategies { public class BBSqueezeFOT : WealthScript { //Create parameters private StrategyParameter bbPeriod; private StrategyParameter bbStdDev; private StrategyParameter bbSqueezeLookback;
public BBSqueezeFOT() { bbPeriod = CreateParameter("Bands Period", 20, 5, 50, 5); bbStdDev = CreateParameter("Std Dev", 2, 1, 5, 0.25); bbSqueezeLookback = CreateParameter("Squeeze lookback", 100, 5, 150, 5 ); } protected override void Execute() { HideVolume(); int BBAvg = bbPeriod.ValueInt; double BBStdev = bbStdDev.Value; int SqueezeLen = bbSqueezeLookback.ValueInt; double PctBBWMin = 0; double level = 0; //Obtain parameters values int bbPer = bbPeriod.ValueInt; double bbSD = bbStdDev.Value; BBandLower bbL = BBandLower.Series( Close, bbPer, bbSD ); BBandUpper bbU = BBandUpper.Series( Close, bbPer, bbSD ); PlotSeriesFillBand( PricePane, bbU, bbL, Color.Silver, Color.Empty, LineStyle.Solid, 2); DataSeries PctBBW = ( ( bbU - bbL ) / SMA.Series( Close, BBAvg ) ) * 100; PctBBW.Description = "% BB Width"; ChartPane PctBBWPane = CreatePane( 30, true, true ); PlotSeries( PctBBWPane, PctBBW, Color.Silver, WealthLab.LineStyle.Solid, 2 ); PlotSeries( PctBBWPane, Lowest.Series( PctBBW, SqueezeLen ), Color.Red, WealthLab.LineStyle.Dots, 4 ); for(int bar = Math.Max( SqueezeLen, BBAvg ); bar < Bars.Count; bar++) { if( PctBBW[bar] <= Lowest.Series( PctBBW, SqueezeLen )[bar-1] ) if ( ( bbU[bar] - bbL[bar] ) < 2.5*ATR.Series( Bars,10 )[bar] ) SetBackgroundColor( bar, Color.FromArgb(231, 255, 231) ); if (IsLastPositionActive) { // Exit trade after 10 bars if ( bar+1 - LastPosition.EntryBar >= 10 ) ExitAtMarket( bar+1, LastPosition, "Time-Based" );
// or exit at 5-day channel stop level = ( LastPosition.PositionType == PositionType.Long) ? Lowest.Series( Low, 5 )[bar] : Highest.Series( High, 5 )[bar]; ExitAtStop( bar+1, LastPosition, level ); } else { if( PctBBW[bar] <= Lowest.Series( PctBBW, SqueezeLen )[bar-1] ) if ( ( bbU[bar] - bbL[bar] ) < 2.5*ATR.Series( Bars,10 )[bar] ) if( BuyAtStop( bar+1, High[bar]+Bars.SymbolInfo.Tick ) == null ) { ShortAtStop( bar+1, Low[bar]-Bars.SymbolInfo.Tick ); } } } } } }
|