- www.mql5.com

I did not read and check your entire post, but I am left wondering if you are perhaps using the enumerations directly in your calculations, instead of using them in the functions?

For example, in your post ...

dbPointValue = SYMBOL_TRADE_TICK_VALUE * SYMBOL_POINT / SYMBOL_TRADE_TICK_SIZE

Are you doing like this?

Forum on trading, automated trading systems and testing trading strategies

Fernando Carreiro, 2022.05.18 21:05

double dbTickSize = SymbolInfoDouble( _symbol, SYMBOL_TRADE_TICK_SIZE ), // Tick size dbTickValue = SymbolInfoDouble( _symbol, SYMBOL_TRADE_TICK_VALUE ), // Tick value dbPointSize = SymbolInfoDouble( _symbol, SYMBOL_POINT ), // Point size dbPointValue = dbTickValue * dbPointSize / dbTickSize; // Point valueRemember, it's best to usetick sizeandtick valuein your calculations, instead ofpoint sizeand its value.

Also, consider simplifying your code and simply use OrderCalcProfit instead.

Forum on trading, automated trading systems and testing trading strategies

SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) sometimes zero

Fernando Carreiro, 2022.08.23 17:41

You can! These are the steps I take. I supply the function with a lot size equal to the “Max Lot Size” allowed for the symbol in question, then calculate the ratio needed to achieve the fractional risk that I wish to apply, to get the correct volume for the order. I then align that with the “Lot Step” and finally check it against both the maximum and minimum allowed lots for the symbol.

The reason I use the “maximum” lots instead of just “1.0” lots as a reference value is because there is no guarantee that the value of 1.0 is within the minimum and maximum values allowed. Given that using 1.0, or the maximum, gives equivalent results anyway (by using the ratio method), I choose to use the “max lots” as the reference point which also offers the most precision for the calculation.

Something like this ...

// This code will not compile. It is only a example reference if( OrderCalcProfit( eOrderType, _Symbol, dbLotsMax, dbPriceOpen, dbPriceStopLoss, dbProfit ) ) { dbOrderLots = fmin( fmax( round( dbRiskMax * dbLotsMax / ( -dbProfit * dbLotsStep ) ) * dbLotsStep, dbLotsMin ), dbLotsMax ); // the rest of the code ... };

- www.mql5.com

**Fernando Carreiro #:**

I did not read and check your entire post, but I am left wondering if you are perhaps using the enumerations directly in your calculations, instead of using them in the functions?

For example, in your post ...

dbPointValue = SYMBOL_TRADE_TICK_VALUE * SYMBOL_POINT / SYMBOL_TRADE_TICK_SIZE

Are you doing like this?

hi Fernando,

yes I start like that and I had taken that formula from one of you posts . But then I enhance it with :

**Position Profit= Difference * POSITION_VOLUME * dbPointValue / SYMBOL_POINT**

and find the EURUSD profit correctly as MT5 displays. But same formula did not work for XAUUSD. Will appreciate if you can point me what is wrong in my logic.

And also I am aware of functions like **OrderCalcProfit** but I am behind the formula to calculate position profit my by self ( my own curiosity)

thank you

Forum on trading, automated trading systems and testing trading strategies

How to calculate take profit from currency

Fernando Carreiro, 2022.09.05 17:00

These are all the same equation written in different ways ...

[Volume] = [Money Value] * [Tick Size] / ( [Tick Value] * [Stop Size] ) [Stop Size] = [Money Value] * [Tick Size] / ( [Tick Value] * [Volume] ) [Money Value] = [Volume] * [Stop Size] * [Tick Value] / [Tick Size] [Volume] in lots [Stop Size] in quote price change [Money Value] in account currency

**Fernando Carreiro #:**

hi Fernando,

Thank you, I understand what you mean by Stop Size now. Now this is exactly the same way I use to calculate EURSUD correctly above.

BUT when I use this for XUAAUSD:

[Money Value] = [Volume] * [Stop Size] * [Tick Value] / [Tick Size]

= 5 * ( 1966.97 - 1966.91 ) * 1.0 / 0.00001

= 5 * 0.06 * 1.0 / 0.00001

= 30,000$ where it should be 30$ actually

So what is the generic formula again ?

thank you

**Robobiee #: **BUT when I use this for XUAAUSD:

[Money Value] = [Volume] * [Stop Size] * [Tick Value] / [Tick Size]

= 5 * ( 1966.97 - 1966.91 ) * 1.0 / 0.00001

= 5 * 0.06 * 1.0 / 0.00001

= 30,000$ where it should be 30$ actually

So what is the generic formula again ?

Your tick size is incorrect for XAUUSD.

If your prices are with two decimal places (digits), then the point and tick size are probably 0.01 and not 0.00001.

In your first post, you have shown ..SYMBOL_TRADE_TICK_SIZE: 0.00001SYMBOL_POINT:0.001

But I doubt the tick size. Either you are reading it incorrectly in your code or the broker is reporting it incorrectly.

**Fernando Carreiro #:**

Your tick size is incorrect for XAUUSD.

If your prices are with two decimal places (digits), then the point and tick size are probably 0.01 and not 0.00001.

In your first post, you have shown ..SYMBOL_TRADE_TICK_SIZE: 0.00001SYMBOL_POINT:0.001

But I doubt the tick size. Either you are reading it incorrectly in your code or the broker is reporting it incorrectly.

Thank you Fernando, your support is very much appreciated !

Robobiee

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets

You agree to website policy and terms of use

thank you very much

Robobiee