Download MetaTrader 5

Why?

To add comments, please log in or register
Track all payments in your profile. It is easy!
Ernest Klokow
1091
Ernest Klokow 2014.04.07 09:50 

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
1401
SYED NAUFAL GADDAFI 2014.04.07 10:08  
Put those inside start() or OnTick() and see what happen.
qjol
3243
qjol 2014.04.07 10:51  
 for (Count = OrdersTotal()-1; Count >= 0; Count--)
Ernest Klokow
1091
Ernest Klokow 2014.04.07 11:05  

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
1091
Ernest Klokow 2014.04.07 11:08  
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
1401
SYED NAUFAL GADDAFI 2014.04.07 11:15  
Hmm.. there is missing puzzle here...
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.07 11:17  
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 2014.04.07 11:20  

what's the problem

works fine for me

Ernest Klokow
1091
Ernest Klokow 2014.04.07 11:23  
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
1401
SYED NAUFAL GADDAFI 2014.04.07 11:27  

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
9647
Keith Watford 2014.04.07 11:29  

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