Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1166

 

Can you please tell me how to set order selection by symbol for OrdersTotal()?

   int total=OrdersTotal();

   if(total==0&&Bid>=OrderBuy&&Bid<=OrderBuy+10*Point)
    {
     if(OrderSend(Symbol(),OP_BUY,Lot,Ask,5,0,0,NULL,0,0,clrNONE)){::Alert(" Order Open ");}
    }

Right now, if there is an open order on one pair, it won't open on others.

 
MakarFX:

Can you please tell me how to set order selection by symbol for OrdersTotal()?

Now, if there is an open order on one pair, it does not open on others.

Look at kodobase, there is an example in every EA

 
Vladimir Pastushak:

Look in kodobase, there is an example in every advisor

I am not a programmer(

It's a bit complicated for me.

 
MakarFX:

I'm not a programmer(

It's a bit complicated for me.

it's not complicated.

to write a basic EA, here is all the functionalityhttps://www.mql5.com/ru/forum/131859

For your purposes OrdersTotal() is the total number of open orders (numbered from 0 ) in the terminal, then you need to select them one by one (go through the loop) using OrderSelect() and manipulate the necessary orders

for (i=OrdersTotal()-1; i>=0; i--)
{
  if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) 
  {
   // проверим символ ордера, проверим магикномер ордера....
  }
}
Только "Полезные функции от KimIV".
Только "Полезные функции от KimIV".
  • 2011.02.18
  • www.mql5.com
Все функции взяты из этой ветки - http://forum.mql4...
 
MakarFX:

Can you please tell me how to set order selection by symbol for OrdersTotal()?

Right now, if there is an open order on one pair, it does not open on others.

I need to periodically check (count myself) my orders as needed.
I have in every EA a loop (a huge method) which is called before important actions:

for(int pos=OrdersTotal()-1; pos>=0;pos--) {

        if (!OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)) {

                selectFailed=true; /* не удалось "выбрать" ордер - статистика может быть неверной */
                continue;

        }

        if (OrderCloseTime()!=0) { /* ордер закрыт но ещё не удалён из списка*/ continue; }

        if (OrderMagicNumber()==0) { /* ордер выставлен юзером */ } continue;
        else if (OrderMagicNumber()!=_Magic) { /* ордер выставлен другим советником */ continue; }

        if (OrderSymbol()!=_Symbol) { /* ордер с правильным Magic но на другом символе */ continue; }

       /// обработка рабочих ордеров, с правильным Magic на символе советника (то есть наш ордер)

       /// проверяются несработки, считается кол-во, статистика, позиции и прочее 

}

check for an order on the symbol is highlighted

 
Maxim Kuznetsov:

periodically, as needed, to check (self-check) their orders.
I have a loop (a huge method) in each EA, which is called before important actions:

for(int pos=OrdersTotal()-1; pos>=0;pos--) {

        if (!OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)) {

                selectFailed=true; /* не удалось "выбрать" ордер - статистика может быть неверной */
                continue;

        }

        if (OrderCloseTime()!=0) { /* ордер закрыт но ещё не удалён из списка*/ continue; }

        if (OrderMagicNumber()==0) { /* ордер выставлен юзером */ } continue;
        else if (OrderMagicNumber()!=_Magic) { /* ордер выставлен другим советником */ continue; }

        if (OrderSymbol()!=_Symbol) { /* ордер с правильным Magic но на другом символе */ continue; }

       /// обработка рабочих ордеров, с правильным Magic на символе советника (то есть наш ордер)

       /// проверяются несработки, считается кол-во, статистика, позиции и прочее 

}

check the order by the symbol is highlighted

On a side note, I understand that the tickers of historical orders may get lost. The question is if the order tickers(SELECT_BY_TICKET) in MT4 and tickers of deals and positions in MT5 may change.

And also, may the order be changed after the OrderSelect on the ticket. For example the next day. The EA is not disabled.

If the pending order has become a market order, you can view it by its type. If the market order has closed, then we look at the time of order closing, not equal to zero OrderCloseTime()!=0

If the pending order has closed by its lifetime, then how do we track it by the order ticket.

And a question, the lifetime is also in market orders(MT4), does it work?

 
MakarFX:

Can you please tell me how to set order selection by symbol for OrdersTotal()?

Now, if there is an open order on one pair, it does not open on others.

The question is already solved. Thank you all.

 
Hello Dear Sirs! I don't understand what's wrong, why does Alert: time3-time1 = wrong datetime?
datetime time1 = iTime(NULL,0,1);
datetime time3 = iTime(NULL,0,3);
datetime delta3 = (time3-time1);  Alert("time3-time1 = ",delta3); 


 
novichok2018:
Hello Dear Sirs! I don't understand what's wrong, why it writes Alert: time3-time1 = wrong datetime?


because the number is negative :-)

by this logic time1 is __always __more than time3

 
Maxim Kuznetsov:

because the number is negative :-)

by the given logic time1 is __always __more than time3

Thank you! Sometimes the brain goes off.

Reason: