Hello,
I try to calculate expected profit (D) and margin requirement , but I get strange result in Tester. On Demo and Real account, it is OK.
I use this code (Script) over account, and same as Expert in Tester :
.. and results are :
Is this normal , my error , or Tester error ?
Here again description of the problem . Used code :
void OnStart() { // ========== double MaginInit, MarginKeep; SymbolInfoMarginRate(_Symbol,ORDER_TYPE_BUY,MaginInit,MarginKeep); Print(" => MaginInit="+DoubleToString(MaginInit,2)); Print(" => MarginKeep="+DoubleToString(MarginKeep,2)); Print(" => USDBGN="+DoubleToString(SymbolInfoDouble("USDBGN",SYMBOL_ASK),_Digits) +"/"+DoubleToString(SymbolInfoDouble("USDBGN",SYMBOL_BID),_Digits)); Print(" => AccLeverage="+IntegerToString(AccountInfoInteger(ACCOUNT_LEVERAGE),2)); // ========== double MarginCalculated; if ( OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,0.01,SymbolInfoDouble(_Symbol,SYMBOL_ASK),MarginCalculated ) ) Print(" ===> MarginCalculated="+DoubleToString(MarginCalculated,2)); else Print(" ===>>> Margin NOT get <<<=== !"); }
Result :
// Script on real account : RQ 0 14:03:32.057 test2 (EURUSD,H1) => MaginInit=3.33 RQ 0 14:03:32.057 test2 (EURUSD,H1) => MarginKeep=0.00 QK 0 14:03:32.057 test2 (EURUSD,H1) => USDBGN=1.78686/1.78644 PL 0 14:03:32.057 test2 (EURUSD,H1) => AccLeverage=100 DI 0 14:03:32.057 test2 (EURUSD,H1) ===> MarginCalculated=65.20 // EA on TESTER : CS 0 13:58:10.589 127.0.0.1 login (build 3802) CS 0 13:58:10.589 Tester account info found with currency BGN CS 0 13:58:10.590 Tester expert file added: Experts\test-start1.ex5. 19287 bytes loaded CS 0 13:58:10.609 Tester calculate profit in pips, initial deposit 1000, leverage 1:100 CS 0 13:58:10.609 Tester successfully initialized ... CS 0 13:58:10.786 test-start1 (EURUSD,M1) 2023.05.01 00:00:00 => MaginInit=3.33 CS 0 13:58:10.786 test-start1 (EURUSD,M1) 2023.05.01 00:00:00 => MarginKeep=0.00 ... CS 0 13:58:10.789 test-start1 (EURUSD,M1) 2023.05.01 00:00:00 => USDBGN=1.77507/1.77466 CS 0 13:58:10.789 test-start1 (EURUSD,M1) 2023.05.01 00:00:00 => AccLeverage=100 CS 0 13:58:10.789 test-start1 (EURUSD,M1) 2023.05.01 00:00:00 ===> MarginCalculated=33.33 CS 3 13:58:15.323 Tester stopped by user CS 0 13:58:15.323 Tester test Experts\test-start1.ex5 on EURUSD,M1 thread finished CS 0 13:58:15.324 MQL5 debugger disconnected CS 0 13:58:15.328 127.0.0.1 prepare for shutdown CS 0 13:58:15.328 127.0.0.1 shutdown finished
Why are result of calculation different ? ... result from Tester is wrong .
... remark : Quote for USDBGN are : Friday Close for EA , Tester start date Open .
Here again description of the problem . Used code :
Result :
Why are result of calculation different ? ... result from Tester is wrong .
... remark : Quote for USDBGN are : Friday Close for EA , Tester start date Open .
Getting this , it looks correct (USD dep.curr)
Try and log all the values it gives in the tester with all leverage choices .
I assume the broker is responsible for tuning these (leverage selections and margins required0Here again description of the problem . Used code :
Result :
Why are result of calculation different ? ... result from Tester is wrong .
... remark : Quote for USDBGN are : Friday Close for EA , Tester start date Open .
On second post account is 1 (one) , Real . Account Currency is BGN . Leverage 1:30
I think that result from tester is :
Volume ( 1000 BGN ) * Leverage ( 1/30 ) = 33.33 ... and this is false !
In description of SYMBOL_CALC_MODE_FOREX Quote of Deposit currency not exist !
![Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties](https://c.mql5.com/36/78/documentation-on-mql5-constants__32.png)
- www.mql5.com
On second post account is 1 (one) , Real . Account Currency is BGN . Leverage 1:30
I think that result from tester is :
Volume ( 1000 BGN ) * Leverage ( 1/30 ) = 33.33 ... and this is false !
In description of SYMBOL_CALC_MODE_FOREX Quote of Deposit currency not exist !
Now I am on other computer.
Same Account, Broker, Account currency, Tester build. Only Wndows is a little older, but is 10, without updates.
Result in Tester is normal, as on Real account, ... but this computer is to slow for tests.
CS 0 07:37:50.028 127.0.0.1 login (build 3802) CS 0 07:37:50.040 Tester account info found with currency BGN CS 0 07:37:50.042 Tester expert file added: Experts\testEA.ex5. 11838 bytes loaded CS 0 07:37:50.071 Tester initial deposit 1000.00 BGN, leverage 1:100 CS 0 07:37:50.071 Tester successfully initialized ... CS 0 07:37:50.349 testEA (EURUSD,M1) 2023.05.01 00:00:00 => MaginInit=3.33 CS 0 07:37:50.349 testEA (EURUSD,M1) 2023.05.01 00:00:00 => MarginKeep=0.00 CS 0 07:37:50.353 testEA (EURUSD,M1) 2023.05.01 00:00:00 => USDBGN=1.77507/1.77466 CS 0 07:37:50.353 testEA (EURUSD,M1) 2023.05.01 00:00:00 => AccLeverage=100 CS 0 07:37:50.353 testEA (EURUSD,M1) 2023.05.01 00:00:00 ===> MarginCalculated=65.20 CS 3 07:37:54.347 Tester stopped by user
And on this computer I can change Tester currency. On Faster, with Tester problem, I cant.
Now I am on other computer.
Same Account, Broker, Account currency, Tester build. Only Wndows is a little older, but is 10, without updates.
Result in Tester is normal, as on Real account, ... but this computer is to slow for tests.
And on this computer I can change Tester currency. On Faster, with Tester problem, I cant.
I think I find solution for OrderCalcMargin . It works normal , when "calculate profit in pips" is NOT checked.
//==========================Test1=== CS 0 16:24:46.482 127.0.0.1 login (build 3802) CS 0 16:24:46.483 Tester account info found with currency BGN CS 0 16:24:46.507 Tester initial deposit 1000.00 BGN, leverage 1:100 CS 0 16:24:46.507 Tester successfully initialized CS 0 16:24:46.673 ******** (EURUSD,M1) 2023.05.01 00:00:00 Margin=65.20 CS 0 16:27:41.572 Tester final balance 1262.43 BGN CS 0 16:27:41.577 Tester EURUSD,M1: 422425 ticks, 106935 bars generated. CS 0 16:27:41.577 Tester EURUSD,M1: total time from login to stop testing 0:02:55.094 CS 0 16:27:41.932 127.0.0.1 shutdown finished // =========================Test2=== CS 0 16:32:46.366 127.0.0.1 login (build 3802) CS 0 16:32:46.366 Tester account info found with currency BGN CS 0 16:32:46.381 Tester calculate profit in pips, initial deposit 1000, leverage 1:100 CS 0 16:32:46.381 Tester successfully initialized CS 0 16:32:46.415 ******** (EURUSD,M1) 2023.05.01 00:00:00 Margin=33.33 CS 0 16:36:04.245 Tester final balance 1159.85 pips CS 0 16:36:04.250 Tester EURUSD,M1: 422425 ticks, 106935 bars generated. CS 0 16:36:04.250 Tester EURUSD,M1: total time from login to stop testing 0:03:17.884
It seems that "The value is returned in the account currency", written in documentation, is not true, when "calculate profit in pips" is checked.
... only for info : 65.20/33.33 is approximately equal to the fixing EURBGN . It is not floating. So looks like returned value is in EUR. ???
I think I find solution for OrderCalcMargin . It works normal , when "calculate profit in pips" is NOT checked.
It seems that "The value is returned in the account currency", written in documentation, is not true, when "calculate profit in pips" is checked.
... only for info : 65.20/33.33 is approximately equal to the fixing EURBGN . It is not floating. So looks like returned value is in EUR. ???
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I try to calculate expected profit (D) and margin requirement , but I get strange result in Tester. On Demo and Real account, it is OK.
I use this code (Script) over account, and same as Expert in Tester :
.. and results are :
Is this normal , my error , or Tester error ?