checking for open orders at same price

 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
i=0; buy=0; sell=0;
orders=OrdersTotal();

for (i=0;i<=orders;i++)
{
OrderSelect(i,SELECT_BY_TICKET);

price_open=OrderOpenPrice();
if (price_open==price_buy) buy=1;
if (price_open==price_sell) sell=1;

if (buy==0) OrderSend(Symbol(),OP_BUYSTOP,lots,price_buy,3,0,price_buy+Point*tp,"",111,0,Blue);
if (sell==0) OrderSend(Symbol(),OP_SELLSTOP,lots,price_sell,3,0,price_sell-Point*tp,"",111,0,Red);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

why the check won't work? it still opens orders where there's already open orders.
 
change

OrderSelect(i,SELECT_BY_TICKET);

to

OrderSelect(i,SELECT_BY_POS);
 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
i=0; buy=0; sell=0;
orders=OrdersTotal();

for (i=0;i<=orders;i++)
{
OrderSelect(i,SELECT_BY_TICKET);

price_open=OrderOpenPrice();
if (price_open==price_buy) buy=1;
if (price_open==price_sell) sell=1;

if (buy==0) OrderSend(Symbol(),OP_BUYSTOP,lots,price_buy,3,0,price_buy+Point*tp,"",111,0,Blue);
if (sell==0) OrderSend(Symbol(),OP_SELLSTOP,lots,price_sell,3,0,price_sell-Point*tp,"",111,0,Red);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

why the check won't work? it still opens orders where there's already open orders.


As abouve, you should select by ticket. You should also check return value from orderselect, as you are looping more iterations that you have orders. You should learn how to compare doubles.
 
change

OrderSelect(i,SELECT_BY_TICKET);

to

OrderSelect(i,SELECT_BY_POS);





i tried that already. still the same problem.
 
change

OrderSelect(i,SELECT_BY_TICKET);

to

OrderSelect(i,SELECT_BY_POS);





i tried that already. still the same problem.

You should really learn how to compare doubles. Use Google.
 
change

OrderSelect(i,SELECT_BY_TICKET);

to

OrderSelect(i,SELECT_BY_POS);





i tried that already. still the same problem.

You should really learn how to compare doubles. Use Google.


Ok. i think i got it. thanks!