本页主题: WL5 code - Bollinger Band breakout-anticipation system (Futures & Options Trader 01-2008) 打印 | 加为IE收藏 | 复制链接 | 收藏主题 | 上一主题 | 下一主题

复活
计划你的交易,交易你的计划。
级别: 总版主


精华: 1
发帖: 35
威望: 38 点
金钱: 370 RMB
贡献值: 0 点
在线时间:216(小时)
注册时间:2008-04-14
最后登录:2008-08-19

 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 );
                        }
                }
            }
        }
    }
}

顶端 Posted: 2008-05-28 14:38 | [楼 主]
帖子浏览记录 版块浏览记录
交易者部落 » Wealth-Lab 5策略库

Time now is:08-22 11:23, Gzip enabled 浙ICP备06052510号
Powered by PHPWind v6.0 Certificate Code © 2003-08 PHPWind.com Corporation