Only one order is changing TakeProfit

 
int OnInit()
  {
//---
      UpdateTPbBUY();
 
   
//---
   return(INIT_SUCCEEDED);
  }
////////////////////////////////////////////////////////////////////////////
double LotsxPriceBuy()
{
double LotsxPriceBuy=0;

for(int i=OrdersTotal()-1;i>= 0 ;i--)
{
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
       {
         if(OrderSymbol()==Symbol() && OrderType() == OP_BUY)
         {
           LotsxPriceBuy += OrderLots() * OrderOpenPrice();
         }
         
       }
   
}
return (LotsxPriceBuy);
}

//total lots
///////////////////////////////////////////////////////////////////////
double TotalLotsBuy()
{
double TotalLots=0;
for(int i=OrdersTotal()-1;i>= 0 ;i--)
{
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
       {
         if(OrderSymbol()==Symbol() && OrderType() == OP_BUY)
         {
           TotalLots += OrderLots();
           
         }
         
       }
   
}
return (TotalLots);
}
/////////////////////////////////////////////////////
void UpdateTPbBUY()
{
for(int i=OrdersTotal()-1;i>= 0 ;i--)
{
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
       {
         if(OrderSymbol()==Symbol() && OrderType() == OP_BUY)
         {
          
            OrderModify(OrderTicket(), OrderOpenPrice(),0,NetMeanOpeningPriceBuy(),0,0);
            
         } 
       }
}
}
/////////////////////////////////////////////////////////
double NetMeanOpeningPriceBuy()
{
double NetMeanOpeningPriceBuy = 0;

      NetMeanOpeningPriceBuy =((LotsxPriceBuy()/TotalLotsBuy())+entryPipDistance);
   
      return (NetMeanOpeningPriceBuy);
      
}
///////////////////////////////////////////////////////////
hi guys im new in coding MQL4 and I have made an EA, but my problem is I have a function named "UpdateTPBuy". This function purpose is to change all take profit of my buy order to the NetMeanOpeningPrice the problem is every time it run it only changes 1of my buy orders. can you check on my code? thank you so much :)
 
mark692:
hi guys im new in coding MQL4 and I have made an EA, but my problem is I have a function named "UpdateTPBuy". This function purpose is to change all take profit of my buy order to the NetMeanOpeningPrice the problem is every time it run it only changes 1of my buy orders. can you check on my code? thank you so much :)

It can be helpful if you add this code and write the result from the expert tab here.


 void UpdateTPbBUY()
{
for(int i=OrdersTotal()-1;i>= 0 ;i--)
{
   if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
       {
         if(OrderSymbol()==Symbol() && OrderType() == OP_BUY)
         {
          
          result abd=   OrderModify(OrderTicket(), OrderOpenPrice(),0,NetMeanOpeningPriceBuy(),0,0);
          Print(" TP :"+NetMeanOpeningPriceBuy()+" Error Codes "+GetLastError());
            
         } 
       }
}
 
Mehmet Bastem:

It can be helpful if you add this code and write the result from the expert tab here.


Thank you sir for your response. On the Experts tab this error appear "2021.07.09 14:22:40.881 TestEa EURUSD,H1: Error in OrderModify. Error code=1"

i think i solved it i put this "double BEbuy=NetMeanOpeningPriceBuy();" above for loop. but ill test it again. thanks :)

"
 
mark692:

Thank you sir for your response. On the Experts tab this error appear "2021.07.09 14:22:40.881 TestEa EURUSD,H1: Error in OrderModify. Error code=1"

i think i solved it i put this "double BEbuy=NetMeanOpeningPriceBuy();" above for loop. but ill test it again. thanks :)

"

when using OrderModify

for example if you want change take profit

if the value of entered takeprofit be same and repeated...you will receive error 1

Reason: