Dear Mr Umarov!
Professional developers please understand that most traders are not professional coders and find it very hard to get things done.
With MQL5 it's even harder.
The trader who wants to learn to work with MT5 needs articles like this to understand how to do it.
Please write more articel like this. Thank's a lot for htis one.
regards
walb
Very good! Thank you !
Teach our newbies step by step.
I have a question,
is it necessary or more proper to add the below code ?
ArraySetAsSeries(price,true);
for(int i=1;i<rates_total;i++)
{
MTMBuffer[i]=price[i]-price[i-1];
AbsMTMBuffer[i]=fabs(MTMBuffer[i]);
}
Why use [i-1] to calculate [i] and start i=1 ? no [0] ?
MTMBuffer[i]=price[i]-price[i-1];
I am with @okwh. I am still baffled why the loop starts with 1?
I've read the article that was pointed by @Rashid Umarov. It did say this :
The default indexing of all arrays and indicator buffers is left to right. The index of the first element is always equal to zero. Thus, the very first element of an array or indicator buffer with index 0 is by default on the extreme left position, while the last element is on the extreme right position.
I am with @okwh. I am still baffled why the loop starts with 1?
I've read the article that was pointed by @Rashid Umarov. It did say this :
The default indexing of all arrays and indicator buffers is left to right. The index of the first element is always equal to zero. Thus, the very first element of an array or indicator buffer with index 0 is by default on the extreme left position, while the last element is on the extreme right position.
Because in this particular example, the indicator needs to calculate the Close[1]-Close[0]. Then, if the start is equal 0, that would cause the indicator to calculate a negative index: Close[0] - Close[-1]. That's why the start must be 1. So the indicator will calculate: Close[1] - Close[0]. Somenthing like: Close[start] - Close[start-1] written on the code.
for(int i=1;i<rates_total;i++)
{
MTMBuffer[i]=price[i]-price[i-1];
AbsMTMBuffer[i]=fabs(MTMBuffer[i]);
}
Why use [i-1] to calculate [i] and start i=1 ? no [0] ?
MTMBuffer[i]=price[i]-price[i-1];

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article MQL5: Create Your Own Indicator is published:
By describing creation of True Strength Index, the author shows how to write indicators in MQL5.
Author: MetaQuotes