Is there a way to get a unique and constant identifier for someone's mql5 account inside of a mq5 indicator script?

 

Hello!

I'm brand new to metatrader but I work professionally as a programmer. I'm also brand new to these forums as well so I'm sorry if I'm overlooking some information out there. I'm working on a side project for a buddy of mine where I'm trying to create a remote licensing server for an indicator using this extremely helpful tutorial https://www.mql5.com/en/articles/359

What I would like to do is have the .mq5 indicator code send the python XML-RPC server a request that contains some sort of unique identifier that identifies the users mql5 account. What I wish that existed was a function called like ACCOUNT_USERNAME() that would give me the username that appears in the top right profile of metatrader. For example my mql5 community account username is "ginjahd". Is there some way I can get this username within the mq5 indicator code?

I found this documentation https://www.mql5.com/en/docs/constants/environment_state/accountinformation but it seems like all of the account info inside of it is related to broker accounts. From my limited understanding, it seems like a user could change their broker and thus these strings and account numbers returned by these functions could change and not be constant. I almost need something like the serial number of a users motherboard on their PC to be sent in the http request (I'm not going to do this but this is an idea I had, I needs some sort of unique identifier) Thank you for anyone who takes time to read this!


This is my code snippet in OnInit() but it seems like these values are not constant and will change depending on what the user chooses for their broker account 

string broker= AccountInfoString(ACCOUNT_COMPANY);
long account = AccountInfoInteger(ACCOUNT_LOGIN);
string name = AccountInfoString(ACCOUNT_NAME);
   
printf("The name of the broker = %s",broker);
printf("Account number =  %d",account);
printf("The username is = %s", name);
Securing MQL5 code: Password Protection, Key Generators, Time-limits, Remote Licenses and Advanced EA License Key Encryption Techniques
Securing MQL5 code: Password Protection, Key Generators, Time-limits, Remote Licenses and Advanced EA License Key Encryption Techniques
  • www.mql5.com
Most developers need to have their code secured. This article will present a few different ways to protect MQL5 software - it presents methods to provide licensing capabilities to MQL5 Scripts, Expert Advisors and Indicators. It covers password protection, key generators, account license, time-limit evaluation and remote protection using MQL5-RPC calls.
 
ginjahd: What I wish that existed was a function called like ACCOUNT_USERNAME() that would give me the username that appears in the top right profile of metatrader. For example my mql5 community account username is "ginjahd". Is there some way I can get this username within the mq5 indicator code? 

Currently, there is no documented way of obtaining the MQL5.Community user name. There may be an undocumented way, but I am not aware of it.

The username is however stored in the "Config/common.ini" file as follows:

[Common]
MQL5Login=username

It also appears in the Journal log file.

 
Fernando Carreiro #:

Currently, there is no documented way of obtaining the MQL5.Community user name. There may be an undocumented way, but I am not aware of it.

The username is however stored in the "Config/common.ini" file as follows:

It also appears in the Journal log file.

Hi, thanks for taking the time to read through my post and reply, I really appreciate it!

This username in the ini file is exactly what I'm looking for. I tried doing this snippet below but I can't seem to get the code to detect that the ini file exists. The following snippet was returning false for FileIsExist. What am I missing here? 

string InpFileName = "C:/Users/Drew/AppData/Roaming/MetaQuotes/Terminal/D0E8209F77C8CF37AD8BF550E51FF075/config/common.ini";
if(!FileIsExist(InpFileName)) {
        printf("File does not exist");
}

As a sanity check I used python and did the following snippet and got back "True" so the path definitely exists. 

os.path.exists("C:/Users/Drew/AppData/Roaming/MetaQuotes/Terminal/D0E8209F77C8CF37AD8BF550E51FF075/config/common.ini")

Do I need to copy the file to a txt file and/or write it to a new location or something? Maybe the mq5 code doesn't have access to the /config directory? 

The documentation for FileIsExist https://www.mql5.com/en/docs/files/fileisexist states "For security reasons, work with files is strictly controlled in the MQL5 language. Files with which file operations are conducted using MQL5 means, cannot be outside the file sandbox." which I understand this but wouldn't a config ini file be within the sandbox of mql5? 

Also might be a dumb question but where would one find the "Journal log file". I found there is a log file in MQL5\Logs but there was unfortunately no username within this file 

Thanks for your help! 

Documentation on MQL5: File Functions / FileIsExist
Documentation on MQL5: File Functions / FileIsExist
  • www.mql5.com
FileIsExist - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
ginjahd #: This username in the ini file is exactly what I'm looking for. I tried doing this snippet below but I can't seem to get the code to detect that the ini file exists. The following snippet was returning false for FileIsExist. What am I missing here? As a sanity check I used python and did the following snippet and got back "True" so the path definitely exists. Do I need to copy the file to a txt file and/or write it to a new location or something? Maybe the mq5 code doesn't have access to the /config directory? The documentation for FileIsExist https://www.mql5.com/en/docs/files/fileisexist states "For security reasons, work with files is strictly controlled in the MQL5 language. Files with which file operations are conducted using MQL5 means, cannot be outside the file sandbox." which I understand this but wouldn't a config ini file be within the sandbox of mql5? Also might be a dumb question but where would one find the "Journal log file". I found there is a log file in MQL5\Logs but there was unfortunately no username within this file 

