Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 580

 
Hello! Please help me with a problem. I need to get data from one EA for different symbols/TF. The manual says:"The mechanism of access to the server for data does not depend on how a request was initiated - by a user when navigating a chart or by the program in MQL4". However, in practice, if in real time, for example, if we track the number of bars on a symbol/TF different than the symbol on which the EA is running, the following happens The new symbol loads a small number of bars on the first access (around 1000 for M1) and this number does not change. I have tried different functions to access timeseries, I have tried to specify displacement of bars and time deeper in the history than it is loaded at the moment, I have tried to move the ChartNavigate(_ID, CHART_BEGIN) - new data are not loaded and the number of bars does not change. However, if I open a window programmatically from the same Expert Advisor (I have already opened it for the ChartNavigate() function) and move the chart leftwards using arrow/Home/PgUp button, it leads to the increase of timeseries arrays, the number of bars is increased in real time, i.e. the data is loaded. What needs to be done to load the history programmatically without pressing physical keys on the keyboard? Thanks)
 
Ihor Herasko:

Do it that way. The code is almost correct. There's only one word missing:

Thank you!
 
Alexandr Mordashov:
Hello! Help me solve the problem. I need to get data from one EA for different symbols/TF. The Help says:"The mechanism of access to the server for data does not depend on how the request was initiated - by a user when navigating a chart or by a program in MQL4". However, in practice, if in real time, for example, if we track the number of bars on a symbol/TF different than the symbol on which the EA is running, the following happens The new symbol loads a small number of bars on the first access (around 1000 for M1) and this number does not change. I have tried different functions to access timeseries, I have tried to specify displacement of bars and time deeper in the history than it is loaded at the moment, I have tried to move the ChartNavigate(_ID, CHART_BEGIN) - new data are not loaded and the number of bars does not change. However, if I open a window programmatically from the same Expert Advisor (I have opened it before for the ChartNavigate() function) and move the chart to the left using arrow/Home/PgUp button, it leads to the increase of timeseries arrays, the number of bars is increased in real time, i.e. the data is loaded. What needs to be done to load the history programmatically without pressing physical keys on the keyboard? Thanks)

You have to be more explicit about the question. If the problem is not posed, it cannot be solved.

 
Galim_V:
Can you tell me how to get the bottom indicators from a timeframe other than the one on which the owl is hovering?
double iRev()
{
 static int wtf;
 static int tf;  
 int xtf =Period();       // таймфрейм текущего графика 
 
                          //PERIOD_CURRENT;
 if(xtf != PERIOD_CURRENT)
 {
 Print("xtf  ",xtf);
   switch(xtf)
   {
    case 1: tf = PERIOD_H1;
    break;
    case 5: tf = PERIOD_H4; wtf = PERIOD_H1;
    break;
    case 15: tf = PERIOD_D1;
    break;
   }
     
 }
Print("tf == ",tf,"wtf ==",wtf);
 double  iRa =  NormalizeDouble(iCustom(NULL,tf,"iRevers",InpSARStep,InpSARMaximum,0),Digits);
 double  wRa =  NormalizeDouble(iCustom(NULL,wtf,"iRevers",InpSARStep,InpSARMaximum,0),Digits);
   if(iRa != 0) ObjectCreate("Ra",OBJ_HLINE,0,Time[0],iRa,0,0);
     
     ObjectSet("Ra",OBJPROP_TIME1,Time[0]);
     ObjectSet("Ra",OBJPROP_PRICE1,iRa);
   
   if(wRa != 0) ObjectCreate("weRa",OBJ_HLINE,0,Time[0],wRa,0,0); 
     ObjectSet("weRa",OBJPROP_TIME1,Time[0]);
     ObjectSet("weRa",OBJPROP_PRICE1,wRa); 
    
     
  Print("iRa   ",iRa,wRa);
 return(iRa);
}  
Works, but not always correctly. I've attached objects for visual assessment. Any tips or where to look.
 
Galim_V:
It works, but not always correctly. I attached the objects for visual assessment. Please advise or where to look.

What is DRAW_LINE for?

 double  iRa =  NormalizeDouble(iCustom(NULL,tf,"iRevers",InpSARStep,InpSARMaximum,DRAW_LINE,0),Digits);
 double  wRa =  NormalizeDouble(iCustom(NULL,wtf,"iRevers",InpSARStep,InpSARMaximum,DRAW_LINE,0),Digits);
 
Alexey Viktorov:

What is DRAW_LINE for?

I corrected the code. But it didn't work correctly, not even because of errors in the code. I do tests in the terminal of my broker and I don't always watch the connection with the server. It is very important in this case. Thank you.
 

Hello. How do I know the closing price at M30 if the EA is on the H1 chart?

Close_M30= iClose(Symbol(),PERIOD_M30,1);
 
bij:

Hello. How do I know the closing price at M30 if the EA is on the H1 chart?

I like it when people ask a question and answer it themselves ))

Basically, everything is correct. There is just one subtle point: before using data obtained from another timeframe, we have to make sure that this data exists at all.

So the full correct code would look like this

ResetLastError();
Close_M30= iClose(Symbol(),PERIOD_M30,1);
if (GetLastError() != ERR_NO_ERROR)
{
  // Значение Close_M30 использовать нельзя
}
 
Ihor Herasko:

I like it when people ask a question and then answer it themselves ))

By and large everything is correct. There's just one nuance: before using data from another TF, you need to make sure that this data exists at all.

So the full correct code would look like this:

Thank you, action only after H1 close, but the condition is met 30 minutes before H1 close.

 ResetLastError();
   niz_=NormalizeDouble(iCustom(NULL,PERIOD_M30,"mand v.1",2,1),Digits);
   Close_M30=iClose(Symbol(),PERIOD_M30,1);
   if(GetLastError() != ERR_NO_ERROR)return;
   if(Close_M30>niz_)//условие
     {
      //действие
     }
 
bij:

Thank you, the action is only after the H1 close, but the condition is met 30 minutes before the H1 close.

If you want to take the M30 candle that closed with the last H1 close, it can be a candle with index not only 1, but also 2. Another thing is that then it is not clear why the closing price of M30 is taken when it is the same closing price for the previous H1 candle. That is, in this case there is no sense to interrogate the closing price of another TF, because it coincides with the closing price of the current TF.

Reason: