Transfer the TP to the upper order - page 2

 
 double TP = 0;  

 for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if((OrderSymbol()=="GBPUSD") && (OrderMagicNumber()==Magic3) && (OrderType()==OP_BUY))
           {
            if(OrderTakeProfit() > TP || TP == 0)
              {
                TP = OrderTakeProfit();    
              }
           }
        }
     }
Print("TP:",(string)TP);

First you get the highest TP == GET

Then you adjust all others TP == SET

 for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if((OrderSymbol()=="GBPUSD") && (OrderMagicNumber()==Magic3) && (OrderType()==OP_BUY))
           {
            if(OrderTakeProfit() != TP)
              {
                OrderModify(.....    
              }
           }
        }
     }

Untested Pseudocode.

You may have to add some additional checks

 
Marco vd Heijden:

First you get the highest TP == GET

Then you adjust all others TP == SET

Untested Pseudocode.

You may have to add some additional checks

Hello

Thank you for sharing your experiences

I edited the code this way But I still could not transfer the profit margin of all positions to the upper order

Where is my code wrong?

int start()
  {
          Trail();
          return(0);
  }
//+------------------------------------------------------------------+
double FindTP() 
 {
  double TP=0;
  double unused=0;
  bool rest;
  for (int i=0; i<=OrdersTotal(); i++)
  {
  rest=OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
  unused=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
  if(OrderSymbol()!="GBPUSD" || OrderMagicNumber()!=Magic3) continue;
  if(OrderSymbol()=="GBPUSD" && OrderMagicNumber()==Magic3 && OrderType()==OP_SELL) 
  {
  if(OrderTakeProfit() > TP || TP == 0)
  {
  TP = OrderTakeProfit(); 
  }
  }         
  }
  return (TP);
 }
 
//+------------------------------------------------------------------+
void Trail()
{

   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if((OrderSymbol()=="GBPUSD") && (OrderMagicNumber()==Magic3) && (OrderType()==OP_BUY))
           {
            if(OrderTakeProfit() != FindTP())
         {
   OrderModify(OrderTicket(),OrderOpenPrice(),Ask-FindTP(),OrderTakeProfit(),0,Green);
             }
        
        }
        }
     }
  }

 
ghobar:

Hello

Thank you for sharing your experiences

I edited the code this way But I still could not transfer the profit margin of all positions to the upper order

Where is my code wrong?


I think you are approaching your goal the wrong way. I think what you ultimately want is that whene the sum of all open orders reaches a certain "Total Profit" close all orders. 

By modifying "all lower entry price order's TP" to the highest order entry price, all lower orders would immediately close once the price increased to cover the spread. Or if you modified to same TP as the highest order they would all close at that TP. However, with an EA, you need to tell it how many orders you want to have before it begins modifying all orders. The EA also needs to know if you are changing Buy or Sell orders or both. This is why I think, you are really looking to sum all orders, and close them all whene a certain Profit Total is reached! Let me know what you think! And No, I did not say all of this to leave you hanging! Just want to make sure I fully undestand what you need before I spend my time writing you some code. 
 
CHARLESS11:
I think you are approaching your goal the wrong way. I think what you ultimately want is that whene the sum of all open orders reaches a certain "Total Profit" close all orders. 

By modifying "all lower entry price order's TP" to the highest order entry price, all lower orders would immediately close once the price increased to cover the spread. Or if you modified to same TP as the highest order they would all close at that TP. However, with an EA, you need to tell it how many orders you want to have before it begins modifying all orders. The EA also needs to know if you are changing Buy or Sell orders or both. This is why I think, you are really looking to sum all orders, and close them all whene a certain Profit Total is reached! Let me know what you think! And No, I did not say all of this to leave you hanging! Just want to make sure I fully undestand what you need before I spend my time writing you some code. 

Hi Dear Charless,

Thank you and all the friends for your sincere cooperation

In this description, all the examples are about buy positions

Yes, I want to close all orders when the sum of all open orders (buy separately and sell separately) reaches a certain "total profit".

Provided that it is equal to the opening price of one of the high positions

