Averages are the most common tools in technical analysis. They are usually calculated over a sliding window of data, which gave them the name moving average. This post is about a different type of a moving average chart; the average of a season. Usually averages are calculated in a rolling manner, e.g. over the last 200 days. But you could also calculate an average over a given start-end time span.
Have a look at the chart and you will understand what I mean:
The chart shows an example of a monthly average on an hourly chart. On the beginning of the month the moving average chart equals the first closing price of the market, later on it will always show the average price of the current month. The indicator can also display the daily, weekly and yearly average, running on intraday or end of day data.
The Moving Average Chart Indicator Code
The programming of this indicator is quite straightforward.
- In line 2 it is defined that the indicator will be displayed on the chart, and not in an seperate subchart.
- Line 3 will give you a dropdown menu to select over which period the average will be calculated.
- Line 6 to 9 finally start the calculation whenever a new period of start. Thereafter the used variables are reset.
- Line 15 and 16 is executed on every bar and sums up the number of bars (count) and calculates the sum of closing prices (summ).
- Line 18 finally calculates the indicator and displays it on the chart.
Tradesignal® is a registered trademark of Tradesignal GmbH. Unauthorized use or misuse is strictly prohibited. Data by Thomson Reuters Eikon.