using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class TASC201603 : WealthScript { private StrategyParameter paramTrailing; private StrategyParameter paramThreshold; private StrategyParameter paramRange; private StrategyParameter paramADX; public TASC201603() { paramADX = CreateParameter("ADX above", 40, 30, 90, 10); paramRange = CreateParameter("15-day range, $", 5, 1, 10, 1); paramThreshold = CreateParameter("Cents above", 0.50, 0, 1.0, 0.1); paramTrailing = CreateParameter("Trailing stop $", 2, 1, 10, 1); } protected override void Execute() { if( !Bars.IsIntraday ) { DrawLabel(PricePane, "Requires intraday data"); Abort(); } else { SetScaleDaily(); DataSeries FifteenDayHigh = Highest.Series(High,15); DataSeries FifteenDayLow = Lowest.Series(Low,15); DataSeries FifteenDayRange = FifteenDayHigh - FifteenDayLow; RestoreScale(); FifteenDayHigh = Synchronize(FifteenDayHigh); FifteenDayRange = Synchronize(FifteenDayRange); FifteenDayRange.Description = "The fifteen day range"; var intradayADX = ADX.Series(Bars,14); intradayADX.Description = "Intraday ADX (14)"; PlotSeries(PricePane,FifteenDayHigh,Color.Blue,LineStyle.Solid,1); ChartPane rangePane = CreatePane(30,true,true); PlotSeries(rangePane,FifteenDayRange,Color.Violet,LineStyle.Solid,1); ChartPane adxPane = CreatePane(30,false,true); PlotSeries(adxPane,intradayADX,Color.Red,LineStyle.Solid,1); DrawHorzLine(adxPane,40,Color.Green,LineStyle.Dashed,1); for(int bar = GetTradingLoopStartBar(1); bar < Bars.Count; bar++) { if (IsLastPositionActive) { Position p = LastPosition; double amount = p.MFEAsOfBar(bar) / p.Shares + p.EntryPrice - paramTrailing.Value; SellAtTrailingStop(bar + 1, p, amount, "$2 Trailing"); } else { if( (Closebar > 20.0) && (Closebar < 70.0) ) if(FifteenDayRangebar > paramRange.Value) if(intradayADXbar > paramADX.ValueInt) BuyAtStop(bar+1, FifteenDayHighbar + paramThreshold.Value); } } } } } }