[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 414

 
inoy:

The advisor will not close an order on time if there is another order on the symbol opened at an earlier time than the advisor's own order.
order. If someone else's order is open later or if there are no other orders, the OrderClose function works correctly. Please advise where the error is


The error is that you just take the order with index 0 and do not look for it among open orders.
 
Roger:

the error is that you simply take an order with index 0 instead of looking for it among the open orders.

I beg your pardon, but the situation is similar in THAT variant.
//---- закрытие позиции
if(OrdersTotal() > 0)
for(int i=OrdersTotal();i>=0;i--)
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol()&& OrderMagicNumber() == MagicNumber)
if ( iTime(Symbol(),0,0) >= OrderOpenTime()+SecondsClose )
if (OrderType() == OP_BUY)
OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),NormalizeDouble((Ask - Bid) * Point,Digits), DodgerBlue);
Would you be so kind as to provide the correct solution to the problem?
 
Avelox:

How to output a beep in an indicator from the following expression:

if (num1 == 9) {
ObjectCreate(""+i, OBJ_TEXT, 0, Time[i+1],High[i+1]+10*Point );
ObjectSetText(""+i, ""+DoubleToStr(num1,0), 16, "Arial", RoyalBlue);

}

If you can be more detailed than "You can use OBJ_SICICOCI and look at the details in the MQL4 documentation, it has everything!"

I managed to solve this issue myself:


ObjectCreate(""+i, OBJ_TEXT, 0, Time[i+1],High[i+1]+10*Point );
ObjectSetText(""+i, ""+DoubleToStr(num1,0), 18, "Arial", RoyalBlue);
PlaySound("havecall.wav"); }
 
inoy:

I beg your pardon, but in THIS scenario the situation is similar. Would you be so kind as to provide a proper solution to the problem?

//---- закрытие позиции
if(OrdersTotal() > 0) 
{
  for(int i=OrdersTotal();i>=0;i--) 
  {
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if (OrderSymbol()==Symbol()&& OrderMagicNumber() == MagicNumber) 
    {
      if ( iTime(Symbol(),0,0) >= OrderOpenTime()+SecondsClose ) 
      {
         if (OrderType() == OP_BUY)
         {
            OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),NormalizeDouble((Ask - Bid) * Point,Digits), DodgerBlue);
         }
      }
   }
}
 

Well, also, replace

for(int i=OrdersTotal();i>=0;i--) 

to

for(int i=OrdersTotal()-1;i>=0;i--) 


И еще, не понял, что за элемент в функции (подчеркнуто красным)?

OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),NormalizeDouble((Ask - Bid) * Point,Digits), DodgerBlue);

 
 for ( Expression_1; ; Expression_2) // No Condition { // Opening curly bracket Operator block, // The loop body may consist of ... making up the loop body //... of several operators } // Closing curly bracket

Can you tell me what is a condition to exit a loop like this? Or a loop like this

 For ( ; ; ) // Absent. Expression and Condition { // Opening curly bracket A block of operators, // A loop body can consist of // ... several operators making up the loop body } // Closing curly bracket
 
VladimirR:

Can you tell me what is the condition for exiting such a cycle? Or one of these


break
 

Vinin, Roger - thanks, it helped.

NormalizeDouble((Ask - Bid) * Point,Digits) is Slippage for symbols with large spreads, e.g. XAUUSD.

 
inoy:

Vinin, Roger - thanks, it helped.

NormalizeDouble((Ask - Bid) * Point,Digits) is Slippage for symbols with large spreads, e.g. XAUUSD.


So, can you imagine that it is 0? Firstly, the slippage should be a positive integer, secondly, the difference should be divided by Point, not multiplied.
 
Gentlemen, how to "train" an EA not to trade at night ? I.e. terminal time between 23 and 02 hours (GMT)... Hour()>=2&Hour()<=23 did not help...