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

 

Hi

What is the problem the following code?

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

  return("sell");


 
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.
 
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");
 
  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.
 
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("");
  }
 
honest_knave:
string stat3()
  {
   if (stat1>stat2)      return("buy");
   else if (stat1<stat2) return("sell");
   return("");
  }
Thank you dear friend