Reading Leverage from .ini file in Strategy Tester interactively and non-interactively gives different outcomes

 

Dear all,


I am developing some experts in MQL5 and am running back tests on them.  To make things faster, I also develop Power Shell (7) scripts which run tests in a non-interactive fashion, varying various trading parameters, including the leverage.  I noticed that scripts sometimes give unexpected results and took a closer look.  It seem that what will Meta Trader strategy tester read from .ini file on Leverage, depends if strategy tester is ran in interactive (with GUI) or non-interactive way (from Power Shell, either from a script or just from prompt).  Allow me to give you a clear example.


I have the .ini file A.ini, which stores the info on the leverage in the line:

Leverage=1:5

If I read the file A.ini from the Strategy Tester interactively (from the GUI), it will miss interpret the leverage and it will stay at 1:1 (or whatever was the previous value).  Running the back test over a specific product and over a year, gives me the final balance of: 10'364.42 EUR.

However, if I use the same script to run the Strategy Tester non-interactively (from the Power Shell) with the command:

Start-Process "C:\Program Files\FP Markets MetaTrader 5\terminal64.exe" /config:.\A.ini -Wait

 it will interpret the leverage correctly, as 1:5, and give the final balance of: 11'575.78 EUR.  (That makes sense, with leverage 1:5 I gain roughly five times more than with leverage 1:1)


OK, now let's focus on the file B.ini which is exactly the same as A.ini, except the line with the info on the leverage, which here reads:

Leverage=5:1

If I read the file B.ini from the  Strategy Tester interactively (from the GUI) it will interpret the leverage correctly as 1:5 (it will overwrite whatever was set before) and if I run the test in this interactive mode, it will give me the final balance of 11'575.78 EUR, the value expected for this leverage.

But, if I run the strategy tester non-interactively (from the Power Shell) and read the same B.ini script with the command:

Start-Process "C:\Program Files\FP Markets MetaTrader 5\terminal64.exe" /config:.\B.ini -Wait

It will fail to read leverage as 1:5, but leave it to 1:1 or whatever was the value previously set in Strategy Tester.  Clearly, the final balance will be 10'364.42 EUR, as for the case without leverage.


So, to summarize, in order to get leverage 1:5 in Strategy Tester, in the .ini file I must specify:

Leverage=1:5 if I run the Strategy Tester non-interactively, and:

Leverage=5:1 if I run the Strategy Tester interactively.


It seems to me that issues started since Meta Trader made an update a few days ago.  I am currently running the version 5.00, Build 4040, Oct 20, 2023.  This version was built five days before I post this question.

Does anyone have an idea what is going on here?  Is it expected behavior, or did I encounter some anomaly?  Has anyone experienced the same or made came up with some workarounds?


    Best regards

 

Why are you using "1:5" or "5:1" ? From what I can see the ini file needs just a simple value :

Leverage=5

 
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
 
Alain Verleyen #: Why are you using "1:5" or "5:1" ? From what I can see the ini file needs just a simple value :

Leverage=5

Dear Alain,

Thanks for the attention and answer.  I was trying with the simple: "Leverage=5" as you suggest, but it was behaving the same as 5:1 - that means it was fine if you read it interactively, but does not work from the shell.

In the meantime I've found what the problem was.  It was in the CRLF line terminators.  I keep all my files on Github through Git Bash shell on Windows.  It is configured in a way to turn all textual files to Unix format when you push them and (consequently) you also get them in Unix format when you retrieve them.  If I transform the .ini files to DOS format with unix2dos command, all works fine :-)

 
Fernando Carreiro #:
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

Thanks and apologies for failing to hit the appropriate section.

 
Butch Boyle #:

Dear Alain,

Thanks for the attention and answer.  I was trying with the simple: "Leverage=5" as you suggest, but it was behaving the same as 5:1 - that means it was fine if you read it interactively, but does not work from the shell.

In the meantime I've found what the problem was.  It was in the CRLF line terminators.  I keep all my files on Github through Git Bash shell on Windows.  It is configured in a way to turn all textual files to Unix format when you push them and (consequently) you also get them in Unix format when you retrieve them.  If I transform the .ini files to DOS format with unix2dos command, all works fine :-)

5:1 doesn't make sense for a leverage.

Are you saying that when running from a script you need to have "1:5" and not just "5" in the ini file ? Even with your CRLF issue fixed ?

I don't have time to check that myself.

 
Alain Verleyen #:

5:1 doesn't make sense for a leverage.

Are you saying that when running from a script you need to have "1:5" and not just "5" in the ini file ? Even with your CRLF issue fixed ?

I don't have time to check that myself.

I agree that 5:1 doesn't make sense, but I was working around this issue for a couple of days and was already running desperate a bit.

I am afraid I was too fast to conclude that CRLF fixed the thing, the tests I did since then confirmed that it wasn't the issue, sorry for misleading you before.

Having said that, I would like to confirm: "Leverage=5" in the .ini file works fine from GUI, but I need "Leverage=1:5" when invoking Strategy Tester from Power Shell (including Power Shell scripts of course).

I have the impression that this asymmetry started after I updated Meta Trader 5 to version 5.00, build 4040, Oct 20 2023, but have no solid evidence of that.

 
Butch Boyle #:

I agree that 5:1 doesn't make sense, but I was working around this issue for a couple of days and was already running desperate a bit.

I am afraid I was too fast to conclude that CRLF fixed the thing, the tests I did since then confirmed that it wasn't the issue, sorry for misleading you before.

Having said that, I would like to confirm: "Leverage=5" in the .ini file works fine from GUI, but I need "Leverage=1:5" when invoking Strategy Tester from Power Shell (including Power Shell scripts of course).

I have the impression that this asymmetry started after I updated Meta Trader 5 to version 5.00, build 4040, Oct 20 2023, but have no solid evidence of that.

Could you share your script ? So I could confirm the issue quickly and report it to MQ, without losing time.

Reason: