Problem with opening hedge position

 

Hi!

 

I try to do EA hedge.

Hedge for one open order.

And i don't know what's wrong with conditions.

 

 

double bid = MarketInfo(Symbol(), MODE_BID);

      double ask = MarketInfo(Symbol(), MODE_ASK);

      OrderSelect(1,SELECT_BY_POS,MODE_TRADES);

        cena=OrderOpenPrice();

        ce=cena-60*Point; 

        typ=OrderType();

        if (OrdersTotal()==1 && typ==0 && ce>bid)

 

 

 

 OrderSelect(1,SELECT_BY_POS,MODE_TRADES);

        cena=OrderOpenPrice();

        ce=cena+60*Point; 

        typ=OrderType();

        if (OrdersTotal()==1 && typ==1 && ce<ask)

 

could you help me? 

 
serafin:

Hi!

 

I try to do EA hedge.

Hedge for one open order.

And i don't know what's wrong with conditions.

 <CODE DELETED>

Please edit your post . . .    please use the   SRC   button to post code: How to use the   SRC   button.
 
serafin:

Hi!

 

I try to do EA hedge.

Hedge for one open order.

And i don't know what's wrong with conditions.

Where is your OrderSend()  ?
 
i didn't write ordersend because i know it's good. Problem is in the conditions.
 
OrderSelect(1,SELECT_BY_POS,MODE_TRADES); // Selects the second open order. Fails if there isn't
cena=OrderOpenPrice();                    // Fails if orderSelect did
ce=cena-60*Point; 
typ=OrderType();                          // Fails if orderSelect did (typ=0?)
if (OrdersTotal()==1 && typ==0 && ce>bid)
   OrderSelect(1,SELECT_BY_POS,MODE_TRADES);
  1. What are Function return values ? How do I use them ? - MQL4 forum
  2. 60*Point not adjusting for 4/5 digit brokers.
  3. No braces on the If. If only handles the orderSelect. If there is only one order you try to select the second one. Select always fails. Remaining code is always executed.



 
serafin:
i didn't write ordersend because i know it's good. Problem is in the conditions.
If you say so . . .

OrderSelect()  the index starts at 0,  not 1.  If you only have one open order it's index will be 0.