2

I have recently download the MetaTrader Terminal platform ( MT4 ).

I have my own back testing engine which stores some output in my SQL-server database. The output depends on the model I am testing. However, the output can just be as simple as the time of entry of a trade.

What I would like to know

Is it possible in MQL4 to download data from a SQL-server database and then annotate the chart with a simple "B" for a buy entry or "S" for a sell entry?

So I have run a back test simulation ( i.e. EURUSD from 2010 to 2011 ) and stored the time of the buy and sell entries. I would then like to go to my MetaTrader 4 platform and run a script which would download the time of all the buy and sell entries from my SQL-database and on my EURUSD chart label these XTO-s.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
mHelpMe
  • 6,336
  • 24
  • 75
  • 150

1 Answers1

1

Yes, this is possible

MQL4 language, incl the "New"-MQL4 ( aka MQL4.5 ), has syntactical support for importing DLL-based services, that allow re-integration of tools, the closed-syntax of the MQL4 does not allow to gain in a more natural way.

//+------------------------------------------------------------------+  // msMOD(s) 2014  >>> [dev]_test_(python)_.PUB__(mql).SUB_with_KBD_and_SIG___StatefullGrammarFSA
//| Ver 4.00, Build 509                          [dev]__********.mq4 |  // msMOD(s) 2013    
//+------------------------------------------------------------------+  //              
#property copyright "[dev] msMOD(s) (c) 1987-2014"                      //              
// ---------------------------------------------------------------------<#import>.start
#import  "msLIB_services.ex4"
         void  msLIB.aSnapshot.MAKE();
#import
// ---------------------------------------------------------------------<#import>.end
// ZMQ LIBRARY |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#include <mql4zmq.mqh>                                                  // Include the libzmq.dll abstraction wrapper
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

This way your code, be it MQL4-Script or MQL4-ExpertAdvisor can communicate with external processes, incl. any reasonably working DBMS.

Beware

There are few important features a code-design and integration architecture should bear in mind. MQL4, since the earliest days, is not a plain sequential-processor, namely the MQL-CustomIndicator is by far distant from this paradigm. The code ( except for the case of MQL4-Script ) acts as an event-driven factory, that is initiated by asynchronous flow of incoming Market Events. User is responsible for all measures to not violate real-time stability of this Alpha&Omega principle-of-MQL4-principles. In other words, a poor design, that may get some I/O-blocking ( due to RDBMS processing et al ), will be most probably a reason for Trading Terminal crash(es), which is the last thing anybody is willing to experience ( be it in live-trading or back-testing phase ), isn't it?

So, a sound non-blocking, heterogenous, parallel multi-processing integration architecture & code-design is to be used for this task.

It works great, if done professionally

Keeping the said in mind allows very smart, fast and (almost) unlimited architectures to work together with Trading Terminal(s). Having multiple cases with near-real-time messaging between MT4/MQL4 code and AI/ML engine via python, fast FIX-Protocol streaming engine for real-time data input from Liquidity Pool provider, using a remote NVIDIA/GPU computation fabric, remote co-integrated IRC/skype/email Signal provisioning channels.

So a can do philosophy is in place. SQL is nothing extra in this sense. Puting labels is trivial in the same sense. Just of your imagination, MQL4 allows to build ( again, using a near-real-time design ) responsive/interactive GUI-layer, that allows, within a few [msec] stability barrier, work with the Trading Terminal in a pure-graphical manner ( long ago before a One-Click-Trading marketing tag came with just a click-To-Buy / click-To-Sell ) working fully interactively with line-controlled / graphical-objects visual trading aids, be it for a fully automated trade-execution ( with an indirect GUI-configuration of the rules-set ), or for an Augmented Trading style.

Distributed-processing-MQL4-Cloud-xtrnSignalProvider

Yes, can make your MT4 Trading Terminal a sort of "remote-programmable charting display", driven not by FX-Market, but from a Cloud-processor, where your remote Strategy Testing Engine rulez ...

Distributed-processing-MQL4-Cloud-Predictive-Technical-Analysis

user3666197
  • 1
  • 6
  • 50
  • 92
  • As I understand it (correct me if I'm wrong) the Expert Advisor & Custom Indicator are event driven so when a market event happens they are called. A script is not even driven so this is where I should create my code. Is it possible to stop the charts updating to get around the stability issue? As I'm back testing I'm not concerned with the charts updating. – mHelpMe Oct 27 '14 at 09:58
  • 1
    Right, **`MQL4-Script`** has no trigger from an event queue, correct. Still, I would not rely on sending a blind SQL-querry & waiting, but rather implement an asynchronous proxy-interface, that would mediate MQL4-front-end / SQL-back-end processing & queue-management, to serve one after another, to avoid both MQL4-blocking and MQL4-side overload case, when getting an avalanche of bytes in the "block-buster" answer ( not mentioning the HFT-case scales as a first trouble in the list :o) ) – user3666197 Oct 27 '14 at 10:06
  • 1
    Ask asked above, your code does not know, whether the **`MT4-Graph`** is an online, or an off-line one. You can easily activate your `MQL4-Script` code on an off-line graph, it does not "listen" to any updates nevertheless by-design. Another issue is to have "relevant OHLCV-data" already available in the MT4-HistoryCentre ( a database, from which your graphing will get PriceDOMAIN data to plot candles/bars ) -- but that is another subject to address. – user3666197 Oct 27 '14 at 10:12
  • Thanks for a very detailed answer. Think I get it and will now try go away and implement it. On the data issue I believe I can place my price data in the HistoryCenter. – mHelpMe Oct 27 '14 at 10:36