Questions from Beginners MQL5 MT5 MetaTrader 5 - page 758

 
-Aleks-:

Getting errors - what's wrong? In MQL4 it works...


'{' - too many initializers TZ_Sky_and_Ground_V_04.mq5 2484 6

I should put arrFibo[18] - they say 18 elements.
 
Vladimir Karputov:

Have you seen theiMA help?

Step one: declare a variable in the "header" to store iMA indicator handle:

Step two: create indicator handle in OnInit().

And the result (crosshair on the screenshot is set at bar #1):

Question: if I loop through the indicator, should I also set double MA[1]; or should I ask/receive a bigger array? I just don't understand what all this complexity is about - what's the advantage as compared to MQL4.
 
-Aleks-:

If I try to use double MA[1] in loop, should I use double MA[1]; or it's better to request/receive the bigger array size? I just don't understand why all these complications are needed - what's the advantage as compared to MQL4.


My example with the iMAGet functionis an example designed for receiving one value at a time from an indicator. If you want to get more values from the indicator, you should useCopyBuffer with parameters "from" and "to" and saving the result in an array.


Added: there will be an example later ...


Promised example.

Input parameters:

  • get values into an array - if "true", then we use get values into an array, if "false", then we get one value at a time
  • count -> only if "get values into an array"==true - the number of bars copied into the array
  • start position -> only if "get values into an array"==true - number of the initial element (bar) to be copied into the array from

Working with the array and the Moving Avegarege indicator in the Expert Advisor:

Working with the array and Moving Avegarege indicator in the EA

Please pay attention to array arr_ma and values of elements with index #0 and with index #8.

ds

Files:
iMAGet.mq5  12 kb
 
Vladimir Karputov:


My example with the iMAGet functionis an example designed for receiving one value at a time from the indicator. If you want to get several values from the indicator, you should useCopyBuffer with parameters "from" and "to" and saving the result in an array.

Added: there will be an example later ...

Promised example.

Input parameters:

  • get values into an array - if "true" - then we use get values into an array, if "false" - then we get one value at a time
  • count -> only if "get values into an array"==true - the number of bars copied into the array
  • start position -> only if "get values into an array"==true - number of the initial element (bar) to be copied into the array from

Working with the array and the Moving Avegarege indicator in the Expert Advisor:

Please pay attention to array arr_ma and values of elements with index #0 and with index #8.

ds

Thanks for the example!

It's very important for me to understand if there is any advantage in requesting a single indicator value and copying a dozen of indicator values - maybe there was some research on that?

The fact that the time series is reversed - it's not good - I'm used to the standard numbering of bars 0123, but here I get 1230 in reverse order.

If I don't know how many bars I need during the search (for example, when we are searching for the MA and bar crossing point), then I should request the maximal possible number? Does it affect the performance in any way?

 
-Aleks-:

Thanks for the example!

It is very important for me to understand if there is an advantage in requesting a single indicator value and copying a dozen indicator values - maybe there has been some research on this?

...


Who's stopping us from doing the research ourselves :) ?

...

The fact that the time series is reversed - it's not good - I'm used to the standard numbering of bars 0123, and here we have 1230 in reverse order.

...

The only thing you need to do after getting an array (after calling iMAGetArray) is to executeArraySetAsSeries('our array',true).
...

If I don't know what number of bars I will need in the search (for example, when searching for a MA and bar crossing point), should I request the maximum possible number? Does it affect the performance in any way?


In such cases, it's better to make several queries. For example, first query - 50 elements, if necessary - second query (50 elements again) ...
 
Vladimir Karputov:

Who's stopping us from doing our own research :) ?


I'm hampered by my illiteracy in MQL5 - I can mislead everyone because of a mistake in the code, but your professionalism would inspire more confidence in such studies!

Vladimir Karputov:


All you need is to executeArraySetAsSeries('our array',true) after getting the array (after calling iMAGetArray).

I mean do it in a function at once?


Vladimir Karputov:


In such cases, it's better to make several queries. For example, the first request - 50 elements, and, if necessary, the second request (50 elements again) ...
Brr... I.e., put a loop into a loop? And why 50 and not 100? All the same researches on this theme are necessary, may be there is no sense in reception of the information more than about one bar...
 
Comments not related to this topic have been moved to "Questions from MQL4 MT4 MetaTrader 4 beginners".
 
-Aleks-:

...

I.e. do it in a function at once?

...


It's better to flip the array in:

Vladimir Karputov:

After receiving the array (after calling iMAGetArray), you will have to executeArraySetAsSeries('our array',true).

-Aleks-:

...

Brr... I.e., put a loop in the loop? Why 50 and not 100? All the same, studies on this topic are necessary, maybe there is no sense in getting information about more than one bar...

No nested loops - there will only be one loop around all values: all processing is sequential - search result in a separate function (in it, we request a certain value - for example, 50 values). If we don't find the result, we make a new request.

 

Working with indicators in MQL5 after MQL4 is terrible! It really makes me sick.

I don't understand why they can't combine everything in one function, including the handle, instead of smearing the call of the indicator all over the code!

And if an indicator settings will be changed by the function where the indicator is located, I don't understand what to do!? Do I need to initiate all variants of the indicator?


i saw an example in MQL4 - how to do it in MQL5 ?


int BarPeresek_iMAf(int PeriodMA)
  {
   int TFT=0;
   int shiftMAT=0;
   int typeMAT=0;
   int priceMAT=0;
   int BarPeresek=0;
   if(Bars(Symbol(),0)>PeriodMA)
     {
      for(int X=1;X<1000; X++)
        {
         double MAT=NormalizeDouble(iMA(Symbol(),TFT,PeriodMA,shiftMAT,typeMAT,priceMAT,X),Digits());
         if((Low(X)>MAT && High(X)>MAT) || 
            (Low(X)<MAT && High(X)<MAT))BarPeresek++;
         else {BarPeresek++; break;}
        }

     }
   return BarPeresek;
  }
Торговые советники и собственные индикаторы - Алгоритмический трейдинг, торговые роботы - Справка по MetaTrader 5
Торговые советники и собственные индикаторы - Алгоритмический трейдинг, торговые роботы - Справка по MetaTrader 5
  • www.metatrader5.com
Среди программ для автоматического трейдинга можно выделить две большие категории: торговые роботы и индикаторы. Первые предназначены для...
 

Can you tell me how to remove the markers after closing a position so that they are not displayed?

Is it possible to remove them programmatically?

Thank you!