[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 347

 

Hello, here's a question. How can I write in the code to only perform an operation on a fixed fractal?

If fractal is fixed, it's ....

my fractal

int start()
  {
//----
    double CenBuy = High[isFractalUp()];
     double CenSell = Low[isFractalDn()];

   return(0);
}

int isFractalUp()
{
 for(int i=0; i != 10; i++)
 {
 if(iFractals(NULL, 0, MODE_UPPER, i)!= NULL) return(i);
 }
 return(-1);
}
 
int isFractalDn()
{
 for(int i=0; i != 10; i++)
 {
 if(iFractals(NULL, 0, MODE_LOWER, i)!= NULL) return(i);
 }
 return(-1);
}
 
hoz:

Hmm. Yes, no problem finding the appropriate pending order this way if the number of pending orders in each direction is the same. And if different, then this will not work as I understand it.

Then determine the fact of triggering of a pending order and delete the most distant opposite one.

All this is done only for one fact and one pending order at one moment in time. There is no need to create a number of triggered and number of deleted, as you are trying to do. You will catch the fact of transformation of the pending orders on one tick. All other triggers (if there are any) will be determined by the next tick.

 
Can you tell me who knows? Why is the tester result different on a weekday than on a weekend? Alpari
 

berezhnuy because of the spread, which is several times bigger on weekends.

 

Dear programmers, here is the code for counting buy and sell orders to open only one buy or sell order:

int CountBuy()
{
int count = 0;
for(int trade = OrdersTotal()-1; trade >= 0; trade--)
{
OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
{
if(OrderType() == OP_BUY)
count++;
}

}
return(count)
}
//+------------------------------------------------------------------+
int CountSell()
{
int count = 0;
for(int trade = OrdersTotal()-1; trade >= 0; trade--)
{
OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
{
if(OrderType() == OP_SELL)
count++;
}

}
return(count);
}

And everything seems to work, but in my EA, there are conditions to buy and sell on some candlestick patterns using TP and SL. But when this condition is fulfilled and TP is triggered, then at 0 candle's formation the conditions for order opening still remain true and new orders are opened, which should not be done at that moment. Could you please tell us which code to use to disable further opening of orders? The EA itself is attached.

Files:
expert.mq4  4 kb
 
artmedia70:

Then determine the fact of a triggered pending order and delete the furthest opposite one.

All this is done only for one fact and for one time. There is no need to create a number of triggered and number of deleted, as you are trying to do. You will catch the fact of transformation of the pending orders on one tick. All other triggers (if there are any) will be determined by the next tick.



And what if there is more than that per tick? If, let's say, the step between the orders is very small, then more than one order can trigger. Of course, we will not be able to perform all necessary actions in time.
 
hoz:

What if more passes in a tick? If, let's say, the step between the orders is very small, then more than one order can be triggered. Of course, we will not be able to perform the required actions in time.
A loop on open positions in search of triggered orders on the current bar and delete the pending orders in the same loop
 
artmedia70:
The loop on open positions in search of triggered orders on the current bar and deletion of positions in the same loop.


Well, this loop will be repeated and everything will be deleted again. I also have a condition in the variant I have at the moment:

 while (ordersToDelete > 0)                      // Если есть ордера, которые требуется удалить..
   {
      OrderDelete(s_ticket,Black);
      ordersToDelete--;                        // Уменьшаем количество требуемых ордеров для удаления на 1, т.к. строкой выше..
                                               // .. один отложенник уже удалили
   }

I.e. it should delete untilordersToDelete is zero. But it destroys everything. It seems to be elementary, but some outrage happens. There is nothing at all about such moments in a worthless tutorial. I already tried it both ways and rewrote it in different ways, it didn't work as I should.

 

Rewritten differently:

//+-------------------------------------------------------------------------------------+
//| Удаление несработанных отложеннык шортов                                            |
//+-------------------------------------------------------------------------------------+
void DeletePendingSells(int& amountOfCurrPending)
{
   int total = OrdersTotal() - 1,
       ordersToDelete = level - amountOfCurrPending,  // Количество отложек, которые требуется удалить
       s_ticket = -1,                                 // Тикет искомого ордера
       np = -1;                                       // Номер позиции искомого ордера
   amountOfCurrPendingBuys = 0;                       // Количество текущих отложек на покупку
   amountOfCurrPendingSells = 0;                      // Количество текущих отложек на продажу

   double OOP = 20.0;                                 // Зададим значение цены открытия отложки, которой не может быть..
   
   if (ordersToDelete == 0) return (0);               // Если ничего удалять не нужно, выйдем из функции

   for (int i=total; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if(OrderType() != OP_SELLSTOP) continue;         // Работает только с шортовыми ордерами
      
      if (OOP > OrderOpenPrice())
      {
          OOP = OrderOpenPrice();                  // Ищется ордер, с минимальной ценой открытия
          np = i;
      }
   }
   if (OrderSelect(np,SELECT_BY_POS))
   {
      s_ticket = OrderTicket();                // Получаем тикет ордера с минимальной ценой открытия
      OrderDelete(s_ticket,Black);
   }
   
   return (0);
}

Kim, also looking for the same way. Found an order with a minimum opening price, defined its position, and selected this order, defined its ticket and deleted it. But it is not deleted.

 
Why don't you remember the ticket of the order and not its position. and what happens in a direct transfer if there is no such order? will you delete the zero order ?