# MACD indicators calculator

I would like to calculate MACD (moving average convergence/divergence) based on 12 period Fast MA, a 26 period Slow MA and a 9 period Signal for 5 minutes bars.

Should I provide only the last 12 bars i.e each bar will have 5 minutes chart or do I need to provide the last 12 days of 5 minutes bars to calculate Fast MA?

If you are using a 5 minute bar chart then you will need 12 five minute periods to calculate your first MA12 number. Initially it will be a simple moving average and thereafter it will be an EMA. You will need 26 five minute periods to calculate your first MA26 number.

I won't bore you with the lag problems of such an indicator and the false signals that it can generate :->)

• Thank you Bob for your response, So for day trading no need historical data, we can get current day 5mins bars and calculate MACD. But we will not have current real time bar that means bars available at 9:30, 9:35, 9:40 etc but chart still updates at 9:41, 9:42 etc eve though it does not have 9:45 bar yet. So how to calculate real time chart in between time frames.? Any reference for MACD and bollinger bands setup for day trading to avoid false signals as you mentioned. – Ramesh Feb 8 at 11:47
• @Ramesh - You need 12 periods to determine a 12 period SMA. If you only have 12 periods of data then that's just a single data point SMA of the last 12 periods which is just an excerpt from the historical data and may be far from the actual long term value. After 12 periods, using EMA calculations, the EMA will eventually catch up to the long term EMA which is why you need historical data for it to be accurate. If you want to see in between time frames (by the minute) then you either need software that calculates a rolling 5 minute bar or you need to look at by the minute tick data. – Bob Baerker Feb 8 at 12:59
• @Ramesh - The MACD is the difference b/t a long term EMA and a short term EMA. Mathematically, it's possible for difference to converge without the underlying moving in the direction the indicator change of direction suggests. IOW, an indicator reversal and turn up below zero may or may not be a valid signal but mathematically, above zero it must be (and conversely for sell signals). Suppose after a long drop, the underlying flattened out for a number of bars. Both EMAs would head toward current price (converge) and if MACD below zero, you could get a meaningless signal or even a whipsaw. – Bob Baerker Feb 8 at 13:01