[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 165

 
Where is the fault ')' hiding here? - wrong parameters count 4 times? Maybe this is not the way to write it?
//-----------------------------------------------------------------------------+ 
//  Удаление объекта OBJ_HLINE горизонтальная линия  /Blue/Red          |  
//-----------------------------------------------------------------------------+   
 void DelHLine(color cl, string nm="", double p1=0, int st=0, int wd=1)  
  { 
     int    obj_total= ObjectsTotal(OBJ_HLINE); 
   
  for(int i=0;i<obj_total;i++) 
   {
     if(ObjectType(OBJ_HLINE)==true) 
     {
        if(ObjectGet(OBJPROP_COLOR)==Red)
         { 
           if(ObjectGet(OBJPROP_PRICE1)>Ask) ObjectDelete(FrDnNam);
         } 
     }
  }
    
    for(i=0;i<obj_total;i++) 
       {
         if(ObjectType(OBJ_HLINE)==true)
         {
          if(ObjectGet(OBJPROP_COLOR)==Blue) 
         { 
          if(ObjectGet(OBJPROP_PRICE1)<Bid) ObjectDelete(FrApNam); 
       }
       
    } 
   }

    return; 
  }
 
Check ObjectGet(), there must be two parameters.
 
Roger:

Use the NormalizeDouble(lot,2) function

Thank you. I suspect that's what I was looking for.

splxgf:

Thanks for the discussion. Your information will come in handy as well.

 
Operr:
Where is the fault ')' hiding here? - wrong parameters count 4 times? Maybe this is not how it should be written?
ObjectType() and ObjectGet() functions are missing object names
 
Operr:
Where is the fault ')' hiding here? - wrong parameters count 4 times? Maybe this is not the way to write it?

//------------------------------------------------------------+ 
//  Удаление объекта OBJ_HLINE горизонтальная линия  /Blue/Red|  
//------------------------------------------------------------+   
void DelHLine(string nm="")  
{int obj_total=ObjectsTotal();
  for(int i=0;i<obj_total;i++) 
  {if(nm==ObjectName(i)&&ObjectType(nm)==OBJ_HLINE)
   {color cl=ObjectGet(nm,OBJPROP_COLOR);double pr=ObjectGet(nm,OBJPROP_PRICE1);
    if((cl==Red&&pr>Ask)||(cl==Blue&&pr<Bid))ObjectDelete(nm);}}}
 
Could you please advise me, is it possible to force an update of the build in MT4? It doesn't update when I restart the terminal.
 

Gentlemen professionals, I need your help again!

Below is a snippet of code responsible for closing trades, but the thing is that when pending orders are not executed it does not delete them, I can't figure out why. But when I need to close a pending order that has already been executed, everything goes correctly and if the order hasn't been executed then it just hangs there until it executes...

OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
Magic = OrderMagicNumber();
orderticket = OrderTicket();

if (OrdersTotal() == 1 && Magic == 111 && OrderType( ) == 0)
{
if (H1_BUY_5 == 0 || H1_BUY_1 == 0)
{
OrderClose(orderticket, lots, Bid, 5, Yellow);
if (OrdersTotal() == 1) OrderDelete(orderticket, Brown);
}

}

 

Xaoss1990:

Below is a snippet of code responsible for closing trades, but the thing is that when pending orders are not executed it doesn't delete them, I can't understand why.


if (OrdersTotal() == 1 && Magic == 111 && OrderType( ) == 0)


this interferes
 

I put a function in my EA to close 1/3 of open lot when stoploss is triggered at breakeven, but for some reason it doesn't work.

Can you tell me what's wrong?

//=======================================================================================     
void BuyCloseOneThird(string sy="", int op=-1, int mn=-1) {
  double pr=0;
  int    i, k=OrdersTotal(), np=-1;

  if (sy=="0") sy=Symbol();
  for (i=k-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && OrderType()==OP_BUY) {
        if (mn<0 || OrderMagicNumber()==mn) {
          if (Bid>OrderOpenPrice() && Bid==OrderStopLoss()) {
    if (OrderSelect(np, SELECT_BY_POS, MODE_TRADES)) {
      ClosePosBySelect();}
    }
  }
}
}
}
}
//=======================================================================================     
void SellCloseOneThird(string sy="", int op=-1, int mn=-1) {
  double pr=0;
  int    i, k=OrdersTotal(), np=-1;

  if (sy=="0") sy=Symbol();
  for (i=k-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && OrderType()==OP_BUY) {
        if (mn<0 || OrderMagicNumber()==mn) {
          if (Ask<OrderOpenPrice() && Ask==OrderStopLoss()) {
    if (OrderSelect(np, SELECT_BY_POS, MODE_TRADES)) {
      ClosePosBySelect();}
    }
  }
}
}
}
}

//+------------------------------------------------------------------+
void ClosePosBySelect() {
  bool   fc;
  color  clClose;
  double pa, pb, pp;
  int    err, it;
double ll = MathCeil(OrderLots() / 3.0 * 10.0) / 10.0;

  if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
    for (it=1; it<=5; it++) {
      if (!IsTesting() && (!IsExpertEnabled() || IsStopped())) break;
      while (!IsTradeAllowed()) Sleep(5000);
      RefreshRates();
      pa=MarketInfo(OrderSymbol(), MODE_ASK);
      pb=MarketInfo(OrderSymbol(), MODE_BID);
      if (OrderType()==OP_BUY) {
        pp=pb; clClose=Red;
      } else {
        pp=pa; clClose=Blue;
      }
      ll=OrderLots();
      fc=OrderClose(OrderTicket(), ll, pp, Slippage, clClose);
      if (fc) {
        PlaySound("wave"); break;
      } else {
        err=GetLastError();
        if (err==146) while (IsTradeContextBusy()) Sleep(1000*11);
        Print(OrderTicket(),"  Ask=",pa,"  Bid=",pb,"  pp=",pp);
        Print("sy=",OrderSymbol(),"  ll=",ll,"  sl=",OrderStopLoss(),
              "  tp=",OrderTakeProfit(),"  mn=",OrderMagicNumber());
        Sleep(1000*5);
      }
    }
  } 
}
 
Sancho77:

I put a function in my EA to close 1/3 of open lot when stoploss is triggered at breakeven, but for some reason it doesn't work.

Can you tell me what's wrong?


Probably because you calculate the lot first and then

ll=OrderLots();
fc=OrderClose(OrderTicket(), ll, pp, Slippage, clClose);
Reason: