Hi,
I would like to create a scanner for gaps up/down. I used a building block strategy on SPY using a specific date range where I know there is a gap up (22 and 23d August 2023). So building block reads buy at market, gap up at bar open. I put an arbitrary sell after 8 bars to test. If I tun a backtest it successfully picks up the gap, buy and sells.
I then open it as a c# coded strategy and add the line for it to be a scanner and rerun the test. Im expecting it to alert if it successfully identifies the gap but this doesnt work.
I would like to create a scanner for gaps up/down. I used a building block strategy on SPY using a specific date range where I know there is a gap up (22 and 23d August 2023). So building block reads buy at market, gap up at bar open. I put an arbitrary sell after 8 bars to test. If I tun a backtest it successfully picks up the gap, buy and sells.
I then open it as a c# coded strategy and add the line for it to be a scanner and rerun the test. Im expecting it to alert if it successfully identifies the gap but this doesnt work.
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript5 { public class MyStrategy : UserStrategyBase { public MyStrategy() : base() { StartIndex = 0; } public override void Initialize(BarHistory bars) { foreach(IndicatorBase ib in _startIndexList) if (ib.FirstValidIndex > StartIndex) StartIndex = ib.FirstValidIndex; } public override void Execute(BarHistory bars, int idx) { if (idx < bars.Count - 1) return; int index = idx; Position foundPosition0 = FindOpenPosition(0); bool condition0; if (foundPosition0 == null) { condition0 = false; { if (bars.IsGapUp(index)) { condition0 = true; } } if (condition0) { _transaction = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0, 0, "Buy At Market (1)"); } } else { condition0 = false; { pos = LastOpenPosition; if (pos == null || (index - pos.EntryBar) >= 8) { condition0 = true; } } if (condition0) { Backtester.CancelationCode = 108; ClosePosition(foundPosition0, OrderType.Market, 0, "Sell At Market (1)"); } } } public override void NewWFOInterval(BarHistory bars) { } private Position pos; private Transaction _transaction; private List<IndicatorBase> _startIndexList = new List<IndicatorBase>(); } }
Rename
It does work, producing new entry Signals for tomorrow as expected.
It's not clear by the description of IsGapUp(), but "gap up" is defined as the opening price greater than the previous bar's High.
Your Response
Post
Edit Post
Login is required