calculate exact costs of a market move

 

Hello,

many posts here are about this problem. However, it seems this is not solved and the desk did not answer for this so far or in russian language.

The Problem: i do a trade , entry at price p1 and exit at price p2. MetaTrader  shows the profit for this trade.

I like to calculate this profit with MQL5 methods, exactly this profit, so profit in account currency.

How to do this, given i have

a) symbol 

b) p1

c) p2

d) volume

 

Thank you 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Account Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Account Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Account Properties - Documentation on MQL5
 
chinaski:

Hello,

many posts here are about this problem. However, it seems this is not solved and the desk did not answer for this so far or in russian language.

The Problem: i do a trade , entry at price p1 and exit at price p2. MetaTrader  shows the profit for this trade.

I like to calculate this profit with MQL5 methods, exactly this profit, so profit in account currency.

How to do this, given i have

a) symbol 

b) p1

c) p2

d) volume

 

Thank you 

How is this related to an answer from Service Desk ?
 
ssn:
For the attached class, PriceDelta would be difference btn p1 an p2. The profit returned is for one lot, so multiply it by you volume to get the loss or profit for your volume.

The method used is uselessly overcomplicated.

You don't have to convert yourself to account currency, simply use SYMBOL_TRADE_TICK_VALUE in your formula.
 
angevoyageur:

The method used is uselessly overcomplicated.

You don't have to convert yourself to account currency, simply use SYMBOL_TRADE_TICK_VALUE in your formula.
Obviously you and I come from different backgrounds...
 
angevoyageur:

The method used is uselessly overcomplicated.

You don't have to convert yourself to account currency, simply use SYMBOL_TRADE_TICK_VALUE in your formula.
There was a time when SYMBOL_TRADE_TICK_VALUE was buggy... If it works ok now, that's fine...
 
ssn:
There was a time when SYMBOL_TRADE_TICK_VALUE was buggy... If it works ok now, that's fine...

If it's buggy, then ask the correction of the bug.

Why did you remove your post ?

Get in touch with developers using Service Desk!
Get in touch with developers using Service Desk!
  • www.mql5.com
We therefore attach great importance to all user reports about issues in our programs and try to answer each one of them.
 
Sorry I removed the code, chinaski can PM me for it or use SYMBOL_TRADE_TICK_VALUE
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
 
angevoyageur:

If it's buggy, then ask the correction of the bug.

Why did you remove your post ?

It should not have been made available free in the first place. My err in judgement. Sorry.
 
ssn:
It should not have been made available free in the first place. My err in judgement. Sorry.
Ok, no problem.
 

Hello guys,

thank you for replies gentlemen.

Can one of you give a simple formular for my problem ? So other users, having the same problem can just copy this formular. 

I know about SYMBOL_TRADE_TICK_VALUE but it simply not works. When i evaluate a trade report about fill price of a position

opened and price when position closed and resulting profit i can't calculate this profit using SYMBOL_TRADE_TICK_VALUE.

Of course in my tests no other symbols were opened at this time.

If you can calculate exaclty the profit, please just post your formular here and this problem should be solved for all times.

Thank you. 

 

formular input 

a) symbol 

b) p1

c) p2

d) volume 

 

output: costs in account currency.

 

(I mentioned the desk because i posted my question there along with detailed sample, screenshots, my code for this

and got no really helpful answer. )

 
chinaski:

Hello guys,

thank you for replies gentlemen.

Can one of you give a simple formular for my problem ? So other users, having the same problem can just copy this formular. 

I know about SYMBOL_TRADE_TICK_VALUE but it simply not works. When i evaluate a trade report about fill price of a position

opened and price when position closed and resulting profit i can't calculate this profit using SYMBOL_TRADE_TICK_VALUE.

Of course in my tests no other symbols were opened at this time.

If you can calculate exaclty the profit, please just post your formular here and this problem should be solved for all times.

Thank you. 

 

formular input 

a) symbol 

b) p1

c) p2

d) volume 

 

output: costs in account currency.

 

(I mentioned the desk because i posted my question there along with detailed sample, screenshots, my code for this

and got no really helpful answer. )

  • Why do you need to calculate profit ? It's already calculated for you by the platform, and accessible with mql5, see DEAL_PROFIT.
  • If that doesn't work, show what you have tried, so maybe we can understand why.
  • You don't have enough input (symbol, p1, p2, volume), you also have to know direction (BUY/SELL) to calculate the profit.
  • The general formula is profit = number_of_pips * pip_value or profit = number_of_ticks * tick_value.
Reason: