QUOTE:
- Neither approach seems to peek ahead, because the StopLoss and Profit Taking are based only on p.EntryPrice and no other indicator that is calculated at Entry Bar.
Of course this is incorrect. You can not know if the stop or profit is hit first. Just give it a thought: entry price may be crossed back and forth within the day and you don't know the order of events unless you peek into intraday data. On this picture, what happened first: the stop or the profit?
Adding to the
FAQ where it's explained, let's assume you bought some time during the downfall. Afterwards the price could have fallen deeper, exiting you with an immediate loss. Or, the price could have immediately rebounded, triggering the profit taking, and
then fell even deeper when you were lucky to have already been out of the position? Without making a guess or
looking into intraday data, you just don't know.
QUOTE:
- Brokerages allow submitting attached StopLoss and ProfitTake orders with the Entry Order (and could execute them in the same bar), so this feature is an important feature to be supported in WealthLab, if it doesn't support today.
It is supported: User Guide > Preferences > Trading >
Allow Same Bar Exits for Auto-Trading.
QUOTE:
I've tried 2 different approaches (code snippets below), and both generate the Stop Sell trigger at the Next Bar after EntryBar, not at Entry Bar.
For a deeper understanding, see Cone's reply #6 in this thread:
Same Bar Exit. Note that it assumes a market entry order, so the answer is not justifying your exit scenario.