This Makes Me CRAZY

To add comments, please log in or register
saghez
39
saghez  

I make a Program to download symbols data.

whenever i run it it works correctly and everything is ok

but after a while i receive this message

Critical error occurred, debugging is stopped.


I have to Stop Metatrader5 By using Alt+Ctrl+Del from Task manager and meta editor to and then start them again and run program

again to continue downloading. 

it makes me crazy because i don't know what is wrong with my program.

sometimes it works without this message and some times it occurs several times.

Any Help will appreciate.

William Roeder
18892
William Roeder  
I guess you wrote an indicator. Indicators can not sleep. They can't run blocking calls and reading from the network is a blocking call.
saghez
39
saghez  

as a matter of fact I am using Indicators like RSI and ZIGZAG and RVI. I am using iCustom and iRsi and iRVI to get their results and save them all in one file.

each symbols data will saved in a individual file.


I can not understand what is indicators  sleep, and what is blocking call, I will be so happy if you have time to tell me what are these


Thanks a lot

Mafuta Landou
590
Mafuta Landou  
Without the codes, It will hard to assist
saghez
39
saghez  
void WriteCandelToFile(string sSymbol,string e_sSymbol,datetime StartDate,datetime EndDate,int MinAllowedBars,string FoldersPrefix,string SavedFolder,string e_SavedFolder)
{  MqlRates  rates_array[];
   ArraySetAsSeries(rates_array,true);
   int MaxBar=TerminalInfoInteger(TERMINAL_MAXBARS);
   short iCurrent=CopyRates(sSymbol,ThePeriod,StartDate,EndDate,rates_array);
   
   if (iCurrent==-1){ return; }
  
  
   double ZigZag_Buffer[];
   
   //-Indicators Parameters
   int ExtDepth=12,ExtDeviation=5,ExtBackstep=3;
   int CCI_PERIOD=20;
   //====================================
   string outputData,e_outputData,ErrData;
   int ResultFileHandle,e_ResultFileHandle;
   string ClosedFileName,e_ClosedFileName;
   string LongClosedFileName;
   datetime d1,d2;
   int bars;
   //====================================
   SetIndexBuffer(0,ZigZag_Buffer,INDICATOR_DATA);
   //=========================================================
   bars=Bars(sSymbol,ThePeriod,StartDate,EndDate);
      //======================================
      if (bars==0)return;
      
   int ZigZag_Handle=    iCustom(sSymbol,ThePeriod,"Examples\\ZigZag",ExtDepth,ExtDeviation,ExtBackstep); if(ZigZag_Handle == INVALID_HANDLE){Print("Error creating RSI1 indicator");    return;}
   
      ArrayResize(ZigZag_Buffer,bars);
      int ZigZag_Copy_value=           CopyBuffer(ZigZag_Handle    ,0,StartDate,EndDate,ZigZag_Buffer           ); if (ZigZag_Copy_value==-1){           Hoax(ResultFileName,bars,"Zig",ZigZag_Copy_value,ZigZag_Buffer);}

      ArraySetAsSeries(ZigZag_Buffer,true);
      //========================================
      e_ResultFileHandle=FileOpen(e_ResultFileName,FILE_WRITE|FILE_CSV|FILE_ANSI);
      FileWriteString(e_ResultFileHandle,"<TICKER>,<DTYYYYMMDD>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>\n");
      FileSeek(e_ResultFileHandle,0,SEEK_END);
      
     
      int StPoint=iCurrent-1-gap;
      for(i=StPoint; i>=0; i--)      
      {
         Numb++;
         ErrData="***";
         
            outputData =TimeToString(rates_array[i].time,TIME_DATE); 
            .....
            e_outputData+=","+DoubleToString(rates_array[i].open,0);
            FileWriteString(e_ResultFileHandle,e_outputData);
     }
     FileFlush(e_ResultFileHandle);      
     FileClose(e_ResultFileHandle);

     ArrayFree(ZigZag_Buffer);
     return;
  }
}         
saghez
39
saghez  
Mafuta Landou:
Without the codes, It will hard to assist

Thanks a lot for your comment

I Inserted Important part of my code

William Roeder
18892
William Roeder  
saghez: I Inserted Important part of my code
   double ZigZag_Buffer[];
:
   SetIndexBuffer(0,ZigZag_Buffer,INDICATOR_DATA);
Make the array global, and make it a buffer in OnInit.
saghez
39
saghez  

William Roeder:
Make the array global, and make it a buffer in OnInit.


