Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1019

 
Сергей Таболин:

The first pathway helped )))) Thanks.

One more question: I tear off 3 indicator instances in the indicator to get data from different TFs. But when I attach it to a chart, I get this kind of spreadsheet:

What would it mean?

I can't say for sure, but maybe the 2nd buffer was initialized late.

To find out exactly what is the reason, you should adjust the following lines like this

if(CopyBuffer(handle_MA,0,0,ma_values_to_copy,buffer_MA) < 0 ) // копируем данные из индикаторного массива в массив buffer_MA
   {                                                                                // если не скопировалось
      Print("Не удалось скопировать данные из индикаторного буфера в buffer_MA, код ошибки "+ IntegerToString(GetLastError()));   // то выводим сообщение об ошибке
      return(0);                                                                    // и выходим из функции
   }

After that we can say more confidently what is wrong

 
Oleg Peiko:

I can't say for sure, but maybe the 2nd buffer was initialized late.

In order to find out exactly what is the reason, you should adjust the following lines like this

After that we can say with more confidence what's wrong.

2019.03.23 22:58:11.410 my_HMA5_123 (GBPUSD,M30)        Скопирован индикаторный буфер в buffer_MA
2019.03.23 22:58:11.410 my_HMA5_123 (GBPUSD,M30)        Не удалось скопировать данные из индикаторного буфера в buffer_MA2
2019.03.23 22:58:11.410 my_HMA5_123 (GBPUSD,M30)        4806
2019.03.23 22:58:11.637 my_HMA5_123.ex5::my_HMA5 (GBPUSD,M15)   BarsCalculated() вернул -1, код ошибки 4806
2019.03.23 22:58:11.648 my_HMA5_123 (GBPUSD,M30)        Скопирован индикаторный буфер в buffer_MA
2019.03.23 22:58:11.648 my_HMA5_123 (GBPUSD,M30)        Скопирован индикаторный буфер в buffer_MA2
2019.03.23 22:58:11.648 my_HMA5_123 (GBPUSD,M30)        Скопирован индикаторный буфер в buffer_MA3
ERR_INDICATOR_DATA_NOT_FOUND    4806    Запрошенные данные не найдены

Can something be done with it?

By the way, this copy opens on M15.

However, the same thing is at other TFs too...

 
Сергей Таболин:

Is there anything you can do about it?

By the way, this copy opens on M15.

It's the same on other timeframes as well...

In the timer, once every two minutes, ask for any data for the required timeframe. This way you will always have up-to-date data for the timeframe.

In addition: in OnCalculate() at the very beginning of it, you request it, for example:

   if(iTime(NULL,PERIOD_M15,1)==0)
      return 0;

Thus, until the data of the fifteen-minute timeframe is available, the indicator will wait for the next tick.
You can request the right amount of data for the calculation by using the CopyXXX function:

   datetime array[];
   if(CopyTime(NULL,PERIOD_M15,0,number_of_datas,array)!=number_of_datas)
      return 0;

In this case, until the required number_of_datas data is available, the indicator will wait for the next tick.

If you decide to use the function

Bars(NULL,PERIOD_M15);

..., you should take into account, that the amount of data for the calculation should not exceed the rates_total, otherwise it will exceed the limits of the array. In other words, if there are less bars on the current timeframe than on M15, then we should take the number of bars equal to their number on the current timeframe = rates_total

 
Artyom Trishkin:

In the timer, once every two minutes, request any data for the required timeframe. This way you will always have up-to-date data for the timeframe.

In addition: in OnCalculate() at the very beginning of it you request, for example:

So, until the 15 min timeframe data is available the indicator will wait for the next tick.
You can request the right amount of data for the calculation with the CopyXXX function:

In this case, until the required amount of data in number_of_datas is available, the indicator will wait for the next tick.

If you decide to use the function

..., you should take into account, that the amount of data for the calculation should not exceed the rates_total, otherwise it will exceed the limits of the array. In other words, if there are less bars on the current timeframe than on M15, then we should take the number of bars equal to their number on the current timeframe = rates_total

Thanks.

Did it like this:

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   
   if(iTime(NULL,PERIOD_CURRENT,1)==0)  return(0); 
   if(iTime(NULL,periodTF1,1)==0)       return(0); 
   if(iTime(NULL,periodTF2,1)==0)       return(0); 
   
   int ma_values_to_copy; 
   int ma_calculated = 0;
   if(PeriodSeconds(PERIOD_CURRENT) < PeriodSeconds(periodTF1) && PeriodSeconds(PERIOD_CURRENT) < PeriodSeconds(periodTF2))   ma_calculated = BarsCalculated(handle_MA);
   else
   if(PeriodSeconds(periodTF1) < PeriodSeconds(PERIOD_CURRENT) && PeriodSeconds(periodTF1) < PeriodSeconds(periodTF2))        ma_calculated = BarsCalculated(handle_MA2);
   else
   if(PeriodSeconds(periodTF2) < PeriodSeconds(PERIOD_CURRENT) && PeriodSeconds(periodTF2) < PeriodSeconds(periodTF1))        ma_calculated = BarsCalculated(handle_MA3);
   
   if(ma_calculated <= 0){ 
      PrintFormat("BarsCalculated() вернул %d, код ошибки %d",ma_calculated,GetLastError()); 
      return(0); 
     }  
   if(prev_calculated == 0 || ma_calculated != ma_bars_calculated || rates_total > prev_calculated + 1){ 
      if(ma_calculated > rates_total) ma_values_to_copy = rates_total; 
      else ma_values_to_copy = ma_calculated; 
     } else { 
      ma_values_to_copy = (rates_total - prev_calculated) + 1; 
     } 

