Moving averages and periods
Looking for general clarification regarding moving averages and data resolution in Backtrader (and other platforms)
Lets say that I'm testing a strategy with 1-minute data resolution
I use the SMA to get a 4-hour MA and a 10-hour MA.
My assumption is that I need to specify periods of (460) and (1060) respectively.
I'm also assuming that the results will be relatively close to using periods of (412) and (1012) in 5-minute data resolution, and just 4 and 10 in file that has hourly candles.
Also assuming that if I resample the data to, say, 30 minutes, I'll need to change my periods to add up to 4 hrs and 10 hrs.
Are those assumptions correct?
Am I missing something?
(If this question does not belong here please let me know)
run-out last edited by
@run-out Thank you Neil, I mostly read through the entire docs, and seen this page. It explains how to mix data with various timeframes and very useful to know.
My question is more general regarding data resolution and indicators.
I will try to boil it down into a single yes/no.
I have one data source only at this point: A 1-minute candle data from Binance.
I would like the MAs to behave as if they run on hourly candles. So that when my fast is 4 and the slow is 18, then it acts the same as 4hr over 18hr EMA cross.
Do I have to resample the data from 1 min to 1 hour first
Can I get away with just using periods that are x60 (period of 240 in minutes to represent 4 hours, etc.), to account for the fact that I use the minute data?
I hope I clarified :)
run-out last edited by
@hanaan You are going to have different results with your two proposed solutions. It's a good question.
Let's use 1 minute to 1 hour, and 4 and 18 bars as per your example.
When you use resampling, what effectively happens is, at the top of the hour (unless modified by user), the previous 60 one minute bars are converted into OHLCV for that 60 minute period. This then is carried forward unchanged for each of the next 60 one minute periods, repeating itself until you complete another 60 minutes. The process reapeats. If you now calculate 4 and 18 period SMAs, you will be calculating on the completed one hour bars, and they will not vary during each 60 minute period, only changing at the hour mark.
However, if you were to calculate your moving average using 60 x 4 and 60 x 18 respectively, then your bars will change each minute since the moving average is calculating 240 and 1080 minute bars respectively, minute to minute.
Hope this helps.
@run-out Okay, thank you! That was my thought, and although different, I'm assuming that the averages will be a slightly different perspectives of the same data, neither right or wrong, just different.
The large-span minute-based version probably slower but more accurate.