using System; using System.Collections.Generic; using System.Text; using WealthLab; using WealthLab.Indicators; using System.Drawing; namespace WealthLabCompile { class QQQQCrash : WealthScript { //Create parameters private StrategyParameter bbPeriod; private StrategyParameter bbStdDev; private StrategyParameter exitDays; public QQQQCrash() { bbPeriod = CreateParameter("Bollinger Period", 10, 6, 20, 2); bbStdDev = CreateParameter("Std Dev", 1.5, 1, 3, 0.25); exitDays = CreateParameter("Timed Exit", 20, 1, 30, 1); } protected override void Execute() { //Obtain parameters values int bbPer = bbPeriod.ValueInt; double bbSD = bbStdDev.Value; int timedExit = exitDays.ValueInt; BBandLower bbL = BBandLower.Series( Close, bbPer, bbSD ); PlotSeries(PricePane, bbL, Color.Silver, LineStyle.Solid, 2); for (int bar = bbPer; bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position Pos = LastPosition; if (bar + 1 - Pos.EntryBar >= timedExit) SellAtMarket(bar + 1, Pos, "Time-based"); else if (Close[bar] > (Pos.EntryPrice * 1.072)) SellAtMarket(bar + 1, Pos); else if (Close[bar] < Pos.EntryPrice * (1 - 15 / 100.0d)) SellAtMarket(bar + 1, Pos, "Stop-Exit"); } else { if (Close[bar] < bbL[bar]) BuyAtMarket(bar + 1); } } } } }