Transfer the TP to the upper order - page 3

Fernando Carreiro
7036
Fernando Carreiro  
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.

ghobar
158
ghobar  
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
158
ghobar  
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);   
              }
           }
        }
     }
      }
      
       
//+------------------------------------------------------------------+


rrocchi
367
rrocchi  
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);   
              }
ghobar
158
ghobar  
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);  
              }
           }
        }
     }
      }
      
       



rrocchi
367
rrocchi  
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);  
Fernando Carreiro
7036
Fernando Carreiro  
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.

ghobar
158
ghobar  
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.