MQL5 How can I calculate Profit??

 
Hello

Imagine that you do not want to lose much in a position and you program that limit to an Expert, so that, when a position reaches or exceeds that negative value, the position is closed.

The problem is: if the Expert Advisor opens a position whose Profit is already below that limit, it will immediately close the position, causing a loss. In addition to this, if the expert has no limitations, he would repeat the action until the account was cleaned or would stop when he could not provide the Profit of the next position to be opened.

Therefore, I want to know if you can calculate the Profit of a position before opening it.

I've done some research and I can't find a good way to do it, and I'm asking for help.

Print( "    Ask: ", YSymbol.Ask( ) );
Print( "    Bid: ", YSymbol.Bid( ) );
Print( " Profit: ", YPosition.Profit( ) );
Print( " Spread: ", ( YSymbol.Spread( ) * YSymbol.Point( ) ) );
Print( "Missing: ", ( -1 * YPosition.Profit( ) - YSymbol.Spread( ) * YSymbol.Point( ) ) );

Use the code above to display the following values

    Ask: 107.218
    Bid: 107.117
 Profit: -0.95
 Spread: 0.101
Missing: 0.849

ProfitLim: -0.5
     Lote: 0.01
   Symbol: USDJPY

I'll appreciate any help with that.







 
26472924:
Hello

Imagine that you do not want to lose much in a position and you program that limit to an Expert, so that, when a position reaches or exceeds that negative value, the position is closed.

The problem is: if the Expert Advisor opens a position whose Profit is already below that limit, it will immediately close the position, causing a loss. In addition to this, if the expert has no limitations, he would repeat the action until the account was cleaned or would stop when he could not provide the Profit of the next position to be opened.

Therefore, I want to know if you can calculate the Profit of a position before opening it.

I've done some research and I can't find a good way to do it, and I'm asking for help.

Use the code above to display the following values

I'll appreciate any help with that.







I'm not sure whether I understand your question correctly. My understanding is that you are concerned about open positions which already exists before you start the EA?

If so, you would need to write code in the OnInit() function that evaluates all open positions and look at the current profit/loss of each position. Then you would need to set an allowable loss for each of these orders. This "allowable loss" could then be different for these already open positions compared to positions you will open from now on in OnTick().

 
You didn't understand.
I need to calculate the Profit before open the position.
 
26472924:
You didn't understand.
I need to calculate the Profit before open the position.

then perhaps you need to calculate the lot size of the position based on a fixed amount you are accepting to lose - i think you can use something like   lot = (amount)/(SLdistanceInPoints*tickValue) , and then normalize the value

 
I like your idea, but I don't have the equation.

If you read the first post, you'll see the data I'm using to make the calculations.

YSymbol.TickValue: 0.9329402545061014
Please give me an example.

I mean, in case that helps.
 
26472924:
You didn't understand.
I need to calculate the Profit before open the position.
You can only calculate the profit before opening the position if you can predict the future.
 

try using this equation

 
I think he's talking about the cost of the spread. It sounds confusing because he's saying "calculate profit before buying" but based on the numbers given in his example that's what I think he means. So he can avoid opening a position if the spread is too large.