Error 4024 on ChartOpen

 

In the code below, the error comes up on ChartOpen.  Now, despite the error; the chart still opens. 

After going through a few things, I actually found out the problem.  MT4 using too much memory.  I made the following changes:

Somehow after I installed MT4, I forgot to change the Max bars property.  1000 is too much too for me.  I don't see why anyone would need more than that.

Here's the code:

//+------------------------------------------------------------------+
//|                                                    ChartHelp.mqh |
//|                                                   Nondisclosure. |
//|                                              https://no.link.yet |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property strict

input bool bPrefix=false; //Is there a prfix?
input string sPrefix="";  //..And if so, what is it?
input bool bSuffix=false;  //Is there a suffix?
input string sSuffix=""; //..And if so, what is it?
input string sTemplate="Defalt";//What chart template should we use?


string Pairs[13]=
  {
   "EURUSD","EURAUD","EURCAD","EURJPY","EURNZD","EURGBP","EURCHF",
   "GBPUSD","GBPAUD","GBPCAD","GBPJPY","GBPNZD","GBPCHF"
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SetupCharts()
  {
   if(bPrefix || bSuffix)
     {
      ResetPairs();
     }
   int tf=PERIOD_H1;
   OpenThem(tf,StringConcatenate(sTemplate,".tpl"));
   tf=PERIOD_D1;
   OpenThem(tf,StringConcatenate(sTemplate,".tpl"));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ResetPairs()
  {
   if(bPrefix)
     {
      for(int i=0;i<ArraySize(Pairs);i++)
        {
         Pairs[i]=StringConcatenate(sSuffix,Pairs[i]);
        }
     }
   if(bSuffix)
     {
      for(int i=0;i<ArraySize(Pairs);i++)
        {
         Pairs[i]=StringConcatenate(Pairs[i],sSuffix);
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OpenThem(int tf,string tpl)
  {
   long IDs;
   bool isOpen=false;
   for(int i=0;i<ArraySize(Pairs);i++)
     {
      isOpen=funcIsOpen(Pairs[i],tf);
      if(!isOpen)
        {
         IDs=ChartOpen(Pairs[i],tf);
         if(IDs==0)
           {
            Print("Error on Chart Open! Template: ",tpl,". Error: ",GetLastError());
           }
         else
           {
            ChartApplyTemplate(IDs,tpl);
           }
        }
      Sleep(100);
     }
  }
  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool funcIsOpen(string sym,int tf)
  {
   bool isFound=false;
   long chartID;
   chartID=ChartFirst();
   string chartSymbol;
   int chartTimeframe=0;
   while(chartID!=-1)
     {
      chartSymbol=ChartSymbol(chartID);
      chartTimeframe=ChartPeriod(chartID);
      if(chartSymbol==sym && chartTimeframe==tf)
        {
         isFound=true;
        }
      //Comment("Chart id:",chartID,"\n","Symbol: ",ChartSymbol(chartID),"\n","Timeframe: ",ChartPeriod(chartID));
      chartID=ChartNext(chartID);
     }
   return(isFound);
  }

//+------------------------------------------------------------------+
//| defines                                                          |
//+------------------------------------------------------------------+
// #define MacrosHello   "Hello, world!"
// #define MacrosYear    2010
//+------------------------------------------------------------------+
//| DLL imports                                                      |
//+------------------------------------------------------------------+
// #import "user32.dll"
//   int      SendMessageA(int hWnd,int Msg,int wParam,int lParam);
// #import "my_expert.dll"
//   int      ExpertRecalculate(int wParam,int lParam);
// #import
//+------------------------------------------------------------------+
//| EX5 imports                                                      |
//+------------------------------------------------------------------+
// #import "stdlib.ex5"
//   string ErrorDescription(int error_code);
// #import
//+------------------------------------------------------------------+
Anyway.  I'm posting this just in case someone else is having the same problem.   :)

 
  1. Your problem may be related to the other problems with that build.
  2. Report it so it gets fixed.
 
whroeder1:
  1. Your problem may be related to the other problems with that build.
  2. Report it so it gets fixed.

No.  I fixed it.  I was able to track it down to a memory limitation on my system.  When I keep what's running on the pc to a minimum; I don't get the error.  But if I do something else that's memory intensive (Visual Studio installer, not installing, just loaded); I get the error.

I don't believe it is a problem with the build at all.‌

 
Michael:

No.  I fixed it.  I was able to track it down to a memory limitation on my system.  When I keep what's running on the pc to a minimum; I don't get the error.  But if I do something else that's memory intensive (Visual Studio installer, not installing, just loaded); I get the error.

I don't believe it is a problem with the build at all.‌


But is it Build 1045?

Y‌ou shouldn't need to drop max bars to 1000 under normal circumstances.

 
honest_knave:


But is it Build 1045?

Y‌ou shouldn't need to drop max bars to 1000 under normal circumstances.

Ok.  I would think so, but that's ok.  I'll look for an email for support.

 
whroeder1:
  1. Your problem may be related to the other problems with that build.
  2. Report it so it gets fixed.
Sorry.  I shouldn't have been so terse toward you.  I should've behaved better.  :(
Reason: