iclose/iopen etc

 

The following code does not work - please help

I am trying to run this code  in strategy tester on period M1

basically i want the open/close/high/low of the M5 candle

to figure out the problem i even changed the 0 to 1 in all the code

I ran this code in strategy tester for 12/01/2024 - 12/15/2024

this code is from   https://docs.mql4.com/series/itime

Print("Current bar for USDCHF M5: ",iTime("USDCHF",PERIOD_M5,0),", ",  iOpen("USDCHF",PERIOD_M5,0),", ",
                                      iHigh("USDCHF",PERIOD_M5,0),", ",  iLow("USDCHF",PERIOD_M5,0),", ",
                                      iClose("USDCHF",PERIOD_M5,0),", ", iVolume("USDCHF",PERIOD_M5,0));

Improperly formatted code edited by moderator.

iTime - Timeseries and Indicators Access - MQL4 Reference
iTime - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
iTime - Timeseries and Indicators Access - MQL4 Reference
 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

Please always use the CODE button (Alt-S) when inserting code.

Code button in editor

 
rjngh2005: The following code does not work - please help

Just saying it "does not work" means nothing. We have no idea what you mean by it, nor can we see what you expect.

Explain in detail, provide screenshots and show the output from the logs.

EDIT: Also, please note that when acquiring data from a different time-frame from the one being tested you have to synchronise the data and handle 4066/4073 errors.

Forum on trading, automated trading systems and testing trading strategies

William Roeder, 2022.08.16 14:57

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

 
Fernando Carreiro #:

Just saying it "does not work" means nothing. We have no idea what you mean by it, nor can we see what you expect.

Explain in detail, provide screenshots and show the output from the logs.

Here is the EDIT: Also, please note that when acquiring data from a different time-frame from the one being tested you have to synchronise the data and handle 4066/4073 errors.

Here is the ouptput I get when i run the code in live/strategy tester   (m1) i am expecting some values for the m5

Current bar for XAUUSD M5: 1970.01.01 00:00:00, 0.0, 0.0, 0.0, 0.0, 0

iTime - Timeseries and Indicators Access - MQL4 Reference
iTime - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
iTime - Timeseries and Indicators Access - MQL4 Reference
 

i checked the logs - i do not see any errors in it

also the history center option to download data says - data is current no new data available

 

rjngh2005 #:

Here is the ouptput I get when i run the code in live/strategy tester   (m1) i am expecting some values for the m5

Current bar for XAUUSD M5: 1970.01.01 00:00:00, 0.0, 0.0, 0.0, 0.0, 0

If i remember right, that farthest date allowed in mt4 is not fixed, it is actually a maximum number of candles, so I remember a thread only recently, in last 10 days, where the op mentioned 1976 was the earliest date that he could get. And I think that the moderator mentioned that even this date will become invalid as this earliest date continues to move forward.
 
rjngh2005 #: Here is the ouptput I get when i run the code in live/strategy tester   (m1) i am expecting some values for the m5

Current bar for XAUUSD M5: 1970.01.01 00:00:00, 0.0, 0.0, 0.0, 0.0, 0

Did you correct your code according to the advice given in my post?

Also, please note that when acquiring data from a different time-frame from the one being tested you have to synchronise the data and handle 4066/4073 errors.

Forum on trading, automated trading systems and testing trading strategies

William Roeder, 2022.08.16 14:57

On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - MQL4 programming forum - Page 3 #26.4 (2019)

 
Fernando Carreiro #:

Did you correct your code according to the advice given in my post?

Also, please note that when acquiring data from a different time-frame from the one being tested you have to synchronise the data and handle 4066/4073 errors.

this correction is required if there are errors

however in my logs i see no errors

 
rjngh2005 #: this correction is required if there are errors, however in my logs i see no errors
The 4066/4073 errors don't appear in the logs. You have to process them just as indicated. Follow the links and read up on how to process them.
 
//+------------------------------------------------------------------+
//|                                               tstOtherCandle.mq4 |
//|                                  Copyright 2025, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
bool New_Bar=false;
datetime New_Time=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   Fun_New_Bar();
   if(New_Bar==false)
      return;

   Print(", Time ",New_Time, ",Open value ,",Open[1],",Close value ,",Close[1],", Open value M5,",iOpen(_Symbol,PERIOD_M5,1),", Close value M5,",iClose(_Symbol,PERIOD_M5,1));
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Fun_New_Bar()
  {

   New_Bar=false;

   if(New_Time !=Time[0])
     {
      New_Time=Time[0];

      New_Bar=true;
     }

  }
//+------------------------------------------------------------------+

here is the final code which is working fine


Thanks a lot everyone