kieran-mackle / AutoTrader

A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
https://kieran-mackle.github.io/AutoTrader/
GNU General Public License v3.0
945 stars 217 forks source link

Time misalignment detected #18

Closed elijahho closed 2 years ago

elijahho commented 2 years ago

Describe the bug I encountered a Time misalignment detected on live trading mode. It seemed to be causing trades to be wrongly opened.

To Reproduce Steps to reproduce the behavior: I'm not too sure how to reproduce but I've upgraded my autotrader version to the latest. Waiting to see if this happens again.

Expected behavior I'm not too sure if this warning/error caused the trades to be wrongly opened.

Screenshots Screenshot 2021-12-28 at 1 33 05 PM

Version of AutoTrader being used Using version 0.5.11

Additional context N/A

kieran-mackle commented 2 years ago

This message occurs when the time index of latest downloaded price data does not align with the current time. In the screenshot above, the latest candle was aligned with the hour (0), but the current time was expecting a candle aligned with 30 minutes past the hour (30) - hence the (0/30). Sometimes, waiting a few seconds before re-downloading the data will fix this issue on its own.

If you want to avoid this function completely, set check_data_alignment = False in the configuration. This will avoid the checking, but then you risk running your strategy on a candle up to 30 minutes old. If using this, I recommend you also set allow_dancing_bears = True so that even incomplete candles will be downloaded and passed to the strategy module. This way, you will always have the latest price data. Just make sure that you only run AutoTrader every 30 minutes (for a M30 strategy) to prevent multiple orders on the same candle. See the configuration docs for more about these options.

What was the issue you observed with how the orders were opened?

kieran-mackle commented 2 years ago

Closing this as the time misalignment messages have been deprecated from v0.6.0 - duplicated bar checking methods have been added to autobot.py to achieve similar functionality.