Download MetaTrader 5

If I use return() -> error5004

To add comments, please log in or register
cape1354
188
cape1354  
I try to use the value outside of the "for".

but when I use "return(Max_Value);"

, error 5004 appear


or print nothing

What should I do?


File "Max"

ex) 

2000-00-00 0:00,00

2000-00-00 0:00,00

2000-00-00 0:00,00

00 => Value between 1 and 100

int Past = 2;
int BarsCount = 0;
int i;

bool Max_Average=False;
bool NewBar= false;

double Max_Value;

int data_size = 8650;


datetime PreviousBar;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {
//---
   string file_name = "max.csv";
   
   string data_double_average[],data_double_datetime[];
   
      
     int file_handle = FileOpen(file_name, FILE_READ|FILE_CSV,",");
     
     if(file_handle != INVALID_HANDLE)
     {
     // PrintFormat("Name : %s", file_name);
      
      ArrayResize(data_double_datetime, data_size);
      ArrayResize(data_double_average,data_size);
     
     
      for(i = 0; i<1000; i++)
            {
            data_double_datetime[i]= FileReadString(file_handle,1);
            data_double_average[i]= FileReadString(file_handle,2);
            
            //Print(data_double_datetime[i], ", ", data_double_average[i]);
            if(StringToTime(data_double_datetime[i])== TimeCurrent() ){
            //Print("True");
            Max_Value=StringToDouble(data_double_average[i]);
                        
            }
                     
            }
            
      FileClose(file_handle);
      return(Max_Value);
      }
      else PrintFormat("error : %d", file_name, GetLastError());
   
      Print(Max_Value);
   
   
    /*  for(int i = 0; i< data_size; i++)
         PrintFormat("data_double_open[%d] : %f", i, data_double_open[i]);*/
     
      
  return(0); 
  }
    
//+------------------------------------------------------------------+
//|         |
//+------------------------------------------------------------------+

bool NewBar()
{
if(PreviousBar<Time[0])
{
PreviousBar=Time[0];
return(true);
}
return(false);
}







Keith Watford
Moderator
10541
Keith Watford  
cape1354:


I have removed the huge spaces in your posted code. Please consider others and make your code as easy as possible to read. Code with 10 empty lines between lines of code is not easy to read.
Naguisa Unada
124
Naguisa Unada  
Alain Verleyen :

And please stop double posting again and again. You already have 1 thread on the same topic where people took time to answer.

I will remove this one (sorry Keith).

I deleted it, but I just answered and I did not double post.
Alain Verleyen
Moderator
33796
Alain Verleyen  
Naguisa Unada:
I deleted it, but I just answered and I did not double post.
Sorry I don't know what happened, I was answering to the OP, not you. You can post of course.
Naguisa Unada
124
Naguisa Unada  

All right. Never mind.

To add comments, please log in or register