2019-10-02: The community is currently in read-only mode
Strategy using day and minute data
Humbleguy last edited by
I am trying to see how I can perform the following:
Let's assume; I want to use SMA(10/SMA(50) indicator to enter and exit positions. Now I want to perform automated trading of this strategy with live data. There are two ways, I can run this in live trading:
1 - Run the strategy everyday once at 3:59PM ET, and perform the trade.
2 - Run the strategy every minute throughout the day. At each minute calculate the SMA(N) using close price of previous N-1 days and the latest price at the moment for this day.
The 2nd strategy allows the algorithm to react to potential major swings throughput the day. Can the second strategy be implemented in backtrader, how?
Thank you very much.
You want to use replay. The strategy doesn't actually run every minute but runs with every tick of the data, slowly recreating the day. The indicators attached to the replayed data are re-calculated automatically for the current day with each new tick (there is no need to recalculate the previous days)
The length (
len(data_in_use)) determines if the replaying has moved to a new day.