Skip to content

MQL5

Besides NTSL, TMChart runs programs in MQL5, the MetaTrader 5 language: EAs (OnTick), indicators (OnCalculate) and scripts (OnStart). They run on TMChart’s own interpreter: MetaTrader 5 never runs the program and MT5 Algo Trading is not used. An EA’s orders go to the TMChart broker — Backtest, SIMULATOR and replay — and, on the LIVE account, only through an automation you turn on.

The list of what the interpreter accepts is in the MQL5 function reference.

  • Language: types with MQL5 semantics (integer division, datetime, color, D'...'/C'...' literals), struct, enum, dynamic arrays, input/sinput, overloading, default and by-reference parameters, #define, #property, #ifdef.
  • Object orientation: classes, inheritance, virtual, interfaces, templates, new/delete, namespace.
  • #include <...> reads the MQL5\Include folder of your terminal (for example Trade\Trade.mqh and the CTrade class); #include "file.mqh" reads the program’s folder.
  • Symbol and series data in any timeframe, 38 technical indicators by handle (iMA, iRSI, iMACD…), iCustom for your own MQL5 indicator, orders, positions and history.
  • Left out (the program is rejected when it loads, with the reason): DLLs and #import, .ex5 without source, chart objects, files, network and real ticks (CopyTicks). See the reference.

Strategies → Strategy Editor menu, MQL5 tab.

MQL5 tab of the Strategy Editor with a sample EA App screenshot with fictitious data (demo).

  • On the left, the .mq5 files of the terminal’s MQL5\Experts\TMChart, MQL5\Indicators\TMChart and MQL5\Scripts\TMChart folders. New file creates one from a template (EA, indicator or script). TMChart only writes to these folders.
  • Save writes the file. Compile uses the terminal’s MetaEditor to check the code (it creates the .ex5); Open in MetaEditor opens the file there.
  • Inputs: the program’s inputs, with a field to change the value (empty = the value in the code).
  • Run (script or indicator): runs on the last bars of the active chart; Print, Comment and errors go to the console below.

In this version the MQL5 tab labels are shown in Portuguese: Novo arquivo (New file), Salvar (Save), Compilar (Compile), Abrir no MetaEditor, Executar (Run), Otimizar (Optimize), Início/Fim (Start/End), Modelagem (Modeling) and Conferir com o Provador do MT5 (Check against the MT5 Tester).

In the chart’s Indicators window, the MQL5 indicators (terminal) group lists the indicators of the Indicators\TMChart folder. Once inserted, the buffers and plots (#property indicator_*, PlotIndexSet*) are drawn like any indicator; double-click to open the inputs.

Below the editor, the TMChart Tester (local broker):

  • Backtest: Start, End, Modeling (OHLC per minute — M1 bars, like the MT5 Tester “1 minute OHLC” — or open prices only), Initial balance, Cost per contract and Slippage (ticks). The result uses the same screen as the NTSL Backtest (summary, trades, chart, equity).
  • Optimize: tick the numeric inputs, with start, step and end; click a result row to see that variation’s backtest and Use these values to bring them to the inputs.
  • The Backtest panel (Strategies menu) also has NTSL | MQL5, with the EAs of the Experts\TMChart folder.

To compare TMChart with MetaTrader 5: in MT5, run the same EA in the Strategy Tester (same symbol, period and dates; “1 minute OHLC” modeling), save the report (right-click → Report → HTML) and, in TMChart, use the open MT5 report button under Check against the MT5 Tester. TMChart only reads the file and compares trade by trade: equal, different (time, price, volume or profit, with the time tolerance), only in MT5 and only in TMChart, plus both results. The “differences only” box filters the list.

In New Automation → Select strategy, the MQL5 EAs tab lists the EAs of the Experts\TMChart folder (the file is read again on every Start). The EA runs on every tick (OnTick) with the automation’s own position, the inputs in Edit parameters and the same tabs and protections as an NTSL automation, on the SIMULATOR, in replay and on LIVE.

MQL5 uses the same license features as NTSL: editor, backtest, optimization and automations (see License and plans). You need MetaTrader 5 installed (the MQL5 folders and MetaEditor come with it).