Take profit MQL 4

 

Hi, If i want to modify a take profit, I've tried this but it doesn't work.

res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), TP-OrderOpenPrice(), 0, CLR_NONE);

//where a Value is - from the open price. 

 

A TP/SL is a price. TP-OrderOpenPrice() is not a price. Always post all relevant code. What is TP?

 
William Roeder #:

A TP/SL is a price. TP-OrderOpenPrice() is not a price. Always post all relevant code. What is TP?

Thanks William, TP is also a Price Value. 

So, (Price Value - OrderOpenPrice()); the issue is the Price Value is larger then the OrderOpenPrice(), and so, if you were to Calculate a Take Profit value with (OrderOpenPrice()- Price Value ) the TakeProfit value would be negative on a BUY order. When you rearrange the equation as (Price Value - OrderOpenPrice()), MQL4 doesn't let you minus Price Value from OrderOpenPrice(). 


What do you mean OrderOpenPrice is not a Price? how would i get the same value for the equation above?


I've tried; 

double OpenPrice =  OrderOpenPrice();

then inputing; 

(PriceValue - OpenPrice)

But that hasn't worked. 

 
Hey, try to normalise your double. 
 
  1. Take profit is a price. TP is a price. Set your take profit to TP.
  2. I did not say OrderOpenPrice() is not a price. I said TP-OrderOpenPrice() is not a price.
 
Here is your TP the upper price when Buy or in pips? If your TP is upper price then if you deduct your open price from TP then you get pips in points like 0.00245 this. If your TP is pips then after deduct you'll get negative value. This function need your new TP value exactly similar as symbol price. 
 
Adj007 #:
Hey, try to normalise your double. 

Thanks Adj007, i've tried; 

 double OP = OrderOpenPrice();
         NormalizeDouble(OP,3); 
              {
               res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OP-TP, 0, CLR_NONE);
              }

From my research, NormalizedDouble is only adjusting digits after the decimal point. This hasn't worked either. 

 
William Roeder #:
  1. Take profit is a price. TP is a price. Set your take profit to TP.
  2. I did not say OrderOpenPrice() is not a price. I said TP-OrderOpenPrice() is not a price.

Yeah, TP is also a Price Value. So, PriceValue-OpenPriceValue will give the points from the open price to the Take profit. And so the equitation is being implemented in doubletakeprofit.


So, how would I find that same value of PriceValue-OpenPriceValue?

 
Sanjay Rathore #: Yeah, TP is also a Price Value. So, PriceValue-OpenPriceValue will give the points from the open price to the Take profit. And so the equitation is being implemented in doubletakeprofit. So, how would I find that same value of PriceValue-OpenPriceValue?

No, you have not been paying attention! Everyone has been telling you that OrderModify() only accepts a "price" for a TakeProfit, not a "price difference".

For example, if your open price is 1.2345 and your take profit is 1.2398, then use OrderModify( OrderTicket(), OrderOpenPrice(), OrderStopLoss(), 1.2398, 0, CLR_NONE )

Don't use OrderModify( OrderTicket(), OrderOpenPrice(), OrderStopLoss(), 1.2345 - 1.2398, 0, CLR_NONE )

 
Fernando Carreiro #:

No, you have not been paying attention! Everyone has been telling you that OrderModify() only accepts a "price" for a TakeProfit, not a "price difference".

For example, if your open price is 1.2345 and your take profit is 1.2398, then use OrderModify( OrderTicket(), OrderOpenPrice(), OrderStopLoss(), 1.2398, 0, CLR_NONE )

Don't use OrderModify( OrderTicket(), OrderOpenPrice(), OrderStopLoss(), 1.2345 - 1.2398, 0, CLR_NONE )

So, if i put in the equation;


 {
  res=OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), (TP-OrderOpenPrice())+OrderOpenPrice(), 0, CLR_NONE);
 }

this will find a price; (TP-OrderOpenPrice())+OrderOpenPrice() but this doesn't work either?

 
Sanjay Rathore #:

Thanks Adj007, i've tried; 

From my research, NormalizedDouble is only adjusting digits after the decimal point. This hasn't worked either. 

You normalise the double using that equation. That equation you’ve put returns more than 5 digits. You need to fill a separate variable with that equation and then use normalise. 
Reason: