Hi Team,
Can I ask why the following code results in only a Stop Loss order instead of both Stop Loss and Trailing Stop Loss Orders in the Signals tab of Strategy?
My understanding is that the trading signals in the signal tab are notifications for orders to be placed in the market for the next bar. Hence, after the stock has been bought on 12th Oct 2022 based on the below code, Stop Loss and Trailing Stop Loss orders will be executed for every bar processed by "public override void Execute". As the backtest ends on 12th July 2023 and the stock position was still opened then, the 2 outstanding Stop Loss and Trailing Stop Loss Orders should appear in the Signals tab for the user to place in Order Manager.
Look forward to hearing from you.
Signal Tab Showing Only 1 Stop Loss Order
Backtest Results -> Positions
Thank you,
pmbf
Can I ask why the following code results in only a Stop Loss order instead of both Stop Loss and Trailing Stop Loss Orders in the Signals tab of Strategy?
My understanding is that the trading signals in the signal tab are notifications for orders to be placed in the market for the next bar. Hence, after the stock has been bought on 12th Oct 2022 based on the below code, Stop Loss and Trailing Stop Loss orders will be executed for every bar processed by "public override void Execute". As the backtest ends on 12th July 2023 and the stock position was still opened then, the 2 outstanding Stop Loss and Trailing Stop Loss Orders should appear in the Signals tab for the user to place in Order Manager.
Look forward to hearing from you.
CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace TestScript1 { //---Strategy Settings--- //symbol: VRTX //Date Range: 7/12/2021 to 7/12/2023 //Sizing: 100% of Equity, //Starting Capital: 1000000 //Margin Factor: 1.0 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; } }
Signal Tab Showing Only 1 Stop Loss Order
Backtest Results -> Positions
Thank you,
pmbf
Rename
It doesn’t make sense to submit two stop orders at different prices, so WL will not submit the redundant stop order, the one with a price further away from the current price.
Thanks Glitch.
Your Response
Post
Edit Post
Login is required