title: Python command to execute non-Python (MQL5) files?
body: <p>I have a collection of expert advisor (EA) scripts written in the MQL5 programming language for the stock/forex trading platform, MetaTrader5. The extension of these files is <code>mq5</code>. I am looking for a way to programatically run these MQL5 files from my Python script on a regular basis. The EAs do some price transformations, eventually saving a set of csv files that will later be read by my Python script to apply Machine Learning models on them.</p>
  <p>My first natural choice was the <a href="https://www.mql5.com/en/docs/integration/python_metatrader5" rel="nofollow noreferrer">Python API for MetaTrader5</a>. However, according to its documentation, it <em>&quot;is designed for convenient and fast obtaining of exchange data via interprocessor communication directly from the MetaTrader 5 terminal&quot;</em> and as such, it doesn't provide the functionality I need to be able to run MQL scripts using Python.</p>
  <p>I have found some posts here on SO (such as <a href="https://stackoverflow.com/questions/49959311/execute-code-from-non-py-file-in-python">#1</a>, <a href="https://stackoverflow.com/questions/31704916/python-how-to-execute-code-from-a-txt-file">#2</a>) about executing non-python files using Python but those posts seemed to always come with the precondition that they already had Python code written in them, only the extension differed - this is different from my goal.</p>
  <p>I then came across Python's <code>subprocess</code> module and started experimenting with that.</p>
  <pre><code>print(os.path.isfile(os.path.join(&quot;path/to/dir&quot;,&quot;RSIcalc.mq5&quot;)))
  with open(os.path.join(&quot;path/to/dir&quot;,&quot;RSIcalc.mq5&quot;)) as f:
     subprocess.run([r&quot;C:\Program Files\MetaTrader 5\terminal64.exe&quot;, f], capture_output=True)
  </code></pre>
  <p>The print statement returns <code>True</code>, so the <code>mq5</code> file exists in the specified location. Then the code opens the MetaTrader5 terminal but nothing else happens, the EA doesn't get executed, process finishes immediately after that.</p>
  <p>Am I even on the right track for what I'm trying to achieve here? If yes, what might be the solution for me to run these MQL5 scripts programatically from Python?</p>
  <p>Edit:
  I use Windows 10 64-bit.</p>