But the new thing I want to do is before the price reaches the total profit

Expert examines which of the above open positions in the opening price of all our purchase orders will reach the total profit

Regarding the number of orders opened, I must say that this is unlimited, but this code must do these calculations from position number 2 onwards.

Note the opposite. Before the price reached the order number 2, we calculated that if the price reaches the order number 2, our total profit will reach +$50.

So before the price reaches the order number 2, we must transfer our TP to the order number 2.

I hope my explanation was complete

Thanks for your friendly follow up.


 
My questions were very difficult for me
I wrote every code that came to my mind and used the guidance of friends.
But the problem is not solved, can you give more help?
 
Marco vd Heijden:

First you get the highest TP == GET

Then you adjust all others TP == SET

Untested Pseudocode.

You may have to add some additional checks

Hi,

I have to remind you that all expert orders are without TP

Thanks.

 

You have sent me PM’s twice now, asking that I help out on your thread. This is what I have to say:

On this your thread you have received help from @William Roeder, @Salih Yasar, @Marco vd Heijden and @CHARLESS1.

Most of them have given you code samples to help you out. However, instead of using their code “as is” to solve the problem, you have altered their code your own way, rendering it useless and making it fail.

@Marco vd Heijden gave you the most complete code sample for a full solution, yet you still messed it up.

You have demonstrated that you do not understand their code and do not know how to use the guidance that was given to you.

How do you expect anyone to help you further, if you cannot understand what is explained to you nor apply the code properly?

I suggest you re-read everything that was explained here, from the beginning, making sure you understand every bit of it by looking up the reference documentation, and then apply it in your code properly this time.

 
Fernando Carreiro:

You have sent me PM’s twice now, asking that I help out on your thread. This is what I have to say:

On this your thread you have received help from @William Roeder, @Salih Yasar, @Marco vd Heijden and @CHARLESS1.

Most of them have given you code samples to help you out. However, instead of using their code “as is” to solve the problem, you have altered their code your own way, rendering it useless and making it fail.

@Marco vd Heijden gave you the most complete code sample for a full solution, yet you still messed it up.

You have demonstrated that you do not understand their code and do not know how to use the guidance that was given to you.

How do you expect anyone to help you further, if you cannot understand what is explained to you nor apply the code properly?

I suggest you re-read everything that was explained here, from the beginning, making sure you understand every bit of it by looking up the reference documentation, and then apply it in your code properly this time.

Greetings and Regards

Thank you for your answer, Mr. Fernando,

I sent this message to all my friends to share if possible (one of which was sent to you)

Regarding the subject that you mentioned, I have to say that I think the professors who did not understand the subject correctly (or I did not state it correctly).

I want this TP transfer to take place before the price reaches the desired order

And all the orders of this expert are without TP or SL

We should look for a high order opening price, not a TP (if I'm not mistaken)

Additional explanation is available in the previous photo I sent.

I will examine the explanations that you said.

With full thanks and respect.

 
ghobar:


If the price of all the positions is positive, bring all the TPs to the high buy position.



You told you want to modify the TP.  

But you are passing the new value to the SL field !?


if(OrderTakeProfit()>(Bid-MathPow(10,-Digits)*PriceOfHigherBuy))
   {
   OrderModify(OrderTicket(),OrderOpenPrice(),Bid-MathPow(10,-Digits)*PriceOfHigherBuy,OrderTakeProfit(),0,Green)
}



Parameters are, respectively: "Ticket" , "OpenPrice", "SL Value", "TP Value", 0, Green


Have you tried this?

OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid-MathPow(10,-Digits)*PriceOfHigherBuy,0,Green)
 
rrocchi:


You told you want to modify the TP.  

But you are passing the new value to the SL field !?



Parameters are, respectively: "Ticket" , "OpenPrice", "SL Value", "TP Value", 0, Green


Have you tried this?

Thank you very much for your help in solving the problem

Yes, I tried this

But still the problem still shifts

A friend of mine said that your problem can only be solved by using 

Array

. I will try to do more research on this.

Reason: