-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
-
Hi - After a strategy is finished being backtested, I wanted to find out if we're currently in an open trade for this strategy.
Let's say I run a simple moving average crossover strategy such as:
Screenshot 2023年03月12日 at 11 27 41 AM
At the conclusion of the backtest, I'd like to know if we currently have an open position (ie. the exit criteria havent been triggered as of the end of my dataset).
When I query stats["_trades"] it always shows the last trade as "exited". If you see this image below, you can see that it exited the trade on 3/10/23 which is the last day of my dataset, but that trade, by the strategy conditions, should still be open.
Screenshot 2023年03月12日 at 11 22 25 AM
So my two questions are:
- Does backtesting always exit the trade on the last day of your dataset regardless if the exit criteria haven't been met?
- How would I, at the conclusion of the backtest, know if a current open trade exists for that strategy? ie. In the above code where I have
y=stats["_trades"]
what would I use to see if an open trade currently exists?
Thanks for any insight
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
Does backtesting always exit the trade on the last day of your dataset regardless if the exit criteria haven't been met?
Yes and this is by design
If you want to see open trades that should not be closed, just look for those closed on the last bar
Beta Was this translation helpful? Give feedback.