Square off on last/current bar close?
-
How do I add a mandatory square off on the last bar of the backtest or a square off on the close of the current bar when a condition is met.
Thanks in advance.
-
And what is a "square off"?
-
@backtrader said in Square off on last/current bar close?:
And what is a "square off"?
Means closing all open position. I want to close my open position when the condition met.
-
@Deepak-Pandey said in Square off on last/current bar close?:
on the last bar of the backtest
The last bar is the last and has already been seen by the broker. You cannot close positions when the bar is the last one. Only if you use
cheat-on-open
(which means you do it before seeing the bar unless you choose to really cheat yourself)- Docs - Broker - Cheat-On-Open - https://www.backtrader.com/docu/cerebro/cheat-on-open/cheat-on-open/
@Deepak-Pandey said in Square off on last/current bar close?:
on the close of the current bar when a condition is met
Using
cheat-on-close
in the broker and methods of the strategy, likeclose
,buy
,sell
,order_target_percent
, depending on your personal taste.