expression on the global scope not allowed

Mideel
90
Mideel  

please help me with this warning.. i've tried so hard to fix it but still no use.. the warning is expression on the global scope not allowed... :-(

also 1 more question what are:

*unbalanced left or right parentheses?

*end program/unbalanced parentheses?

*unbalanced parentheses?



if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)=true)
{
martin_level=OrderMagicNumber();
if(martin_level<=max_martin&&OrderSelect(1,SELECT_BY_POS,MODE_TRADES)=false)
{
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)=true)
{
type=OrderComment() ;
price=OrderOpenPrice() ;
volume=OrderLots() ;
stoploss=OrderStopLoss();
}
if(type="buy")
OrderSend(Symbol(),OP_BUYLIMIT,volume*2,stoploss,2,stoploss-(price-stoploss),price,"buy",martin_level++)
if(type="sell")
OrderSend(Symbol(),OP_SELLLIMIT,volume*2,stoploss,2,stoploss+(stoploss-price),price,"sell",martin_level++)
}
}

Simon Gniadkowski
17400
Simon Gniadkowski  

Before posting please read some of the other threads . . . then you would have seen numerous requests like this one:

Please use this to post code . . . it makes it easier to read.

Simon Gniadkowski
17400
Simon Gniadkowski  
mideel:

please help me with this warning.. i've tried so hard to fix it but still no use.. the warning is expression on the global scope not allowed... :-(

also 1 more question what are:

*unbalanced left or right parentheses?

*end program/unbalanced parentheses?

*unbalanced parentheses?

You are confusing the compiler by missing ; here . .

if(type="buy")
   OrderSend(Symbol(),OP_BUYLIMIT,volume*2,stoploss,2,stoploss-(price-stoploss),price,"buy",martin_level++)   // <----  missing  ;

if(type="sell")
   OrderSend(Symbol(),OP_SELLLIMIT,volume*2,stoploss,2,stoploss+(stoploss-price),price,"sell",martin_level++)   // <----  missing  ;

Unbalance parentheses happen when you don't have matching numbers of braces . . . ( and ) or { and }

Mideel
90
Mideel  
RaptorUK:

You are confusing the compiler by missing ; here . .

Unbalance parentheses happen when you don't have matching numbers of braces . . . ( and ) or { and }


still the warning showed

also there is a negative sign beside this text like this


if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)=true)
-{ <<<---------------- the warning or negative sign is located beside the brace...

dabbler
1091
dabbler  

this is wrong ...

if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)=true)

You need two equal signs for a comparison

if( dog==true )

but in this case the return value of OrderSelect is a bool in any case so this simplifies the code down to

if( OrderSelect(0,SELECT_BY_POS,MODE_TRADES) )
dabbler
1091
dabbler  

Now compiler error free

int start(){
   int max_martin =2;
   string type;
   double price;
   double volume;
   double stoploss;

   if( OrderSelect(0,SELECT_BY_POS,MODE_TRADES) ){
      int martin_level=OrderMagicNumber();
      if( martin_level<=max_martin && !OrderSelect(1,SELECT_BY_POS,MODE_TRADES) ){
         if( OrderSelect(0,SELECT_BY_POS,MODE_TRADES) ){
            type=OrderComment();
            price=OrderOpenPrice() ;
            volume=OrderLots() ;
            stoploss=OrderStopLoss();
         }
         
         if(type=="buy"){
            OrderSend(Symbol(),OP_BUYLIMIT,volume*2,stoploss,2,stoploss-(price-stoploss),price,"buy",martin_level);
            martin_level++;
         }
         if(type=="sell"){
            OrderSend(Symbol(),OP_SELLLIMIT,volume*2,stoploss,2,stoploss+(stoploss-price),price,"sell",martin_level);
            martin_level++;
         }
      }
   }
   
   return(0);
}

You have more assignments rather than comparisons (= rather than ==)

and MQL4 doesn't like the ++ in the OrderSend.

Mideel
90
Mideel  
dabbler:

Now compiler error free

You have more assignments rather than comparisons (= rather than ==)

and it doesn't like ++ in the OrderSend.


thanks..... sorry for the trouble...

but if i want the condition in if there is no a second order in the trading pool/mode_trades then perform the order send... is it like this?

if(OrderSelect(1,SELECT_BY_POS,MODE_TRADES)==false)

OrderSend . . . . . .

Simon Gniadkowski
17400
Simon Gniadkowski  
mideel:

thanks..... sorry for the trouble...

but if i want the condition in if there is no a second order in the trading pool/mode_trades then perform the order send... is it like this?

if(OrderSelect(1,SELECT_BY_POS,MODE_TRADES)==false)

OrderSend . . . . . .


The most versatile way of doing this . . . and some would argue the most correct, is to loop through all the open orders, check which match the Symbol you are working on, which are OP_BUY or OP_SELL (not pending) and which match your Magic number, count those and if that count is less than 2 go ahead and place your order.
William Roeder
25322
William Roeder  
mideel:

but if i want the condition in if there is no a second order in the trading pool/mode_trades then perform the order send... is it like this?

if(OrderSelect(1,SELECT_BY_POS,MODE_TRADES)==false)

OrderSend . . . . . .

But you do NOT what that. What about another open order on some other chart (by the same EA or another or manual trading?) You only want one order on the current chart by the current EA. Do it right.
int nOrders=0;
    for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--) if(
        OrderSelect(iPos, SELECT_BY_POS)             ) if(  // Only my orders w/
        OrderMagicNumber()  == magic.number          ) if(  // my magic number
        OrderSymbol()       == chart.symbol                 // and my pair.
    ){  nOrders++; }
if (nOrders == 0){
   :
Mideel
90
Mideel  
ok.. thanks for the advice everyone... but i have a LOT of questions ... and i don't think i should make a lot of new threads... should i collect all my different type questions and make one new thread or is there one thread to ask-answer...? -_-
Simon Gniadkowski
17400
Simon Gniadkowski  
mideel:
ok.. thanks for the advice everyone... but i have a LOT of questions ... and i don't think i should make a lot of new threads... should i collect all my different type questions and make one new thread or is there one thread to ask-answer...? -_-
First search, there is a search box top right of this page, also use Google with site:forum.mql4.com . . . then read the Documentation and Search the Book (using the search box top right) . . . . then if you still need help please feel free to ask in this tread . . .