Download MetaTrader 5
To add comments, please log in or register
How to choose the most appropriate signal and subscribe to it in no time
trader1000
6
trader1000 2010.10.04 07:33 

I am writing this code in order to read the history of a symbol and save it in a dynamic array, but it returns (copied = -1), which means it cannot read anything. What is wrong with it?



//+------------------------------------------------------------------+
//|                                                           aa.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {

   MqlRates rates[];
   int copied = CopyRates(Symbol() , PERIOD_M1 , D'2007.01.01 00:00:00' , D'2008.01.01 00:00:00' , rates);
  

   if(copied>0)
     {
      Print("Bars copied: "+copied);
      string format="open = %G, high = %G, low = %G, close = %G, volume = %d";
      string out;
      int size=fmin(copied,10);
      for(int i=0;i<size;i++)
        {
         out = i + " : " + TimeToString(rates[i].time);
         out = out + " " + StringFormat(format,
                                        rates[i].open,
                                        rates[i].high,
                                        rates[i].low,
                                        rates[i].close,
                                        rates[i].tick_volume);
         Print(out);
        }
     }
   else Print("Failed to get history data for the symbol ",Symbol());
  }
  
 
//+------------------------------------------------------------------+

Automated Trading and Strategy Testing
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Vladimir Batrudinov
4863
Vladimir Batrudinov 2010.10.04 08:01  
trader1000:

I am writing this code in order to read the history of a symbol and save it in a dynamic array, but it returns (copied = -1), which means it cannot read anything. What is wrong with it?

//+------------------------------------------------------------------+
//|                                                           aa.mq5 |
//|                        Copyright 2010, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {

   MqlRates rates[];
   int copied = CopyRates(Symbol() , PERIOD_M1 , D'2007.01.01 00:00:00' , D'2008.01.01 00:00:00' , rates);
  

   if(copied>0)
     {
      Print("Bars copied: "+copied);
      string format="open = %G, high = %G, low = %G, close = %G, volume = %d";
      string out;
      int size=fmin(copied,10);
      for(int i=0;i<size;i++)
        {
         out = i + " : " + TimeToString(rates[i].time);
         out = out + " " + StringFormat(format,
                                        rates[i].open,
                                        rates[i].high,
                                        rates[i].low,
                                        rates[i].close,
                                        rates[i].tick_volume);
         Print(out);
        }
     }
   else Print("Failed to get history data for the symbol ",Symbol());
  }
//+------------------------------------------------------------------+

Probably between these dates too much information for the selected period.

Try to choose another period or change interval of the dates.

I tried on this interval of the dates with a period in 15M.

alix7
4
alix7 2010.12.09 22:25  
Interesting:

Probably between these dates too much information for the selected period.

Try to choose another period or change interval of the dates.

I tried on this interval of the dates with a period in 15M.

Since a few days ago I'm having the same problem (previously my code was working fine). I think there is an issue here. I tried the posted code with a 15M period and it doesn't work.

Data is present in the directory Bases\MetaQuotes-Demo\history\ and I am using the same corresponding account.

Any help would be greatly appreciated.

/
To add comments, please log in or register