Discussion of article "MQL5: Create Your Own Indicator"

 

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.

The second version of True Strength Index indicator looks better

Author: MetaQuotes

 

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.

 
Thank your very much for this useful article. As a beginner using the MT5 platform, and as @Wolfgang pointed out, those of us who are not professional coders really depend on these types of articles to get familiarized with the inner workings of the language.
 
Great article!! I simply loved all the details and learned a lot from it! Thank you. Great job.
 
dhermanus #:

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.

 
okwh #:

   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];

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.
 
Does this exist in German? 
Searching for "Wie man einen eigenen Indikator erstellt" yielded a lot of results, however not from 2010.
Reason: