Why?

 

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())
 
Put those inside start() or OnTick() and see what happen.
 
 for (Count = OrdersTotal()-1; Count >= 0; Count--)
 

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())
 
deysmacro:
Put those inside start() or OnTick() and see what happen.

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

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

No need OnTick() then.


By the way, where is { & } ?

 

what's the problem

works fine for me

 
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!
 

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.

 

It is probably the code prior to your posted code

If it has one too many "}"

Then you will get that error

Reason: