using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class TradingGapReversals : WealthScript { private StrategyParameter gapPct; private StrategyParameter buyStp; private StrategyParameter sellStp; public TradingGapReversals() { gapPct = CreateParameter("Gap %", 10, 1, 30, 1); buyStp = CreateParameter("Buy stop", 0.50, 0.10, 1.0, 0.1); sellStp = CreateParameter("Sell stop", 0.40, 0.10, 1.0, 0.1); } protected override void Execute() { DataSeries trigger = Bars.Close * (1 - gapPct.Value / 100) >> 1; int cnt = 0; for (int bar = 1; bar < Bars.Count; bar++) { if( Date[bar].Date > Date[bar-1].Date ) cnt++; Position p = LastPosition; if (IsLastPositionActive) { double amount = p.MFEAsOfBar(bar) / p.Shares + p.EntryPrice - sellStp.Value; if(!SellAtStop(bar+1, p, p.EntryPrice - sellStp.Value, "Initial")) if(!SellAtTrailingStop(bar+1, p, amount, "Trailing")) SellAtLimit(bar+1, p, p.AutoProfitLevel, "Gap closed"); } else if (p == null || !p.Active && p.EntryBar < (bar - Bars.IntradayBarNumber(bar))) { if( cnt > 0 ) { int firstBarToday = bar - Bars.IntradayBarNumber(bar); int lastBarYesterday = firstBarToday - 1; bool priceFilter = (Close[firstBarToday] >= 20) && (Close[firstBarToday] <= 70); bool gap = (Open[firstBarToday] <= trigger[lastBarYesterday]); if( priceFilter && gap && Bars.IntradayBarNumber(bar) > 0 ) { if( BuyAtStop(bar + 1, Low[firstBarToday] + buyStp.Value ) != null ) LastPosition.AutoProfitLevel = Close[lastBarYesterday]; } } } } } } }