How to get MACD of 1 minute and 5 minute

hey guys,
It seems that there're no
period
parameter forbt.indicators.MACD
andbt.indicators.MACDHisto
likebt.indicators.SMA
, question is clear:How should I do if I need to get MACD of 1minute and 5minute for a strategy from one date feed(ccxt live).
Any suggestions?

@mrm0nst3r said in How to get MACD of 1 minute and 5 minute:
It seems that there're no period parameter for bt.indicators.MACD and bt.indicators.MACDHisto
They actually have 3 period parameters.

Hi @backtrader ,
I noticed the three parameters:
1  period_me1 (12) 2  period_me2 (26) 3  period_signal (9) 4  movav (ExponentialMovingAverage)
But the first three params are the standard MACD calculation params, the 4th param is
MovAv.Exponential
.the problem is how to get MACD of 5 minutes period and 15 minutes. Using other indicators like SMA we could script like this:
// data feed's timeframe is `Minutes` self.sma = bt.indicators.SMA(data, period=5) // To get 5 minutes SMA self.sma2 = bt.indicators.SMA(data, period=15) // to get 15 minutes SMA
But how to achieve this using MACD?
self.macd = bt.indicators.MACD(data, ??=5)
?It seems the only way is to resample data to 5 minutes timeframe then use
self.macd = bt.indicators.MACD(data)
to get 5 minutes MACD.Am I understanding it right?

@mrm0nst3r said in How to get MACD of 1 minute and 5 minute:
Am I understanding it right?
No. The
MACD
needs 3 period parameters and that determines the calculations. You should probably understand what theMACD
is.@mrm0nst3r said in How to get MACD of 1 minute and 5 minute:
self.sma = bt.indicators.SMA(data, period=5) // To get 5 minutes SMA
This is not the same as this ...
@mrm0nst3r said in How to get MACD of 1 minute and 5 minute:
It seems the only way is to resample data to 5 minutes timeframe then use self.macd = bt.indicators.MACD(data) to get 5 minutes MACD
The
SMA
with period5
is NOT giving you the simple moving average of a resampled data.Your problem is that you are mixing
timeframe
andperiod
. Thetimeframe
applies to the data feeds. Theperiod
is what the indicators use as lookback value to understand how many bars of a giventimeframe
have to be used. 
@backtrader said in How to get MACD of 1 minute and 5 minute:
The period is what the indicators use as loo
Hi @backtrader ,
Thank you for your answer.
First of all, this is my understanding of timeframe and period:
timeframe
is an attribute of the data feed;period
is the "bar".
If the data's timeframe is 1 minute, then 1 period is 1 minute's data (OCHLV); if data's timeframe is 5 minutes, then 1 bar is 5 minutes' data.I usebt.timeframe.Minutes
all the time, so whybt.indicators.SMA(data, period=5)
is not giving me the 5 minutes SMA value? I directly use the data, not a resampled one.
I guess to get SMA of 5 minutes, I have to use 5 minutes timeframe data, seems clearer to me now. Thank you.And I used the Minutes data to resample to a 5 minutes timeframe using
cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=5)
. Am I doing it right?And you're right, I'm confused when it comes to MACD.
MACD=12Period EMA − 26Period EMA
So, if the data's timeframe is 5 minutes, we'll get EMA(12) and EMA(26) of 5 minutes' timeframe, after calculation, it's the 5m MACD value, is that right?
From the MACD equation, I see only
period
calculations, whether thisperiod
stands for 1 minute or 5 minutes, it's decided by the data's timeframe, which lead me to the conclusion thatto get macd of 5m, the only way is to resample original 1m timeframe data to 5m timeframe data using compression=5
. is that right?I'm stuck here, and forgive me if my expression confuses you.
Thank you very much for your time.