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?
- Use SRC
- Check your return codes to find out why.
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.