Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Does backtesting always conclude by closing the last trade? | How to see open trades? #933

Unanswered
cgdutoit asked this question in Q&A
Discussion options

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:

  1. Does backtesting always exit the trade on the last day of your dataset regardless if the exit criteria haven't been met?
  2. 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

You must be logged in to vote

Replies: 1 comment

Comment options

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

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /