pmbf8
- ago
WAS: "Signal Tab Doesn't Show a Buy Trade Alert, But Backtest Results Show a Buy Transaction On Next Day"

Hi Everyone,

For the code shown below, can I ask why the backtest ending on 14th Mar 2023 didn't show a buy trade alert in the Signal tab for symbol, NI, though this symbol was bought on 15th Mar 2023 for backtest ending on 15th Mar 2023?

The answer might be related to the sizer, Max Risk % Limited to % of Equity, as I see the buy signal appearing when I change the Position Sizer to Max Risk Percent (2%) or Percent of Equity (10%), though I am unable to confirm on the rationale behind this scenario.

CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace TestScript1 {    //---Strategy Settings---    //Portfolio: S&P 500 (WealthData)    //Datascale: Daily    //Date Range: 7/13/2018 to 3/15/2023 v.s. 7/13/2018 to 3/14/2023    //Sizing: Advanced Pos Sizer, Max Risk (2%) Limited to (10%) of Equity    //Starting Capital: 1000000    //Margin Factor: 1.0    //Retain NSF Position: Unchecked        public class MyStrategy : UserStrategyBase    {       public override void Initialize(BarHistory bars)       {          //--- Indicators ---          sma20 = new SMA(bars.Close, 20);          sma40 = new SMA(bars.Close, 40);          roc100 = new ROC(bars.Close, 100);          StartIndex = 200;       }       public override void Execute(BarHistory bars, int idx)       {          //=== Exit ===          Position p = LastOpenPosition;          if (p != null)          {             CloseAtTrailingStop(p, TrailingStopType.PercentC, 25, "Trailing Stop");             ClosePosition(p, OrderType.Stop, 0.95 * p.EntryPrice, "Stop Loss");          }          //=== Entry ===          // Prevents Overlapping Position          if (HasOpenPosition(bars, PositionType.Long)) return;          // Signal          if(!sma20.CrossesOver(sma40, idx)) return;          Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Market, 0.0, 1, "Long Entry");          //--- Ranking ---          t.Weight = roc100[idx];       }       // private variables       IndicatorBase sma20, sma40, roc100;    } }


Details of Signal Tab for Backtest Ending on 14th Mar 2023


Position Detail of NI for Backtest Ending on 15th Mar 2023


Thank you,
pmbf

0
250
0 Replies

Reply

Bookmark

Sort
Currently there are no replies yet. Please check back later.