Question on order
I have a question on order and how to achieve it. In a day assume price pattern is like this:
open 10, High: 11 Low:6, Close:7
I want to do checking on these prices and give order to execute on the same day.
For example, I want to check whether my stop loss that is set at 8 is hit. In this case since low is 6, so it falls within that range. So I want to exit position on the same day at 8 (my stop loss). Is it feasible?
An additional point, I have a stop and target price, it needs to check both and see whether price is hit and issue order accordingly.
I referred this link. But since it has only open, it may not serve my purpose:
Thanks in advance
ab_trader last edited by
In case of stop loss and take profit orders you don't need to check prices. Just issue the appropriate order(stop or limit) and
backtraderwill execute it if price will allow it.
Here is more description on the order execution -
Also you may want to check parallel thread about stop losses -
To execute on the same day you want to use
cheat-on-close. See: Docs - Broker
You can evaluate the prices and issue an order which will be executed on the same bar.
@ab_trader Thank you very much for guiding. It was very helpful.
@backtrader Thanks a lot. I tried. Its very easy way to do. I suspect cheat-on-close behaves differently depending on whether we are acting on position already present (self.position). When acted on a position thats freshly initiated (if not self.position), its taking today's value. Otherwise its moving to next day value. I didn't investigate in detail. But thought will share observation anyway.
cheat-on-closemakes no difference with regards to an existing position. This functionality is implemented in the broker and looks only at what an
orderis asking for.
If you think there is something wrong, a sample would be needed to understand what's happening.
@backtrader You are right. I messed up elsewhere. Kindly ignore. Sorry.