-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
-
When you are using an indicator that only uses close data as input, it's possible to see (by looping trough the open -> low & open -> high values) at which point the trade actually is been opened. Does this library makes use of this? Or does anyone know a library that does this? By doing this, the actual backtesting result can be closer to the real world trading result of the same strategy (if you are only making us of close base indicators such as macd, ema, ...).
Beta Was this translation helpful? Give feedback.
All reactions
-
😕 1
Replies: 1 comment 3 replies
-
Probably, yes. Not sure I get it right. Can you show an example of what you mean?
Beta Was this translation helpful? Give feedback.
All reactions
-
Okay, no problem. Take for example the MACD indicator (which is only based on close values) would he takes in calculation that trade is been opened on the close price like in this example:
Or does the library loop trough the values from the open price until the close price (and even further until the high price because if the high is so high that a signal to buy is been triggered but on the close price there isn't any signal anymore) to see where he would he opened the trade exactly? Example:
Beta Was this translation helpful? Give feedback.
All reactions
-
Not sure if I am understanding you perfectly, possibly because of the grammar. Just to be clear, most of the price time series data you will be working with will be in OHLCV format. Open, High, Low, Close, and Volume. The term "close" can be confusing because sometimes people refer to closing out a trade but in this sense, the closing value is the last traded value in a given period, sometimes referred to as a "candle". If your signal is triggered based on the closing value of a candle, the default is to enter the trade on the opening price of the next candle. (you can customize this if you would like to use something else) It seems like you are using the term "closing price/value" to refer to all of the trades that occurred in the market in between the candle opening period and closing period. If you are building a simple and straightforward backtest like those described in the documentation then your strategy would be blind to all of the "trades" that happened inside of the candle period. It would only be looking at the open, high, low, and closing prices for the period. Given that, it would enter an order to buy or sell at the next "opening price" after your signal crossed, again, this is assuming you are using the default options.
A simple example:
If you were using daily data, and your MACD signal crossed yesterday based on the closing price, then this morning, you would enter your order to be the first trade at the opening price.
It is important to note though that the library is very robust so you can create highly complex orders and strategies. You can resample the data to have different signals trigger based on different periods. https://kernc.github.io/backtesting.py/doc/examples/Multiple%20Time%20Frames.html or average out trades over time after a signal is triggered, etc.
Hopefully, this is helpful.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
a bit more on this topic from the quick start guide in the documentation.
Note, backtesting.py cannot make decisions / trades within candlesticks — any new orders are executed on the next candle's open (or the current candle's close if trade_on_close=True). If you find yourself wishing to trade within candlesticks (e.g. daytrading), you instead need to begin with more fine-grained (e.g. hourly) data.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2