I Changed My Program Like the following but ,I am sorry to say, Still the same error message is produced.

   //-BUFFERs DEFINE----------------------
   double ZigZag_Buffer[];
int OnInit()
  {
   SetIndexBuffer(0,ZigZag_Buffer,INDICATOR_DATA);
   return(INIT_SUCCEEDED);
  }
Seng Joo Thio
576
Seng Joo Thio  
saghez:

Thanks a lot for your comment

I Inserted Important part of my code

I think nobody knows what you were creating - a script? an expert? or an indicator? 

I'll just assume it's a script which u drag onto a chart to do the symbol data downloading and writing to file. As such, based on the codes u revealed, I was able to run without problem after slight changes here and there (mainly quick fixes (e.g. commenting out some lines, and declaring some variables...) to remove compilation errors since the code segment u gave wasn't complete):

//+------------------------------------------------------------------+
//|                                                       saghez.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   WriteCandelToFile(Symbol(),"",iTime(Symbol(),PERIOD_MN1,2),iTime(Symbol(),PERIOD_MN1,0),100,"","","");
  }
//+------------------------------------------------------------------+

void WriteCandelToFile(string sSymbol,string e_sSymbol,datetime StartDate,datetime EndDate,int MinAllowedBars,string FoldersPrefix,string SavedFolder,string e_SavedFolder)
{  
   ENUM_TIMEFRAMES ThePeriod = PERIOD_H1;
   string ResultFileName = "saghez.txt";
   string e_ResultFileName = "esaghez.txt";
   double gap = 0.01;
   int i, Numb = 0;
   
   MqlRates  rates_array[];
   ArraySetAsSeries(rates_array,true);
   int MaxBar=TerminalInfoInteger(TERMINAL_MAXBARS);
   short iCurrent=CopyRates(sSymbol,ThePeriod,StartDate,EndDate,rates_array);
   
   if (iCurrent==-1){ return; }
  
  
   double ZigZag_Buffer[];
   
   //-Indicators Parameters
   int ExtDepth=12,ExtDeviation=5,ExtBackstep=3;
   int CCI_PERIOD=20;
   //====================================
   string outputData,e_outputData,ErrData;
   int ResultFileHandle,e_ResultFileHandle;
   string ClosedFileName,e_ClosedFileName;
   string LongClosedFileName;
   datetime d1,d2;
   int bars;
   //====================================
   //SetIndexBuffer(0,ZigZag_Buffer,INDICATOR_DATA);
   //=========================================================
   bars=Bars(sSymbol,ThePeriod,StartDate,EndDate);
      //======================================
      if (bars==0)return;
      
   int ZigZag_Handle=    iCustom(sSymbol,ThePeriod,"Examples\\ZigZag",ExtDepth,ExtDeviation,ExtBackstep); if(ZigZag_Handle == INVALID_HANDLE){Print("Error creating RSI1 indicator");    return;}
   
      ArrayResize(ZigZag_Buffer,bars);
      int ZigZag_Copy_value=CopyBuffer(ZigZag_Handle    ,0,StartDate,EndDate,ZigZag_Buffer           );
      if (ZigZag_Copy_value==-1)
      {
         //Hoax(ResultFileName,bars,"Zig",ZigZag_Copy_value,ZigZag_Buffer);
         Print ("Error = ", GetLastError());
      }
      else
         Print ("ZigZag_Copy_value = ", ZigZag_Copy_value);

      ArraySetAsSeries(ZigZag_Buffer,true);
      //========================================
      e_ResultFileHandle=FileOpen(e_ResultFileName,FILE_WRITE|FILE_CSV|FILE_ANSI);
      FileWriteString(e_ResultFileHandle,"<TICKER>,<DTYYYYMMDD>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>\n");
      FileSeek(e_ResultFileHandle,0,SEEK_END);
      
     
      int StPoint=iCurrent-1-gap;
      for(i=StPoint; i>=0; i--)      
      {
         Numb++;
         ErrData="***";
         
            outputData =TimeToString(rates_array[i].time,TIME_DATE); 
            //.....
            e_outputData+=","+DoubleToString(rates_array[i].open,5);
            FileWriteString(e_ResultFileHandle,e_outputData);
     }
     FileFlush(e_ResultFileHandle);      
     FileClose(e_ResultFileHandle);

     ArrayFree(ZigZag_Buffer);
     return;
  }
       

So the problem you had may not be due to this code segment?

To add comments, please log in or register