different trade volume calculation in different computers

 

Hello,

I am coding an expert and for volume calculation using below function.

double tradelot(double Entry, double SL)
  {
   double riskamount = AccountInfoDouble(ACCOUNT_BALANCE) * capital_risk / 100;
   double totalpointmoney = (MathAbs(Entry-SL) / SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE))     // Calculate Point# x Point value
                            * SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE);                          
   return NormalizeDouble(riskamount/totalpointmoney,2);
 }

Improperly formatted code edited by moderator.

but regret volume in different computers differs. one will be 1.38 and the other one is 1.39000000001.

What is my problem and how can fix it ?

 

Improperly formatted code edited by moderator. Please always use the CODE button (Alt-S) when inserting code.

Code button in editor

 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

Consider using 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 ...
};
 
Also read the following related post for more information ... https://www.mql5.com/en/forum/449520#comment_47719772
[Help - fixed] Leverage is disturbing my Size calculation. Using TV.
[Help - fixed] Leverage is disturbing my Size calculation. Using TV.
  • 2023.06.23
  • www.mql5.com
Hi all. My function SetSize is working on my own trading conditions, but not working on high leverage or low account balances as I extecpted...
 
why my code results different volume in different computers ?
 
mrnoorhani #: why my code results different volume in different computers ?

You have not provided sufficient information and details for us to provide a definitive answer.

So, I would guess that it is probably because you are using different trading accounts and/or symbols.
 

No I use the same symbol on strategy tester platform but the code claculate different volume size for trades that SL and entry points are all the same.

I have attached above my code.

 
mrnoorhani #: No I use the same symbol on strategy tester platform but the code claculate different volume size for trades that SL and entry points are all the same. I have attached above my code.

Yes, you have provide the code, but you have not provided anything else.

  • Is it the same broker and trading account?
  • Is it the same account currency selected in the Strategy Tester?
  • Are the contract specifications for the symbol the same in each case?
  • etc.

Have your code print out the relevant information to the log file and show us the results for the tests on different computers ...

  • Tick Size
  • Tick Value
  • Account Balance
  • Account Currency
  • Entry price
  • Stop Size
  • Risk percentage
  • etc.
 
mrnoorhani #: No I use the same symbol on strategy tester platform but the code claculate different volume size for trades that SL and entry points are all the same. I have attached above my code.
Also, just to make sure, your question is about MetaTrader 5, correct?
 

Hello, thanks for your prompt replies.

I found out the issue.

In one PC metatrader calculated the trade commissions but in another one no. it seems metatrader for different brokers calculate commissions and others not in strategy tester.