MT5: 'for' expressions are not allowed on a global scope

 

This indicator is similar to the RSI.  The idea is to calculate  net_profit / [sum(positive returns) + abs(sum(negative returns))]  in a rolling window. 

But after I changed the code in the main loop, the terminal says:   'for' expressions are not allowed on a global scope

//--- the main loop of calculations
   for(int i=pos; i<rates_total && !IsStopped(); i++)
     {
      double diff=price[i]-price[i-1];
      ExtPosBuffer[i]=ExtPosBuffer[i-1]+(diff>0.0?diff:0.0);
      ExtNegBuffer[i]=ExtNegBuffer[i-1]+(diff<0.0?-diff:0.0);
      ExtRSIBuffer[i]=(ExtPosBuffer[i]+ExtNegBuffer[i])/(ExtPosBuffer[i]-ExtNegBuffer[i]);

     }

The similar part works for the official RSI. I don't understand this error.

The file is attached below. 

Thank you. 


Update: 

I got this warning.  But the code is modified from the official RSI and the terminal is up to date. 


Files:
 
Phoebe Hj:

This indicator is similar to the RSI.  The idea is to calculate  net_profit / [sum(positive returns) + abs(sum(negative returns))]  in a rolling window. 

But after I changed the code in the main loop, the terminal says:   'for' expressions are not allowed on a global scope

The similar part works for the official RSI. I don't understand this error.

The file is attached below. 

Thank you. 

You put an extra closing brace } on line 85, remove it and it'll compile.
 
Alexandre Borela #:
You put an extra closing brace } on line 85, remove it and it'll compile.

Solved. Thank you very much.

 

hello.I have this problem.please help to solve

'for' - expressions are not allowed on a global scope

Files:
5.jpg  91 kb
 
akbar1372625 #: 'for' - expressions are not allowed on a global scope

So put them inside a function.

Reason: