Generate Stop Loss orders at Entry
Author: kbellare
Creation Date: 5/28/2015 6:14 PM
profile picture

kbellare

#1
How do i enter Stop orders and Profit Take orders at Entry bar? 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.

- 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.

- 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.


CODE:
Please log in to see this code.


CODE:
Please log in to see this code.
profile picture

Eugene

#2
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.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).