Download MetaTrader 5

Outside "for" ???

To add comments, please log in or register
cape1354
188
cape1354  

How do I use the Max Value value outside of function "for"?



int BarsCount = 0;
int i;
bool Max_Average=False;
bool NewBar= false;
double Max_Value;
int data_size = 8650;




int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
  }
 int start()
  {

 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(data_double_datetime[i]==TimeToString( TimeCurrent() ) ){
            //Print("True");
            Max_Value=StringToDouble(data_double_average[i]);
            //}
            
            }


}
Carl Schreiber
Moderator
7943
Carl Schreiber  
  1. You defined Max_Value as global variable so it is globally accessible.
  2. for is not a function, so variable that are not defined within the loop 'keep' their value after the loop has ended
  3. Your code snippet will not return a max. value but only the last value - think about using fmax() or MathMax()?
  4. It would be better to initialize Max_Value for fmax(). In your case the variable is automatically init. by 0 but in other cases it has a random value!
whroeder1
17063
whroeder1  
  1. int OnInit()
      {
       return(INIT_SUCCEEDED);
      }
    void OnDeinit(const int reason)
      {
      }
    int start() ...
    Start using the new Event Handling Functions Or the old ones. Not both.

  2. Carl Schreiber: It would be better to initialize Max_Value for fmax(). In your case the variable is automatically init. by 0 but in other cases it has a random value!
    Not using strict it will be zero only the first time your code runs. Code breaks after that. Other comments are also valid.

  3.  for(i = 0; i<1000; i++)
    Are you sure you have a thousand lines in the file? Make it an infinite loop and stop when you've exhausted the file.

  4. data_double_datetime[i]= FileReadString(file_handle,1);
    data_double_average[i]= FileReadString(file_handle,2);
    Your timestamp is only one character? Your double is only two? why are you reading a string when you know it's a double?
  5. Don't double post
  6. Stop Triple posting!
Alain Verleyen
Moderator
35040
Alain Verleyen  
whroeder1:
  1. Start using the new Event Handling Functions Or the old ones. Not both.

  2. Not using strict it will be zero only the first time your code runs. Code breaks after that. Other comments are also valid.

  3. Are you sure you have a thousand lines in the file? Make it an infinite loop and stop when you've exhausted the file.

  4. Your timestamp is only one character? Your double is only two? why are you reading a string when you know it's a double?
  5. Where do you ever open the file?

The OP obviously has very little knowledge about programming. Instead of such extensive answer and all these links, I would suggest you to create a new topic, for example, "FAQ about mql4 programming" (name doesn't matter of course) or something like that. With all your remarks and links, using anchors. So you will be able to provide 1 link related to the OP topic and at the same time the OP will have access to all information if he wants. In case you do it, please don't use html table.

By the way you didn't answer the OP question.

whroeder1
17063
whroeder1  
Alain Verleyen: you will be able to provide 1 link related to the OP topic, please don't use html table.
  1. Makes no sense when the OP has at least four separate problems.
  2. What table? I haven't use a table since I read your first mention of the problem yesterday.
Alain Verleyen
Moderator
35040
Alain Verleyen  
whroeder1:
  1. Makes no sense when the OP has at least four separate problems.
  2. What table? I haven't use a table since I read your first mention of the problem yesterday.
I am talking in general about your posts, taking this one as example. Sorry mentioning table, I was preparing this post before you stopped to use them and didn't had time to post it.
nicholishen
1525
nicholishen  
Alain Verleyen:
I am talking in general about your posts, taking this one as example. Sorry mentioning table, I was preparing this post before you stopped to use them and didn't had time to post it.

I agree. Almost all of whroeder1's forum replies are barely readable on mobile.

whroeder1
17063
whroeder1  
nicholishen: I agree. Almost all of whroeder1's forum replies are barely readable on mobile.

For the Nth time. I have not posted a single post with tables for over 28 hours. Since the first mention of a problem. How many times do you people have to repeat it????

To add comments, please log in or register