critical error in array

 
Hello, dear professors.
Unfortunately I had a problem with the arrays.
I have been trying to find a problem for a few days
But I could not solve the problem. Can you help me? Please?
 
Can I write my program code here?
 
Aimar X:
Can I write my program code here?

Yes, use Code button (Alt+S) </>

 
//+------------------------------------------------------------------+
//|                                                         JACK.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property strict


     double kharid[30];
     double forosh[30];
      double s[200];
      double n[200];
      short i=0;
      short j=0;
      bool flags=false;
      bool flagn=false;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {   
      double SENKOUSPANA=( iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANA,-26));
      double SENKOUSPANB=( iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANB,-26));
 
      if(SENKOUSPANA>SENKOUSPANB && Volume[0]<=1)
                               {
                               ArrayFill(s,i,1,SENKOUSPANA) ;
                            //   Print("a" ,s[i]); 
                           //    Comment("",s[0]," ",s[1]," ",s[2]," ",s[3]);
                               i=i+1;
                               if(i==200){i=0;}
                               flags=true;
                                 }
       if(SENKOUSPANA<SENKOUSPANB  && Volume[0]<=1)
                     {
                      ArrayFill(n,j,1,SENKOUSPANB)  ;
                     // Print("b" ,n[j]);
                     //  Comment("",n[0]," ",n[1]," ",n[2]," ",n[3]); 
                      j=j+1; 
                      if(j==200){j=0;}
                      flagn=true;
                       } 
                       
       if(flags==true && flagn==true){
                                       if(SENKOUSPANA>SENKOUSPANB )
                                                   {
                                                   double minnum=ArrayMinimum(n,WHOLE_ARRAY,0);
                                                   ResetLastError();
                                                   int handle=FileOpen("minimums",FILE_READ|FILE_WRITE|FILE_CSV);
                                                            if(handle!=INVALID_HANDLE)
                                                                {
                                                                 FileSeek(handle,0,SEEK_END);
                                                                 FileWrite(handle,DoubleToString(minnum,2));
                                                                 FileClose(handle);
                                                                 }
                                                            else
                                                                 Print("Failed to open the file, error ",GetLastError());
                                        // for(short d=0;d<200;d++){n[d]=NULL;}          
                                                   ArrayFree(n);
                                                   j=0;                                                             
                                                    } 
                                        if( SENKOUSPANA<SENKOUSPANB )
                                                 {
                                                  double maxnum=ArrayMaximum(s,WHOLE_ARRAY,0);
                                                  ResetLastError();
                                                  int handle=FileOpen("maximums",FILE_READ|FILE_WRITE|FILE_CSV);
                                                         if(handle!=INVALID_HANDLE)
                                                                 {
                                                                 FileSeek(handle,0,SEEK_END);
                                                                 FileWrite(handle,DoubleToString (maxnum,2));
                                                                 FileClose(handle);
                                                                  }
                                                          else
                                                                 Print("Failed to open the file, error ",GetLastError());
                                                             //  for(short e=0;e<200;e++){s[e]=NULL;} 
                                                 ArrayFree(s);
                                                 i=0;                                                            
                                                 }
                                   flagn=false;
                                   flags=false;
                                     }
  
     else if(SENKOUSPANA==SENKOUSPANB  && Volume[0]<=1){Sleep(60000);}
//-----------------------------------------------------------------------------------------------------------------------------------
                       ResetLastError();
                       int handl=FileOpen("maximums",FILE_WRITE|FILE_READ|FILE_CSV);
                       if(handl!=INVALID_HANDLE)
                                   {
                                     FileSeek(handl,0,SEEK_SET);
                                     for(short k=0;k<30;k++){
                                           if((StringToDouble(FileReadString(handl)))==NULL || (StringToDouble(FileReadString(handl)))==0 ){break;}
                                           ArrayFill(forosh,k,1,StringToDouble(FileReadString(handl))) ;
                                           if(k==29){k=0;}
                                                             }
                                     for(short l=0;l<30;l++) {                  
                                           if(Bid==(forosh[l]))
                                                 {

                                                 SendNotification("SELL "+forosh[l]); 
                                                  Alert("SELL ",forosh[l]); 
                                                  forosh[l]=NULL ;
                                                  }                       
                                                            }
                                                                  
                            FileSeek(handl,0,SEEK_SET);
                            for(short m=0;m<30;m++){ if(forosh[m]==NULL){continue;}
                            FileWrite(handl,DoubleToString(forosh[m],2));
                                                   } 
                                                                                          
                        FileClose(handl);


                        ArrayFree(forosh);
                                    }
                        else
                            Print("Failed to open the file, error ",GetLastError()); 
//------------------------------------------------------------------------------------------------------------------
                          ResetLastError();
                          int hand=FileOpen("minimums",FILE_WRITE|FILE_READ|FILE_CSV);
                          if(hand!=INVALID_HANDLE)
                                      {
                                      FileSeek(hand,0,SEEK_SET);
                                            for(short a=0;a<30;a++){
                                            if((StringToDouble(FileReadString(hand)))==NULL || (StringToDouble(FileReadString(hand)))==0 ){break;}
                                            ArrayFill(kharid,a,1,StringToDouble(FileReadString(hand)));
                                            if(a==29){a=0;}
                                                                    }
                                      for(short b=0;b<30;b++) {                    
                                               if(Bid==(kharid[b])){
                                                    SendNotification("Buy "+kharid[b]); 
                                                    Alert("Buy ",kharid[b]); 
                                                    kharid[b]=NULL ;
                                                                    }                        
                                                               }
                                                                  
                                       FileSeek(hand,0,SEEK_SET);
                                       for(short c=0;c<30;c++){ if(kharid[c]==NULL){continue;}
                                       FileWrite(hand,DoubleToString(kharid[c],2));
                                                              } 
                                       FileClose(hand);


                                       ArrayFree(kharid);
                                       }
                             else
                                Print("Failed to open the file, error ",GetLastError()); 
     
     
     
     
     
  }
//+-------
 
Aimar X:

Please highlight the lines of code where you are having a problem.

Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

 
Keith Watford :

Please highlight the lines of code where you are having a problem.

Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.

Sorry, I was distracted

 
No one to help me?
 
Aimar X:
No one to help me?

Try removing the ArrayFree function call.

Several times I have tried the ArrayFree function, resulting in incorrect array values. If using ArrayFree, I always do ArrayResize after that.

 
Aimar X: No one to help me?

Use the debugger or print out your variables (sizes),  and find out why. Do you really expect us to debug your code for you?

Reason: