In the Mql5 language, I need a function(I called it: Profit_To_Price) with two input parameters where the first parameter is the position ticket and the second parameter is a real number (double ExpectedProfit) as profit or loss and the output of this function is a real number (double TargetPrice) which if the currency price reaches that number and exits the transaction at the same point, then this position will profit (or lose) exactly as much as the value of ExpectedProfit. Are there built-in functions for this in mql5?
In other words, from a mathematical point of view, I need the inverse of the OrderCalcProfit function. This function gets the price of a given order and returns the exact profit/loss amount, but I want the opposite. That is, I want to give the profit/loss amount as input parameter and get the exact price.
Thank you in advance for answering this question.
int OnInit()
{
//We assume that there is an open position with 123456 ticket number.
Print("If you want this position to make you $100 profit, the price must reach the TargetPrice=", Profit_To_Price(123456, 100.0));
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
}
double Profit_To_Price(ulong PositionTicket, double ExpectedProfit)
{
double TargetPrice = -1.0;
//how can i calculate TargetPrice?
//...
return TargetPrice;
}