Transfer the TP to the upper order - page 3

 
ghobar: A friend of mine said that your problem can only be solved by using Arrays. I will try to do more research on this.

No, you don't need arrays. The solution has already been given to you, but you have failed to apply it properly.

I repeat, read it again and don't say that the "professors" did not understand you. They understood your request just fine.

 
Fernando Carreiro:

No, you don't need arrays. The solution has already been given to you, but you have failed to apply it properly.

I repeat, read it again and don't say that the "professors" did not understand you. They understood your request just fine.

Thank you very much from all the friends (and Professors) who help me in this direction
I will examine what you said
Your tips, dear ones, are valuable to me
Global thanks.
 
ghobar:
Thank you very much from all the friends (and Professors) who help me in this direction
I will examine what you said
Your tips, dear ones, are valuable to me
Global thanks.

I edited the code a bit again

But now it returns the same amount of profit related to the same order

//+------------------------------------------------------------------+
void FindTP() 
 {
 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);

 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(OrderTicket(),OrderOpenPrice(),Bid-OrderStopLoss(),OrderTakeProfit(),0,Green);   
              }
           }
        }
     }
      }
      
       
//+------------------------------------------------------------------+


 
ghobar:

I edited the code a bit again

But now it returns the same amount of profit related to the same order



if(OrderTakeProfit() > TP || TP == 0)

Remove the OR comparision.

TP variable already is Zero, and having that OR inside the while does not make sense.


Change to this: 

if(OrderTakeProfit() > TP)



On the second While, change this:

if(OrderTakeProfit() != TP)


to this:

if(OrderTakeProfit() < TP)


And you are passing the SAME TP value to Order itself.


This has to be:


if(OrderTakeProfit() < TP)
              {
                OrderModify(OrderTicket(),OrderOpenPrice(),Bid-OrderStopLoss(),TP,0,Green);   
              }



The rest seems fine.


PS: for SELL orders, invert the logic:

if(OrderTakeProfit() > TP)



UPDATE: Why are you changing the StopLoss too? I can notice on the picture spreadsheet that SL is a complete mess. 

You are changing it doing sequencia loops. Every time the while is run, it will subtract the BID value from the current StopLoss value.. on the next run, it will subtract again... and again..

This is wrong.. the SL Value will become negative at some point. 


Dont change SL, if you want to adjust just the TP value. 


Here are both correction, to the second While:

if(OrderTakeProfit() < TP)
              {
                OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TP,0,Green);   
              }
 
rrocchi:


Remove the OR comparision.

TP variable already is Zero, and having that OR inside the while does not make sense.


Change to this: 



On the second While, change this:


to this:


And you are passing the SAME TP value to Order itself.


This has to be:




The rest seems fine.


PS: for SELL orders, invert the logic:



UPDATE: Why are you changing the StopLoss too? I can notice on the picture spreadsheet that SL is a complete mess. 

You are changing it doing sequencia loops. Every time the while is run, it will subtract the BID value from the current StopLoss value.. on the next run, it will subtract again... and again..

This is wrong.. the SL Value will become negative at some point. 


Dont change SL, if you want to adjust just the TP value. 


Here are both correction, to the second While:

Hello and thank you

I edited the points you said like this

But still I could not get the result


//+------------------------------------------------------------------+
void FindTP() 
 {
 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 = OrderTakeProfit();    
              }
           }
           
        }
     }
Print("TP:",(string)TP);

 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(OrderTicket(),OrderOpenPrice(),Bid-OrderStopLoss(),TP,0,Green);  
              }
           }
        }
     }
      }
      
       



 
ghobar:

Hello and thank you

I edited the points you said like this

But still I could not get the result




Please take a look carefully on my previous answer. You are still making a mistake that I pointed out.

Do not change the SL to random calculated values (explanation is detailed on my previous answer)


Please change:

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-OrderStopLoss(),TP,0,Green);  


to:

OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TP,0,Green);  
 
ghobar:  I edited the points you said like this.  But still I could not get the result

This is getting ridiculous. You keep just showing parts of your code but never how you are calling it or implementing it.

Let's just stop beating around the bush! Just attach your entire code file, so that we can properly compile it, test it and show you what you are doing wrong.

 
rrocchi:

Please take a look carefully on my previous answer. You are still making a mistake that I pointed out.

Do not change the SL to random calculated values (explanation is detailed on my previous answer)


Please change:


to:

Hello dear Rrocchi,

I changed it according to your orders, but the profit limit still does not change

Like the previous photo I sent you, there was no change

Thank you for your follow-up and guidance, dear friend.

 

 Here is my solution to the problem. It's easier for me to just write the program than to fix a program from a newbie!

This EA will accept manual entry of multiple Orders or the EA can Auto enter multiple Pending Orders at Fixed, but adjustable, distances apart, if selected in the settings.

Since no Order will close until the Highest Order TP has been reached, I have just programmed it to take the TP from the Highest Order and Modify the TP of all other

Orders to match; so they will all close when that TP is reached. While StopLoss can be Enabled or Disabled; it does need to have a "Break Even" and a "Trailing Stop"; in the evnt the TP

of the Highest Order is not reached. It has only be tested in Strategy Tester; as the Market was closed when I finished!


Charlie Bear!

Files:
Ghobar.mq4  12 kb
 
CHARLESS11:

 Here is my solution to the problem. It's easier for me to just write the program than to fix a program from a newbie!

This EA will accept manual entry of multiple Orders or the EA can Auto enter multiple Pending Orders at Fixed, but adjustable, distances apart, if selected in the settings.

Since no Order will close until the Highest Order TP has been reached, I have just programmed it to take the TP from the Highest Order and Modify the TP of all other

Orders to match; so they will all close when that TP is reached. While StopLoss can be Enabled or Disabled; it does need to have a "Break Even" and a "Trailing Stop"; in the evnt the TP

of the Highest Order is not reached. It has only be tested in Strategy Tester; as the Market was closed when I finished!


Charlie Bear!

Thanks dear Charlis.
Reason: