Below are the required files to use the MML Data Bridge
- User Set Up Manual: https://www.mql5.com/en/blogs/post/766374
#ifndef MMLDataStructs #define MMLDataStructs //input a defined length for char array #define CHAR_FIELD_WIDTH 128 //leave name as is, used as char field width for the bridge //Define your data structures below //Example 1 struct DIRECTION { datetime time; int signal; }; //Example 2 struct BTC_DATA { datetime time; double actual_price; double predicted_price; double price_residual; double price_error_pct; double actual_return; double predicted_return; double return_residual; double direction_correct; char dataset_name[CHAR_FIELD_WIDTH]; }; #endif
MMLUtility.mqh
#property strict #include <MMLDataStructs.mqh> // Import functions #import "MMLDataBridge.ex5" //Imports from the library directory // exported functions void initializeBridge_internal(string eaName); void shutdownBridge_internal(); // bool getRecordBytes_internal(const string csvFileName, uchar &out[]); // exported above string CStrFromCharArray(const char &arr[], int max_len = CHAR_FIELD_WIDTH); #import //Wrapper functions listed below // Purpose: Initializes the MML data bridge with the specified Expert Advisor name // Arguments: eaName - the name of the Expert Advisor to initialize the bridge for void initializeBridge(string eaName){ initializeBridge_internal(eaName); } // Purpose: Shuts down and cleans up the MML data bridge // Arguments: None void shutDownBridge() { shutdownBridge_internal(); } // Purpose: Converts a character array to a string // Arguments: arr[] - the character array to convert // Return value: string - the converted string value string CharArrayToStr(const char &arr[]) { return CStrFromCharArray(arr); } // Purpose: Pulls raw bytes from the bridge and maps them into a POD struct T // Arguments: FileName - the file name to retrieve data from, out - reference to the struct that will receive the mapped data // Return value: bool - true if the data was successfully retrieved and mapped, false otherwise template<typename T> bool returnData(const string FileName, T &out) { // Ask bridge for the raw bytes (bridge will size 'bytes' correctly) uchar bytes[]; if (!getRecordBytes_internal(FileName, bytes)) return false; const int need = sizeof(out); const int have = ArraySize(bytes); // Size mismatch means the struct doesn't match the data - fail to prevent reading corrupted data if (have != need) { if (have > need) { PrintFormat("MML Data Bridge: Struct size mismatch for '%s'", FileName); PrintFormat(" Your struct is missing %d byte(s) or has incorrect field types.", have - need); PrintFormat(" Solution: Add missing field(s) to your struct or check field data types"); return false; } else { PrintFormat("MML Data Bridge: Struct size mismatch for '%s'", FileName); PrintFormat(" This means your struct has %d extra byte(s) or incorrect field types", need - have); PrintFormat(" Solution: Remove extra field(s) from your struct or check field data types"); // If BIN has fewer bytes than struct, we can't fill it -> fail. return false; } } // Return true and map the bytes to the object return CharArrayToStruct(out, bytes, 0);


