Fresh MQL5 code release – perfect for enhancing your MT4/MT5 strategies.

Author:
Russell
Classic MACD strategy made fully automatic – the MACD Expert Advisor for MT4 handles it all. Check it out.
There are a few solutions around for reading and writing to MySQL databases. Writing to MySQL is in general not a big problem in MT4. But the reading part is kinda hard. MT4 can't handle C++ structures very well, only the native types such as int, double and string are supported. Other solutions use a SELECT statement CONCATing the wanted fields. I found this solution unstable and therefor a high error risk. The wrapper translates two MySQL structures to the types MT4 can handle. All orignal functions of libmysql are exported in the wrapper as well. Full sourcecode available in zip-file.
Example:
#include <mysql_v2.0.4.mqh> int init(){ Print(MT4_mysql_wrapper_version()); MySQL_Init(); getDB(); return(0); } int deinit(){ MySQL_DeInit(); return(0); } int start(){ return(0); } void getDB(){ //--------------v set this to the number of fields you're selecting string lsData[][2]; string lsQuery = "SELECT tableid,some_value FROM `mytable` INNER JOIN .... WHERE ... ORDER BY ..."; MySQL_FetchArray(lsQuery, lsData); for (int i = 0; i < ArrayRange(lsData,0); i++){ for (int j = 0; j < ArrayRange(lsData,1); j++){ Print(i+","+j+": "+lsData[i][j]); } } }
Credits:
https://www.mql5.com/en/users/gc1 for pointing out some bugs
Install:
mysql_v2.0.2.mqh - goes to your include directory
mysql_wrapper_v1.0.2.zip
- open the zip
- extract mysql_wrapper_v1.0.2.zip\mysql_wrapper\Debug\mysql_wrapper.dll to C:\Windows\system32\
Discussion:
Update:
mysql_v2.0.4.mqh - has some extra error checks
mysql_wrapper_v1.0.3.zip - repack VS2008
Build better strategies with RobotFX professional tools – check them out.
8623