using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using System.Linq;namespace WealthLab.Strategies { public class TASC201708 : WealthScript { private StrategyParameter paramLookback1; private StrategyParameter paramLookback2; private StrategyParameter paramLookback21; private StrategyParameter paramLookback3; private StrategyParameter paramLookback31; private StrategyParameter paramLookback32; private StrategyParameter paramExitAfter; private StrategyParameter paramGap; public TASC201708() { paramLookback1 = CreateParameter("AP bars",1,0,4,1); paramLookback2 = CreateParameter("MP1 bars",3,0,4,1); paramLookback3 = CreateParameter("MBP1 bars",0,0,4,1); paramLookback21 = CreateParameter("MP2 bars",2,0,4,1); paramLookback31 = CreateParameter("MBP2 bars",1,0,4,1); paramLookback32 = CreateParameter("MBP3 bars",2,0,4,1); paramExitAfter = CreateParameter("Exit after",8,1,20,1); paramGap = CreateParameter("Entry gap",0.08,0.01,1.0,0.01); } protected override void Execute() { var averagePrice = (Open+Close+High+Low)/4; var medPrice = AveragePrice.Series(Bars); var medBodyPrice = (Open+Close)/2; var barsAvgPrice = paramLookback1.ValueInt; var barsMedPrice = paramLookback2.ValueInt; var barsMedPrice2 = paramLookback2.ValueInt; var barsMedBodyPrice = paramLookback3.ValueInt; var barsMedBodyPrice2 = paramLookback31.ValueInt; var barsMedBodyPrice3 = paramLookback32.ValueInt; var bars2Exit = paramExitAfter.ValueInt; int[] lookback = new int[]{barsAvgPrice,barsMedPrice,barsMedPrice2, barsMedBodyPrice,barsMedBodyPrice2,barsMedBodyPrice3}; int startBar = lookback.Max() + 1; var sfasatura = -paramGap.Value; for(int bar = GetTradingLoopStartBar(startBar); bar < Bars.Count; bar++) { if (IsLastPositionActive) { /* Exit after N days */ Position p = LastPosition; if ( bar+1 - p.EntryBar >= bars2Exit ) SellAtMarket( bar+1, p, "Timed" ); } else { /* AI Pattern Generator */ if( (averagePrice[bar - barsAvgPrice] < medPrice[bar - barsMedPrice]) && (medBodyPrice[bar - barsMedBodyPrice] < medPrice[bar - barsMedPrice2]) && (medBodyPrice[bar - barsMedBodyPrice2] < medBodyPrice[bar - barsMedBodyPrice3]) ) { var entryLabel = string.Format("AP[{0}],MP1[{1}],MP2[{2}],MBP1[{3}],MBP2[{4}],MBP3[{5}]", barsAvgPrice, barsMedPrice, barsMedPrice2, barsMedBodyPrice, barsMedBodyPrice2, barsMedBodyPrice3 ); BuyAtLimit(bar+1, Low[bar] + sfasatura, entryLabel); } } } } } }