MQL's file handling functions are sandboxed to the "Files" folder, under MQL folder, or under the Tester folder or in the common path folder. Those are the only areas where files can be accessed.

The journal log files would also be out of reach for the sandboxed functions.

Only DLL calls would be able to access these files (be it the config or logs).

 
You could also restrict a subscriber's credentials to a number of active ips (per the check frequency).
The drawback here is an additional terminal from a new ip will operate for at least check frequency x 2
in a worse case senario.

For example :
Let's say Bob has valid credentials for your friend's indicator for 5 ips.
Your friend's indicator checks credentials every 1 hour
Bob is using all 5 ips
A 6th ip appears and has Bob's valid credentials 
You cannot kill it immediately (reject the request) because you do not know
if any of the previous 5ips was shut down so you have to wait at most 59 minutes from the 
last time one of those guys checked in , and another at most +59 minutes from to reject 
the 6th ip once it checks for credentials again .
Unless upon detection of the 6th ip you instruct that terminal to check every 5 minutes because you
are in doubt until the debuckle clears out.

 
Fernando Carreiro #:

MQL's file handling functions are sandboxed to the "Files" folder, under MQL folder, or under the Tester folder or in the common path folder. Those are the only areas where files can be accessed.

The journal log files would also be out of reach for the sandboxed functions.

Only DLL calls would be able to access these files (be it the config or logs).

Do you know if this instance ID 
"C:/Users/Drew/AppData/Roaming/MetaQuotes/Terminal/D0E8209F77C8CF37AD8BF550E51FF075

is unique to a persons metatrader account or metatrader installation? 

 
ginjahd #: Do you know if this instance ID is unique to a persons metatrader account or metatrader installation? 
It's for the installation only. So each installation on the PC has a different one, irrespective of the user ID or account number.
 
Fernando Carreiro #:
It's for the installation only. So each installation on the PC has a different one, irrespective of the user ID or account number.

Hmm okay I think this might be my golden ticket then. I think I can use this unique computer instance ID to communicate with the licensing server. This would prevent someone from sending the .ex5 to someone else and using it on their computer. I went down the path of using serial number/mac address as a unique hardware identifier but this requires DLLs, is tough to handle across multiple operating systems, and its a bit more heavy lifting. I found a way to generate the instance id programmatically and natively within the .mq5 file.

dumb question but when you say "each installation on the PC has a different one". Am I understanding you correctly that this means someone could install multiple copies or versions of metatrader 5 and each installation has it's own unique instance id?

this is where I found the instance ID generation -> https://www.mql5.com/en/code/26945

Instance ID script for MT4/MT5
Instance ID script for MT4/MT5
  • www.mql5.com
This script allows a user to find out instance_id of the running MetaTrader instance/installation.
 
ginjahd #:

Hmm okay I think this might be my golden ticket then. I think I can use this unique computer instance ID to communicate with the licensing server. This would prevent someone from sending the .ex5 to someone else and using it on their computer. I went down the path of using serial number/mac address as a unique hardware identifier but this requires DLLs, is tough to handle across multiple operating systems, and its a bit more heavy lifting. I found a way to generate the instance id programmatically and natively within the .mq5 file.

dumb question but when you say "each installation on the PC has a different one". Am I understanding you correctly that this means someone could install multiple copies or versions of metatrader 5 and each installation has it's own unique instance id?

this is where I found the instance ID generation -> https://www.mql5.com/en/code/26945

No! That is not the same thing as I was talking about. That script generates a hash based on the terminal path and not the Installation Hash generated by MetaTrader.

I don't recommend using that method because should the user change the path (especially in portable mode), it would invalidade the license.

Plus, many of us use portable mode that does not have an installation hash ID in the path. Here is my example (using that script):

2022.09.07 01:01:41.231 instance (GBPUSD,D1)    Install folder = C:\Trading\MetaQuotes\MetaTrader 5
2022.09.07 01:01:41.232 instance (GBPUSD,D1)    Instance ID = 897252626A1CF54B5C61C568B559B237
 
ginjahd #: dumb question but when you say "each installation on the PC has a different one". Am I understanding you correctly that this means someone could install multiple copies or versions of metatrader 5 and each installation has it's own unique instance id?

Yes, you can have multiple installations of the terminal on a PC, and each will have a different hash in the data folder path. In portable mode however, we can choose own directory path and not have a hash id in it.

 
Fernando Carreiro #:

Yes, you can have multiple installations of the terminal on a PC, and each will have a different hash in the data folder path. In portable mode however, we can choose own directory path and not have a hash id in it.

ahh okay thank this makes more sense. Looks like I'm gonna have to go down the path of serial numbers using C++ and dlls :( 
Reason: