[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 1096

 
kolyango:
How do I make this code check whether we already have a buy order or not before buying. If there are no market buy orders, then only then execute the buy?

I have posted an EA today in my toys. It's all there.
 
Vinin:

I posted an advisor in toys today. It's all there.

What kind of toys?
 
kolyango:

What kind of toys?

https://www.mql5.com/ru/forum/108553/page28
 

Which one is it? The name of it...
 
kolyango:

Which one is it? The name of it...

There's only one advisor of mine. Doesn't seem to help, though.
 
Vinin:

There's only one advisor of mine. Although from the looks of it, it won't help.

))))))
 

How do I make this code check whether we already have a buy order or not before buying. If there are no market buy orders, then only then execute the buy?

extern double LOT = 0.01;
//--------------------------------------------------------------------------------------------
int start()
{
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if (OrderSymbol() !=Symbol() || OrderType() !=OP_SELL ) continue;
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,White);
Alert (GetLastError()); // Выводит сообщение об ошибке

OrderSend(Symbol(),OP_BUY,LOT,Ask,1,Bid-400*Point,Bid+400*Point,0,Green);
Alert (GetLastError()); // Выводит сообщение об ошибке
return(0);
}
}
}
//--------------------------------------------------------------------------------------------

 
kolyango:

How do I make this code check whether we already have a buy order or not before buying. If there are no market buy orders, then only then execute the buy?

extern double LOT = 0.01;
//--------------------------------------------------------------------------------------------
int start()
{
for (int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if (OrderSymbol() !=Symbol() || OrderType() !=OP_SELL ) continue;
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,White);
Alert (GetLastError()); // Выводит сообщение об ошибке

OrderSend(Symbol(),OP_BUY,LOT,Ask,1,Bid-400*Point,Bid+400*Point,0,Green);
Alert (GetLastError()); // Выводит сообщение об ошибке
return(0);
}
}
}
//--------------------------------------------------------------------------------------------


int OrderBuy=0;
for(int cnt=0;cnt<OrdersTotal();cnt++){
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)){
if(OrderMagicNumber()==Magic){
if(OrderSymbol()==Symbol()){
if(OrderType()==OP_BUY) OrderBuy++;
} } } }

if(OrderBuy==0) Open a position.

 
DhP:

int OrderBuy=0;
for(int cnt=0;cnt<OrdersTotal();cnt++){
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)){
if(OrderMagicNumber()==Magic){
if(OrderSymbol()==Symbol()){
if(OrderType()==OP_BUY)OrderBuy++;
} } } }

if(OrderBuy==0) Open position.


int i;
extern double LOT = 0.01;

//--------------------------------------------------------------------------------------------
int start()
{
//-----
for (i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
{
if (OrderSymbol() !=Symbol() || OrderType() !=OP_SELL ) continue;
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,White);
Alert (GetLastError()); // Выводит сообщение об ошибке
int OrderBuy=0;
for(int cnt=0;cnt<OrdersTotal();cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
{
if(OrderMagicNumber()==Magic)
{
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) OrderBuy++;
}
}
}
}
if(OrderBuy==0) // Открыть позицию
{
OrderSend(Symbol(),OP_BUY,LOT,Ask,1,Bid-400*Point,Bid+400*Point,0,Green);
Alert (GetLastError()); // Выводит сообщение об ошибке
return(0);
}
}
}
//-----
}
//--------------------------------------------------------------------------------------------


'Magic' - variable not defined C:\Program Files (x86)\Alpari ÌÒ4\experts\111.mq4 (25, 36)

How do you define Magic ? int Magic? And there's probably no need to assign anything, right?

 
Thanks DhP !!! Just what you need !!! Everything works!!!