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"

- www.metatrader5.com
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.
//+------------------------------------------------------------------+ //| 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 }
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)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.
A little help please, thank you!