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:7I 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:
https://www.backtrader.com/blog/posts/2016-07-13-day-in-steps/day-in-steps.htmlThanks in advance
-
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
backtrader
will execute it if price will allow it.Here is more description on the order execution -
https://www.backtrader.com/docu/order-creation-execution/order-creation-execution.htmlAlso you may want to check parallel thread about stop losses -
https://community.backtrader.com/topic/163/trailing-stop-loss -
To execute on the same day you want to use
cheat-on-close
. See: Docs - BrokerYou 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-close
makes no difference with regards to an existing position. This functionality is implemented in the broker and looks only at what anorder
is 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.