Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1151

 
Maksym Mudrakov:

The error could be in the number of digits after the decimal point:


This is not the error, the data is not calculated on the history, but from the moment the symbol is created everything is calculated correctly, I suspect the history calculation function is not working correctly, i.e. it is a bug.
 
Good afternoon, gentlemen.

I have such a problem: I've just started in MT5, I'm transferring my indicators from MT4 and I've encountered some problems. I need to use iMA in one line and get the value of one specific index. I've seen messages on forum and use iMAGet function (as well as similar iATRGet etc.). As I see, the functions no longer work, then this question: how to gracefully get one single iMA value? I've tried using the above functions to do this:

NormalizeDouble(iMAGet(iMA(Symbol(), timeframe, signal_period, 0, MODE_LWMA, PRICE_LOW), shift), Digits())

I know it's bad without checking, but I have to port old MT4 code, I couldn't think of any other way to make it simpler (I have dozens of wizards, and they all work on different timeframes). I can't initialize the wizards in oninit, because the code has three steps nesting and I can't call the needed wizard without troubles. So, in short, my goal is to turn

This :

NormalizeDouble(iMA(Symbol(), timeframe, signal_period, 0, MODE_LWMA, PRICE_LOW, shift), Digits())

Into something that works on MT5 without any drastic gestures.

 
Olga Miakhovich:
Good afternoon, gentlemen.

I have a problem, I have just started MT5 and I have problems with it when I transfer my indicators from MT4. I need to use iMA in one line and get the value of one specific index. I've seen messages on forum and use iMAGet function (as well as similar iATRGet etc.). As I see, the functions no longer work, then this question: how to gracefully get one single iMA value? I've tried using the above functions to do this:


I know it's bad without checking, but I have to port old MT4 code, I couldn't think of any other way to make it simpler (I have dozens of wizards, and they all work on different timeframes). I can't initialize the wizards in oninit, because the code has three steps nesting and I can't call the needed wizard without troubles. So, in short, my goal is to turn

This :

Into something that works on MT5 without any drastic gestures.

Check out the examples in kodobase, such as this one:https://www.mql5.com/ru/code/27161

Basically: create an indicator handle in OnInit()

handle_iMA_High=iMA(Symbol(),Period(),Inp_MA_ma_period,Inp_MA_ma_shift,
                       Inp_MA_ma_method,PRICE_HIGH);
//--- if the handle is not created
   if(handle_iMA_High==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code
      PrintFormat("Failed to create handle of the iMA indicator (\"Price High\") for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early
      return(INIT_FAILED);
     }

Then you copy the necessary element(s) to the clipboard and work with it

if(CopyBuffer(ind_handle,0,-shift,amount,values)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("Failed to copy data from the iMA indicator, error code %d",GetLastError());

https://www.mql5.com/ru/docs/series/copybuffer

 
Vitaly Muzichenko:

Look up examples in the kodobase, e.g. this one:https://www.mql5.com/ru/code/27161

Basically: Create indicator handle in OnInit()

Then you copy the necessary element(s) to the buffer and work with it

https://www.mql5.com/ru/docs/series/copybuffer

As I have already written, initialization in OnInit is not suitable for me. I have work with all timeframes simultaneously, I have to initialize all masks in each TF, and then in code, where I use some value, do something like this:

if(timeframe = PERIOD_M5)
        CopyBuffer(handle_ma_m5, ...)
if(timeframe = PERIOD_M15)
        CopyBuffer(handle_ma_m15, ...)
...

And so with every call of each wristband. The code will just turn into a confusing diarrhea.

And every new bar will need to update it somehow?

Is there a function like CopyBuffer, but copying not an array, but one value by required index?

 
Olga Miakhovich:

As I have already written, initialization in OnInit is not suitable for me. I have work with all timeframes simultaneously, I have to initialize all masks in each TF, and then in code, where I use some value, do something like this:

And so with every call of each wristband. The code will just turn into a tangled diarrhea.

And every new bar will need some way to update it?

Is there a function like CopyBuffer, but copying not an array, but a single value by the right index?

Make an array of handles inOnInit() and work with them.

CopyBuffer(...) into function for usability, feed it with indicator handle and required index from array, and function will return the price

 
Vitaly Muzichenko:

Make an array of handles inOnInit() and work with them.

CopyBuffer(...) into a function for ease of use, pass the indicator handle and the required index from the array, and the function will return the price

very inconvenient, though)

 
Olga Miakhovich:

(it's awkward, though))

More like uncomfortable ))))

 
Vitaly Muzichenko:

Make an array of handles inOnInit() and work with them.

CopyBuffer(...) into function for usability, there you feed the indicator handle and the required index from the array, and the function will return the price

The other problem of CopyBuffer is that it necessarily requires the indicator buffer for itself. I have a hundred indicators in total and they are used in calculations to get one single indicator. Do I need to create a hundred buffers to store these values?

 
Olga Miakhovich:

Another problem with CopyBuffer is that it necessarily requires an indicator buffer for itself. I have under a hundred indicators in total and they are used in calculations to get one single indicator. Do I need to create a hundred buffers to store these values?

Look for code examples in scriptor's CodeBase - everything is there.
Actually, you can calculate the MA for any bar.
 
I need an example to solve the following problem: there is an indicator ¹1 in the chart with a dozen graphical buffers (not wavecaps and other stuff) and the basement indicator ¹2 should take some buffers from the indicator ¹1 and display them as hixograms (no matter how) already in the basement. Thank you in advance, for MT5.
Reason: