Download MetaTrader 5

What is the cause of the error (expressions are not allowed on a global scale )

To add comments, please log in or register
reza90
13
reza90  

Hi

What is the problem the following code?

string stat3()
if (stat1>stat2)
    return("buy");
else if (stat1<stat2)

  return("sell");


Carl Schreiber
6691
Carl Schreiber  
Load your code (not only this snippet) in a different editor and count the brackets: { and } and ( and ) and then start to find where have you either one of them too many or too less.
reza90
13
reza90  
Carl Schreiber:
Load your code (not only this snippet) in a different editor and count the brackets: { and } and ( and ) and then start to find where have you either one of them too many or too less.
//+------------------------------------------------------------------+
//|                                                         6060.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
extern int stat1 = 50;
extern int stat2 = 100;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
  
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
 
  }
//---
  
  //+------------------------------------------------------------------+
string stat3()
if (stat1>stat2)
    return("buy");
else if (stat1<stat2)
  return("sell");
whroeder1
14780
whroeder1  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. void OnTick()
      {

      }
    ^^^^^^^^^^^ OnTick has ended. vvvvvvvvvv everything below is on global scope.
honest_knave
Moderator
2423
honest_knave  
reza90:

void OnTick()
  {
 
  }
//---
  
  //+------------------------------------------------------------------+
string stat3()
if (stat1>stat2)
    return("buy");
else if (stat1<stat2)
  return("sell");
string stat3()
  {
   if (stat1>stat2)      return("buy");
   else if (stat1<stat2) return("sell");
   return("");
  }
reza90
13
reza90  
honest_knave:
string stat3()
  {
   if (stat1>stat2)      return("buy");
   else if (stat1<stat2) return("sell");
   return("");
  }
Thank you dear friend
To add comments, please log in or register