result:

2019.03.24 00:56:38.056 my_HMA5_125 (GBPUSD,M30)        BarsCalculated() вернул -1, код ошибки 4806
2019.03.24 00:56:38.226 my_HMA5_125 (GBPUSD,M30)        Скопирован индикаторный буфер в buffer_MA
2019.03.24 00:56:38.226 my_HMA5_125 (GBPUSD,M30)        Скопирован индикаторный буфер в buffer_MA_c
2019.03.24 00:56:38.226 my_HMA5_125 (GBPUSD,M30)        Скопирован индикаторный буфер в buffer_MA2
2019.03.24 00:56:38.226 my_HMA5_125 (GBPUSD,M30)        Скопирован индикаторный буфер в buffer_MA_c2
2019.03.24 00:56:38.226 my_HMA5_125 (GBPUSD,M30)        Скопирован индикаторный буфер в buffer_MA3
2019.03.24 00:56:38.226 my_HMA5_125 (GBPUSD,M30)        Скопирован индикаторный буфер в buffer_MA_c3

I'm having a hard time with indicators ))))

 

Hi all!
Please advise on function CopyHigh.
I've read in the definition of this function, "Gets history data to an array with maximal bar price for a specified symbol and period".

Are we talking about a Bid or Ask price array ? Or is there some way to set the type of price needed?

 
renatmt5:

Hi there!
Please advise on the function CopyHigh.
I've read in the definition of this function, "Gets history data to an array of maximum bar prices for a specified symbol and period".

Are we talking about a Bid or Ask price array ? Or is it possible to set the type of price needed somehow?

Reference:Features of Plotting

Features of making charts

The history data, on the basis of which the charts are built, is stored on the hard disk. When you open a chart, the data is downloaded from the disk and the last missing data from the trading server is downloaded. If the historical data on a financial instrument is not available on the hard disk, the last 512 bars of the history are downloaded.

To download the earlier data, move the chart to the required area. Once the chart is opened, the platform will start receiving information about the current quotes. Thus, the further price movement is formed in real time. This information is automatically saved in a history file and is used when opening this chart again in the future.

  • The "Max bars on chart" parameter is set inthe platformsettings. This parameter allows controlling the amount of historical data shown on the chart.
  • The charts are plotted against Bid prices. If theDepth of Market is available for the symbol, the charts will be plotted at Last prices (the price of the last trade executed).
Просмотр и настройка графиков - Графики котировок, технический и фундаментальный анализ - MetaTrader 5
Просмотр и настройка графиков - Графики котировок, технический и фундаментальный анализ - MetaTrader 5
  • www.metatrader5.com
Графики в торговой платформе отображают изменение котировок финансовых инструментов во времени. Они необходимы для проведения технического анализа и работы советников. Они позволяют трейдерам наглядно следить за котировками валют и акций в режиме реального времени и моментально реагировать на любое изменение ситуации на финансовых рынках...
 
Vladimir Karputov:

Reference:Features of graphing

Features of making charts

Historical data, on the basis of which charts are built, is stored on hard disk. When you open a chart, the data is downloaded from the disk and the last missing data from the trading server is downloaded. If the historical data on a financial instrument is not available on the hard disk, the last 512 bars of history are downloaded.

To download the earlier data, move the chart to the required area. Once the chart is opened, the platform will start receiving information about the current quotes. Thus, the further price movement is formed in real time. This information is automatically saved in a history file and is used when opening this chart again in the future.

  • The "Max bars on chart" parameter is set inthe platformsettings. This parameter allows controlling the amount of historical data shown on the chart.
  • The charts are plotted against Bid prices. If theDepth of Market is available for the symbol, the charts will be plotted at Last prices (last trade price).

Good day Vladimir, as always you help me out :) Thank you!

 
Good day to all. Please advise how to calculate the volume of the position based on the funds allocated to the transaction.
 

How to find the smallest candle of N in mql5?

In mql4

   min=99999;
   N=5;
   for(int i=1;i<=N;i++)
     {
      if(High[i]-Low[i]<min) min=High[i]-Low[i];
     }
 
yiduwi:

How to find the minimum candle of N in mql5?

In mql4

In Expert Advisor or in an indicator? For the current timeframe or for another one?