Error -1 iBarShift

 

hi everyone, i have a problem with this iBarShift function.

As soon as I look for a candle before midnight on the server, it returns error -1 as if it has no data history but the history is there.


void OnTick()
  {
  
   Data       = TimeCurrent();
   Mezzanotte = Data - (Data % 86400); // 86400 == 1 Day in seconds      
   
  
  Mezzanotte  = Mezzanotte+25200; // 25200 -7 Time 00:00 New York
  Mezzanotte1 = Mezzanotte-86400; // 86400 -24 hours  New York
  
   
  index       = iBarShift(NULL,PERIOD_CURRENT,Mezzanotte);
  index1      = iBarShift(NULL,PERIOD_CURRENT,Mezzanotte1,true);
   
  LineaV("LineaMezzanotte",0,index,Blue);
  LineaV("LineaMezzanotte1",0,index1,Blue); 
  
  
  Print(TimeToString(Mezzanotte )+"---"+"Indice Mezzanotte : "+IntegerToString(index));
  Print(TimeToString(Mezzanotte1)+"---"+"Indice Mezzanotte1: "+IntegerToString(index1));
  
  /*  
  Print("Numero totale di barre per il periodo-simbolo specificati al momento = ", 
         SeriesInfoInteger(Symbol(),Period(),SERIES_BARS_COUNT)); 
  
  Print("La prima data per il simbolo-periodo in questo momento = ", 
         (datetime)SeriesInfoInteger(Symbol(),Period(),SERIES_FIRSTDATE)); 
  
  Print("La prima data nello storico per il simbolo-periodo sul server = ", 
         (datetime)SeriesInfoInteger(Symbol(),Period(),SERIES_SERVER_FIRSTDATE)); 
  
  Print("I dati dei simboli sono sincronizzati = ", 
         (bool)SeriesInfoInteger(Symbol(),Period(),SERIES_SYNCHRONIZED)); 
  */
  
  }


A little help please, thank you!

 

I understand that if I get the error -1 it means that I don't get historical data ... ok!

But how can I recover this data?

This morning this data was present but when I tried with ibarschift to go to the past I got error -1 again!!!

 

If your program compiles without any error but doesn't do what is should use the debugger and control the relevant variables:

https://www.metatrader5.com/en/metaeditor/help/development/debug // Code debugging
https://www.mql5.com/en/articles/2041 // Error Handling and Logging in MQL5
https://www.mql5.com/en/articles/272 // Tracing, Debugging and Structural Analysis of Source Code
https://www.mql5.com/en/articles/35 // scrol down to: "Launching and Debuggin"

I would recommand to check the time setting.
Code debugging - Developing programs - MetaEditor Help
Code debugging - Developing programs - MetaEditor Help
  • www.metatrader5.com
MetaEditor has a built-in debugger allowing you to check a program execution step by step (by individual functions). Place breakpoints in the code...
 

Thanks for the answer, I also tried debugging but the result doesn't change. From the screnn you can see how the date calculated with the variable Mezzanotte3 is correct but with the iBarShift() on line 101

index3      = iBarShift(NULL,PERIOD_CURRENT,Mezzanotte3,true);
I get error -1 that is there are no candles in the graph but instead it is not so. debug

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{

   Data       = TimeCurrent();
   Mezzanotte = Data - (Data % 86400); // 86400 == 1 giorno in secondi
   //int      index      = iBarShift(NULL,PERIOD_CURRENT,Mezzanotte);


   Mezzanotte  = Mezzanotte+FusoOrario; // -7 ore Orario New York
   Mezzanotte1 = Mezzanotte-86400;      // -24 ore Orario New York
   Mezzanotte2 = Mezzanotte1-86400;     // -48 ore ore Orario New York
   Mezzanotte3 = Mezzanotte2-86400;     // -72 ore ore Orario New York

   index       = iBarShift(NULL,PERIOD_CURRENT,Mezzanotte, true);
   index1      = iBarShift(NULL,PERIOD_CURRENT,Mezzanotte1,true);
   index2      = iBarShift(NULL,PERIOD_CURRENT,Mezzanotte2,true);
   index3      = iBarShift(NULL,PERIOD_CURRENT,Mezzanotte3,true);

   if(index == -1) Print("Dati Storico Assenti Mezzanotte: "+IntegerToString(index));

   else LineaV("LineaMezzanotte",0,index,Blue); // Linea Mezzanotte New York

   if(index1 == -1) Print("Dati Storico Assenti Mezzanotte1: "+IntegerToString(index1));

   else LineaV("LineaMezzanotte1",0,index1,Blue); // Linea Mezzanotte1 New York  

   if(index2 == -1) Print("Dati Storico Assenti Mezzanotte2: "+IntegerToString(index2));

   else LineaV("LineaMezzanotte2",0,index2,Blue); // Linea Mezzanotte2 New York
   
   if(index3 == -1) Print("Dati Storico Assenti Mezzanotte3: "+IntegerToString(index3));

   else LineaV("LineaMezzanotte3",0,index3,Blue); // Linea Mezzanotte3 New York

}
 
Please check a) the error message and b) whether the market is closed on D'2022.10.02 07:00' and no quotes are available.
 
Carl Schreiber #:
Please check a) the error message and b) whether the market is closed on D'2022.10.02 07:00' and no quotes are available.
What he said. Try setting iBarshift accuracy to false.
 

You precalculate the dates and use iBarShift(true). Code fails over the weekend and market holidays.

Use false, and compute the next day from the date shift returns.

See yesterday:
          Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)

 
Thanks to all I understand!!!
Reason: