Problems with opening new position

 

Hello,

I have a problem related to opening new position.
I would like to make my EA open one hedge position if I have only one open position at the exact moment.

I tried to use that code:


if (OrdersTotal() == 1){

for(int cnt=0;cnt<OrdersTotal();cnt++)
{


OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()==OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MAGIC
)
{ OrderSend(Symbol(), OP_BUY, lots ,Ask, 3, Ask - stop_loss * Point, Bid + take_profit * Point, IDENT, MAGIC, 0, Blue);


}

if(OrderType()==OP_BUY &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MAGIC
)

{OrderSend(Symbol(), OP_SELL, lots ,Bid, 3, Bid + stop_loss * Point, Ask - take_profit * Point, IDENT, MAGIC, 0, Red);
}

}

}

But it doesn't work.
Can anyone help me up or make this code even shorter?


Thanks.

 
Camza:

Hello,

I have a problem related to opening new position.
I would like to make my EA open one hedge position if I have only one open position at the exact moment.

I tried to use that code:

<CODE REMOVED>

But it doesn't work.
Can anyone help me up or make this code even shorter?

Please edit your post . . .    please use the   SRC   button to post code: How to use the   SRC   button.
 
  1. Use SRC
  2. Check your return codes to find out why.
 
Camza:

Hello,

I have a problem related to opening new position.
I would like to make my EA open one hedge position if I have only one open position at the exact moment.


But it doesn't work.
Can anyone help me up or make this code even shorter?

It's very easy to make non-functioning code shorter . . .  here . . .

if (OrdersTotal() == 1) return(0);

  . . . it's shorter and performs just as well as your code.

Perhaps you should concentrate of making it work before making it shorter ?

Do the OrderSend() calls fail ?  oh,  you don't bother to check,  why not ?

Read this:  What are Function return values ? How do I use them ? 

 
OrderSend() works properly, just I can't check which order is opened at the moment - if it's BUY or SELL.
 
Camza:
OrderSend() works properly, just I can't check which order is opened at the moment - if it's BUY or SELL.
Can you please edit your first post as requested.
Reason: