<p>The normal approach is as you suggest, to update the average regularly - that's pretty much the definition of a moving average. For example <a href="http://en.wikipedia.org/wiki/Bollinger_Bands" rel="nofollow">Bollinger Bands</a> are a similar metric and use a moving average which is continually updated. A true moving average would be updated with every trade made but it makes sense to break it down into periods of 30 seconds or a minute.</p>

CC BY-SA 3.0
2014-01-01T23:01:11.247Z
Thanks, that's informative. How I wrote it to work, is it fetches a new price every 60 seconds. If it is trying to calculate a 5 minute period EMA, it will create a calculation with a "period index", starting from 0 and counting up until it reaches 4. The EMA calculator will always use the data from the same period index, but it can be calculated every 60 seconds once there is enough historical data.
Andy Bas
CC BY-SA 3.0
2013-12-30T02:15:47.407Z
2013-12-30T02:15:47.407Z
Jamie Bull
<p>For any Moving average calculation you have to start with tick by tick calculation, then 1 minute ,then 5 minutes,30 minutes, 1 hr, 4 hrs ,daily, weekly and monthly.</p>

CC BY-SA 3.0
2014-01-01T19:26:04.337Z
2014-01-01T19:26:04.337Z
BTCXINDIA
<p>I'm writing a bot that acts on market signals - currently just based on exponential moving averages. At the moment, I have the program watching the market on multiple different period lengths. For example, it will grab the last price right now, calculate and log a moving average if there is enough data, and then 60 minutes from now do the same. It can be doing this for 5min, 15min, 30min, 2h, 4h, etc. etc. time periods. </p>

<p>However, If I have an algorithm making decisions every 60 minutes, It could very easily lose a lot of money in between the two calculations. My thought is that I should be grabbing market data and calculating values every 1 or 2 minutes, and base those calculations on data from <code>period_length</code> time ago. It still obviously charts a 60 min or 2h or w/e chart, but does so every 1 min in order to react as fast as possibly to changes.</p>

<p>Is this the correct approach, or am I way off on this?</p>

<trading><bots>
Calculating EMA on multiple time periods - right or wrong?
Andy Bas
# Calculating EMA on multiple time periods - right or wrong?

(Asked by: username_0 on 2013-12-26)

I'm writing a bot that acts on market signals - currently just based on exponential moving averages. At the moment, I have the program watching the market on multiple different period lengths. For example, it will grab the last price right now, calculate and log a moving average if there is enough data, and then 60 minutes from now do the same. It can be doing this for 5min, 15min, 30min, 2h, 4h, etc. etc. time periods.

However, If I have an algorithm making decisions every 60 minutes, It could very easily lose a lot of money in between the two calculations. My thought is that I should be grabbing market data and calculating values every 1 or 2 minutes, and base those calculations on data from `period_length` time ago. It still obviously charts a 60 min or 2h or w/e chart, but does so every 1 min in order to react as fast as possibly to changes.

Is this the correct approach, or am I way off on this?

**Tags:** trading, bots


---

## 2 answers

### Answer by username_1 on 2013-12-30. Score: 1

The normal approach is as you suggest, to update the average regularly - that's pretty much the definition of a moving average. For example [Bollinger Bands](http://en.wikipedia.org/wiki/Bollinger_Bands) are a similar metric and use a moving average which is continually updated. A true moving average would be updated with every trade made but it makes sense to break it down into periods of 30 seconds or a minute.

> **Comments:**
> **username_0**: Thanks, that's informative. How I wrote it to work, is it fetches a new price every 60 seconds. If it is trying to calculate a 5 minute period EMA, it will create a calculation with a "period index", starting from 0 and counting up until it reaches 4. The EMA calculator will always use the data from the same period index, but it can be calculated every 60 seconds once there is enough historical data.  

---

### Answer by username_2 on 2014-01-01. Score: 0

For any Moving average calculation you have to start with tick by tick calculation, then 1 minute ,then 5 minutes,30 minutes, 1 hr, 4 hrs ,daily, weekly and monthly.


---

