Excuse me, what's the variable "position"?
double SimpleMA(const int position,const int period,const double &price[])
double SimpleMA( const int position, const int period, const double &price[]) { double result= 0.0 ; //--- check period if (period> 0 && period<=(position+ 1 )) { for ( int i= 0 ; i<period; i++) result+=price[position-i]; result/=period; } return (result); }
Good morning
Is it clearer like this?
No, I already saw it thinking that position was the first bar to calculate as example 20 if I want 20 period but I'm not sure.
price has [position - 1] (and not +1) because mql5 doesn't set as series by default?
Gerard Willia G J B M Dinh Sy #:
The as_series is according to...
It will depend on what you are looking at.
But to make an SMA, we don't care.
It doesn't come into play, unlike the average exhibition where meaning is important.
Ok, therefore if I want SMA with 5 periods which position I have to write?
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
MovingAverages:
The MovingAverages library is a part of Standard package of MetaTrader 5 client terminal.
The library contains functions for calculation of different types of moving averages. Totally, there are 8 functions that can be divided into 2 groups of functions of the same type, each containing 4 of them.
The first group contains functions that receive an array and simply return a value of a moving average at a specified position:
These functions are intended for obtaining the value of an average once for an array, and are not optimized for multiple calls. If you need to use a function from this group in a loop (to calculate values of an average and further write each calculated value into an array), you'll have to organize an optimal algorithm.
The second group of functions is intended for filling out the recipient array by values of a moving average based on the array of initial values:
Author: MetaQuotes Software Corp.