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

 

The objective is to open only one order on the current zero bar.

If there was already a closed order on the current bar, do not open a new one.

And the code does not work:

bool is = OrderSelect(1, SELECT_BY_POS, MODE_HISTORY);
 
       if ( iTime(NULL,0,0) < OrderOpenTime() || is == false){
 
 
 if (OrdersTotal() < 1) OrderSend(Symbol(), OP_BUY, 1, Ask, 3, 0,0, "", 1212, 0, clrGreen);
  }
 
Pavel Verveyko:
but can it be done this way? (Only the last type - with a rectangle - would work now).


ObjectsDeleteAll(0,"prefix",0,OBJ_LABEL);
ObjectsDeleteAll(0,"prefix",0,OBJ_RECTANGLE_LABEL);

is to remove all objects that have the type OBJ_LABEL or OBJ_RECTANGLE_LABEL

 
HeAic:

The objective is to open only one order on the current zero bar.

If there was already a closed order on the current bar, do not open a new one.

The code does not work:

datetime openBarTime=iTime(_Symbol,_Period,0);

bool orderFound=false;

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

   ... /// тут всякие проверки на select,magic,symbol,type и проч

   if (OrderOpenTime()>=openBarTime) {

       orderFound=true; // нашёлся ордер открытый на текущем баре

       break;

   }

}

if (!orderFound) {

   // не было ордеров на текущем баре - трам пам пам

   ...

}

the orders will have to be memorised and executed separately. In general, it is done better as a complex

About closed orders similar check by HISTORY

 

What is the usual way to display text on a graphic? Anywhere, just text?

is ithttps://www.mql5.com/ru/docs/objects ? point me in the right direction

Документация по MQL5: Графические объекты
Документация по MQL5: Графические объекты
  • www.mql5.com
Функции, задающие свойства графических объектов, а также операции создания ObjectCreate() и перемещения ObjectMove() объектов на графике фактически служат для отправки команд графику. При успешном выполнении этих функций команда попадает в общую очередь событий графика. Визуальное изменение свойств графических объектов производится в процессе...
 
 
Maxim Kuznetsov:

datetime openBarTime=iTime(_Symbol,_Period,0);

bool orderFound=false;

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

   ... /// тут всякие проверки на select,magic,symbol,type и проч

   if (OrderOpenTime()>=openBarTime) {

       orderFound=true; // нашёлся ордер открытый на текущем баре

       break;

   }

}

if (!orderFound) {

   // не было ордеров на текущем баре - трам пам пам

   ...

}

The pauses will have to be memorised and processed separately. In general, this is done more optimally as a complex

about closed ones, similar check by HISTORY

So, I found an example for my own case from the reference book:

bool orderFound=false;

 // retrieving info from trade history 
  int i,accTotal=OrdersHistoryTotal(); 
  for(i=0;i<accTotal;i++) 
    { 
     //---- check selection result 
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) 
       { 
        Print("Ошибка при доступе к исторической базе (",GetLastError(),")"); break; 
       } 
     // работа с ордером ... 
   if (OrderCloseTime() > iTime(_Symbol,_Period,0))orderFound=true ;// нашёлся ордер закрытый на текущем баре
    }
//-----
 
 if(OrdersTotal() < 1 && orderFound == false ) {//тут открываем ордера по алгоритму
  

I will close orders like this:

   if( OrdersTotal() > 0) 
 
     {
        for(cnt = 0; cnt < OrdersTotal(); cnt++)
      {
       bool s = OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
       
      
       if( TimeCurrent()>= OrderOpenTime()+ (lifetime * 60)) // lifetime - время в минутах
          
          {
           
           if(OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber())    // long position is opened
            

Thanks for your help :)

 
Hello. Hello, everyone. Can you help me find an indicator

Balance of power. Where can I download it? Thank you. (chuckles)

 
2004sasha:
Hello. Hello all. Help me find an indicator

Balance of power. Where can I download it? Thank you.

A search on the website will come up with a result.


 
Maxim Kuznetsov:

is to remove all objects which have type OBJ_LABEL or OBJ_RECTANGLE_LABEL

I understand that you can call them 2.

, but my question is this

ObjectsDeleteAll

does the function go through the loop specifying OBJ_TREND and select only objects of the correct object type or does it create the loop with only the required objects at once?

Reason: