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

Are trades based on signals lagged? #541

Answered by kernc
replacementAI asked this question in Q&A
Discussion options

My forecasted price and my open price are both in the same dataframe. When I run the backtest, it doesn't buy when the buy condition (forecasted price > open price) is fulfilled, yet it buys the next day despite the sell condition being fulfilled (forecasted price < open price) I've repeatedly checked my code and checked the csv the dataframe is reading, and nothing is suggesting that I formatted the data incorrectly. If someone could follow up with this I'd be grateful.

You must be logged in to vote

Replies: 2 comments 2 replies

Comment options

Just tested it on another ticker, and yes, trade signals are lagged. This is incredibly confusing, especially compounded with the fact that the backtesting model always sells on the last candle...

You must be logged in to vote
0 replies
Comment options

IIUC, have you tried with trade_on_close=True?

You must be logged in to vote
2 replies
Comment options

Apologies, I should have read the documentation where it states that when buy/sell condition is met, a buy order will be placed on next days open. And if trade_on_close=True, it will buy on close on the same candle. Is it possible to make orders on open of the same candle?

Comment options

When is it that you are going to be deciding upon your trade then? Do you often place your market order for 8 AM at 11 AM? 🤨 If you need more timely precision, use more fine-grained data. It's all in the tutorial. 😛

Answer selected by replacementAI
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 によって変換されたページ (->オリジナル) /