Transfer the TP to the upper order

 

Hi

With this code

I want the expert to check the high purchase order. If the price of all the positions is positive, bring all the TPs to the high buy position.

But this must be done before the price reaches a high order position

But the code has a problem and it does not do that


//+------------------------------------------------------------------+
void BuyOrdersInfo1()
  {
   PriceOfHigherBuy=-99999;
   SumOfBuyOrders=0;
//---
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if((OrderSymbol()=="GBPUSD") && (OrderMagicNumber()==Magic3) && (OrderType()==OP_BUY))
           {
            SumOfBuyOrders++;
            PriceOfHigherBuy=MathMax(OrderOpenPrice(),PriceOfHigherBuy);
            }
        }
     }
  }
//+------------------------------------------------------------------+
void Trail()
{
for(int i=OrdersTotal()-1;i>=0;i--)
{
 OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
 
 if(OrderMagicNumber()==Magic3)
 BuyOrdersInfo1();
 {
 if((SumOfBuyOrders>0)&&((Ask-PriceOfHigherBuy>=Distance*Point)))
  {
   if(OrderTakeProfit()<(Ask-MathPow(10,-Digits)*PriceOfHigherBuy))
   
   {
   OrderModify(OrderTicket(),OrderOpenPrice(),Ask-MathPow(10,-Digits)*PriceOfHigherBuy,OrderTakeProfit(),0,Green);
    }
   }  
  }
   }
}
 
for(int i=OrdersTotal()-1;i>=0;i--)
{
 OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
 
 if(OrderMagicNumber()==Magic3)
 BuyOrdersInfo1();

{
  1. Your function call invalidates your OrderSelect. Call outside.
  2. Your function call is only part of the if magic. Everything else below the bracket is always called.
 
William Roeder:
  1. Your function call invalidates your OrderSelect. Call outside.
  2. Your function call is only part of the if magic. Everything else below the bracket is always called.

Hi Dear William,

Thank you for answering

I changed the code this way but still could not get the desired result

int start()
  {
BuyOrdersInfo1();
          return(0);
  }
//+------------------------------------------------------------------+
void BuyOrdersInfo1()
  {
   PriceOfHigherBuy=-99999;
   SumOfBuyOrders=0;
//---
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if((OrderSymbol()=="GBPUSD") && (OrderMagicNumber()==Magic3) && (OrderType()==OP_BUY))
           {
            SumOfBuyOrders++;
            PriceOfHigherBuy=MathMax(OrderOpenPrice(),PriceOfHigherBuy);
            {
               if(OrderTakeProfit()>(Bid-MathPow(10,-Digits)*PriceOfHigherBuy))
   {
   OrderModify(OrderTicket(),OrderOpenPrice(),Bid-MathPow(10,-Digits)*PriceOfHigherBuy,OrderTakeProfit(),0,Green);
             }
        }
        }
        }
     }
  }
//+------------------------------------------------------------------+


 
if(OrderTakeProfit()>(Bid-MathPow(10,-Digits)*PriceOfHigherBuy))
  1. MathPow(10-Digits) is the same as _Point.
  2. Point times a price is essentially zero, so you are comparing OTP to Bid which will always be true.
  3. Don't you want to move the OTP if it is less than the current high?
  4. You can't know the current high until you complete the loop.
 
William Roeder:
  1. MathPow(10-Digits) is the same as _Point.
  2. Point times a price is essentially zero, so you are comparing OTP to Bid which will always be true.
  3. Don't you want to move the OTP if it is less than the current high?
  4. You can't know the current high until you complete the loop.

Pay attention to the photo, we have 8 open positions. Before the price reaches it, the expert must find out in which of these positions all the positions (purchase) are in profit, then let him put all the TPs on the entry point of the same position.

Don't you want to move the OTP if it is less than the current high?

All profit margins must be equal at the entry point of one of the top positions, provided that the sum of all positions is in profit.

Thanks,

 
ghobar:

Hi

With this code

I want the expert to check the high purchase order. If the price of all the positions is positive, bring all the TPs to the high buy position.

But this must be done before the price reaches a high order position

But the code has a problem and it does not do that


//+------------------------------------------------------------------+
void BuyOrdersInfo1()
  {
   PriceOfHigherBuy=-99999;
   SumOfBuyOrders=0;
//---
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if((OrderSymbol()=="GBPUSD") && (OrderMagicNumber()==Magic3) && (OrderType()==OP_BUY))
           {
            SumOfBuyOrders++;
            PriceOfHigherBuy=MathMax(OrderOpenPrice(),PriceOfHigherBuy);
            }
        }
     }
  }

Hello dear
This Function  returns the highest (not higher) price of buy orders(open price of 8th order). Is that what you want?

 
Salih Yasar:

Hello dear
This Function  returns the highest (not higher) price of buy orders(open price of 8th order). Is that what you want?

Hello
Thank you for your help
I want, for example, when positions 3 or 4 or later are opened, the TP of all positions should be at the entry point of one of the top positions.
Transfer the TP of all positions to the entry point of one of the higher positions provided that our total profit is in profit
 
ghobar:

Have you noticed that if you transfer TP to the last open price order, it means closing all active positions? (Although this is impossible because in BUY orders the TP must be higher than the current price)

 
Salih Yasar:

Have you noticed that if you transfer TP to the last open price order, it means closing all active positions? (Although this is impossible because in BUY orders the TP must be higher than the current price)

Hi dear Salih,
Yes, I mean this
I want to put all the TPs in the price of one of the high open positions
Or position number 3 or 4 or 5 or 6 or 8
Provided that the sum of all positions is either overhead or the sum of all positions is in profit
 
Salih Yasar:

Have you noticed that if you transfer TP to the last open price order, it means closing all active positions? (Although this is impossible because in BUY orders the TP must be higher than the current price)

What I want is perfectly stated in this photo

I hope you understand what I mean and help solve this problem

Thanks.

 
ghobar:

What I want is perfectly stated in this photo

I hope you understand what I mean and help solve this problem

Thanks.

Or



In this photo, we considered the buy position.