What RefreshRates() updates - page 6

 
Mikhail Nazarenko:

MT4 is a dark box and I can only judge what happens there by testing in real conditions. Initially I didn't use sleep at all, but when I was getting bullshit on some hour bars I added sleep and the problem disappeared. I don't know in what order and how the MT4 time series is updated. I'm not sure what to do with it, I will use it as an opportunity to fix my problem and share it with others.

I`ve been experiencing this problem myself, everything is fine in the tester, but on the real market it is nothing.

I`ve been running the Expert Advisor since Monday and I`m surprised.

I have opened several profitable openings and then went back to buy instead of sell, and vice versa.

Forum on trading, automated trading systems & strategy testing

Any questions from newbies on MQL4 and MQL5, or any tips and discussion on algorithms and codes

Vitaly Muzichenko, 2021.02.15 21:48

I have already started working with MQL4 to check my algorithm.

I have never tried it before, but I've never seen such an algorithm correctly. Simple code, only 2 indicator buffers



The code is very simple

   double poi=Point();
   for(int i = limit-2; i>0; i--) {
      if(open[i+0] > close[i+0] && MathAbs(open[i+0] - high[i+0]) < 0.1 * poi)
         Dn[i] = high[i+0] + 30 * poi;
      if(open[i+0] < close[i + 0] && MathAbs(open[i+0] - low[i+0]) < 0.1 * poi)
         Up[i] = low[i+0] - 30 * poi;
   }
 
Vitaly Muzichenko:

I have faced this myself, everything is fine in the tester, but in the real market it's rubbish.

I've been running the EA since Monday and am surprised.

I'm surprised. Some openings are correct, but after that I am buy again instead of sell and vice versa.


Indicator code is simple.

This is the same problem I had before I started this thread. I made the isRefresh() function above. Try it. It worked fine for me.

But it's not slippage?

 
Vitaly Muzichenko:

The code of the indicator is simple

does the indicator open trades?

the arrows are the same - the problem is in the EA code

 
Mikhail Nazarenko:

If you start to teach, then help, confirm with code, tests, a link to a forum topic or documentation. Everything else is just brain masturbation.

Please clarify what remains unclear. After reading it seemed that the main question is solved and it remains to discuss how obsolete 4 is).

I had no problems after inserting such timeframe loading

bool HistoryCheck(int TF)
  {
   int err=0;   
   int i=0;
   datetime d1=0,d2=0;
   while(i<10)
    { 
    if((d1=iTime(NULL,TF,0))==0 || (d2=iTime(NULL,TF,InpPeriod*2))==0)          
        PrintFormat("itime=0, %s, %s", TimeToString(d1),TimeToString(d2)) ; 
   err=GetLastError();    
   if(err==4066)    
    {
    	PrintFormat("Error=4066") ; 
    	 Sleep(500);     	
    }
   else break;	
      SleepA(100);
      i++;                 
    } // while
   if(i==10)
	 { Comment("Update failed. Go to the next attempt."); return(false); }
   PrintFormat("HistoryCheck %d , %s, %s",i,TimeToString(d1),TimeToString(d2)) ;
   Comment(""); 
   return(true);
  }

If you need to seldom and irregularly access the timeframe, you should (but not necessarily if the chart is open) perform this loading again before checking

  if((iTime(NULL,TF,0)+PeriodSeconds(TF))<TimeCurrent()
   || (iTime(NULL,TF,1)+PeriodSeconds(TF)*2)<TimeCurrent())
   HistoryCheck(TF)
Документация по MQL5: Операции с графиками / ChartOpen
Документация по MQL5: Операции с графиками / ChartOpen
  • www.mql5.com
ChartOpen - Операции с графиками - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Mikhail Nazarenko:

This is the same thing I encountered before opening this thread. For some reason terminal gives outdated data on real, I wrote isRefresh() function above. Try it. It worked fine for me.

But it's not slippage?

No, it opens on a new 0 bar and the signal is looked for on the closed bar, i.e. 1.

That is the situation sometimes when an EA does not get what is expected through iCustom(). Again: sometimes, but not often.

Here is another one - a fresh one. I have correctly opened a buy position according to the signal and the next signal from the indicator is also buy (arrow below). But the EA viaiCustom() has received a sell signal and closed the buy position and opened the sell one, though there should be another buy position opened.

Something is wrong with time series, I have not understood it yet, it was found 4 days ago and I probably will not try to find it out. I have not seen any problems in the tester

Right now.

--- And I just found


 

And also, but already instead of a sell, a buy is open. As I said, it is not often, but it happens

The code of the indicator is simple - there are no complicated


 
Aleksey Mavrin:

Please clarify what remains unclear. After reading this, it seems that the main question is solved and we are left to discuss how obsolete 4 is)

I have not had any problems after inserting timeframes loaded in this way

If you need to seldom and irregularly access a timeframe, you should (but not necessarily if the chart is open) do this loading again before checking, or such a check will help

This is correct,

this is from the help:

The indicator and timeseries data are accessed independently of the fact that the requested data are ready (so called asynchronous access). This is critical for the calculation of custom indicators, so in the absence of the requested data the functions like Copy...() immediately return an error. However, when accessing from Expert Advisors and scripts, several attempts to receive data are made, with a small pause, which is aimed at providing the time necessary to download required timeseries or to calculate indicator values.


If information is requested from another chart (instrument name and/or timeframe value differ from the current one), the situation may occur, when there is no appropriate chart opened in the client terminal and the necessary data have to be requested from the server. In this case, error ERR_HISTORY_WILL_UPDATED (4066 - requested history data in update state) will be placed in the _Last_error variable and the request must be retried after some time (see ArrayCopySeries() example).

 
Vitaly Muzichenko:

And also, but already instead of a sell, a buy is open. As I said, it is not often, but it happens

The code of the indicator is simple - there are no intricacies


The most reliable method is to write the log. At each transaction write the values of the key variables in the file. From experience: not strict condition <=0 instead of <0 introduced a terrible curvature.

 
Vitaly Muzichenko:

I have faced this myself, everything is fine in the tester, but in the real market it's rubbish.

I've been running the EA since Monday and am surprised.

I'm surprised. Some openings are correct, but after that I am buy again instead of sell and vice versa.


The indicator code is simple

   double poi=Point();
   for(int i = limit-2; i>0; i--) {
      if(open[i+0] > close[i+0] && MathAbs(open[i+0] - high[i+0]) < 0.1 * poi)
         Dn[i] = high[i+0] + 30 * poi;
      if(open[i+0] < close[i + 0] && MathAbs(open[i+0] - low[i+0]) < 0.1 * poi)
         Up[i] = low[i+0] - 30 * poi;
   }


Why would I add 0 to [i + 0] ?

 
Aleksey Mavrin:

Please clarify what remains unclear. After reading this, it seemed that the main question is solved and we still need to discuss how obsolete 4 is)

I have not had any problems after inserting timeframes loaded in this way

If you need to refer to the timeframe rarely and irregularly, then this loading should (but not necessarily if the chart is open) be done again before checking, or such a check would help

Thank you, that's the point. Does the terminal really give a 4066 error after accessing an unupdated time series via iTime? I've encountered iClose giving unupdated information instead of zero.

Reason: