Download MetaTrader 5

Why?

To add comments, please log in or register
Ernest Klokow
1119
Ernest Klokow  

I use the following snippet of code in two different EA's. In the one there is no problem when I compile the code, but in the other it gives me an error message saying;

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

Why? I have searched and searched and cannot find the cause. Can somebody please help me?

Here is the snippet of code:

 Count = 0;
   for (Count = OrdersTotal()-1; Count >= 0; Count
   if (OrderSelect(Count, SELECT_BY_POS)
   && OrderType() == OP_SELL
   && OrderMagicNumber() == MagicNumber
   && OrderSymbol() == Symbol())
SYED NAUFAL GADDAFI
1399
SYED NAUFAL GADDAFI  
Put those inside start() or OnTick() and see what happen.
qjol
3243
qjol  
 for (Count = OrdersTotal()-1; Count >= 0; Count--)
Ernest Klokow
1119
Ernest Klokow  

Sorry! I copied the code incorrectly. Here it is now the way it is in my program:

             Count = 0;
         
             for (Count = OrdersTotal()-1; Count >= 0; Count--)
                    if (OrderSelect(Count, SELECT_BY_POS)
                    && OrderType() == OP_SELL
                    && OrderMagicNumber() == MagicNumber
                    && OrderSymbol() == Symbol())
Ernest Klokow
1119
Ernest Klokow  
deysmacro:
Put those inside start() or OnTick() and see what happen.

It is inside Start(). Never worked with OnTick() before, but I will investigate
SYED NAUFAL GADDAFI
1399
SYED NAUFAL GADDAFI  
Hmm.. there is missing puzzle here...
SYED NAUFAL GADDAFI
1399
SYED NAUFAL GADDAFI  
ernest02:

It is inside Start(). Never worked with OnTick() before, but I will investigate

No need OnTick() then.


By the way, where is { & } ?

qjol
3243
qjol  

what's the problem

works fine for me

Ernest Klokow
1119
Ernest Klokow  
qjol:

what's the problem

works fine for me


Works fine in one EA, but give the error in another EA using the identical code. Do not understand what is going on!
SYED NAUFAL GADDAFI
1399
SYED NAUFAL GADDAFI  

You copy and paste right? Well, it is always like that. One time it works, other time not. Show us where you put the code.

qjol can point you the right way then. XD


but usually anything that says ...

expressions are not allowed on a global scope

means .. you have missed { or } or ( or ) or some/all. Most of the case happened to me.

Keith Watford
Moderator
10646
Keith Watford  

It is probably the code prior to your posted code

If it has one too many "}"

Then you will get that error

12
To add comments, please log in or register