New article How to Access the MySQL Database from MQL5 (MQL4) has been published:
Author: Eugeniy Lugovoy
Hi Eugeniy Lugovoy,
Firstly, thank you for taking the time to make this project.
I've been looking for weeks on how to import/update all the open/closed trades from a trading account into a MySQL table, if possible realtime. is there a way to do this using your library?
Many thanks in advance.
Hi Amy. It's great, I had no time to do it by myself. So, if that's alright by you, can you share sources with community?
Hello to everyone!
Unfortunately, I have no time to support this project and to spend time in community, so All My Dears forgive me unanswered questions and my silence.
But I see some experienced people here which can help to others and it's really great.
Thank you all for using my library, extending its functionality and getting your own experience.
Good luck to all with your projects!
Sure, you can build EA using this library to insert data into your Mysql database and keep them up to date (close to realtime update).
Pay attention, that closed orders in MT4/5 available programmatically only when they listed in History tab. So, if you set the filter in History 3 recent days - you can access only trades processed in that period.
It's not depended on this library, it's just MQL-MT4 infrastructure.
Awesome work again as this was very simple to get working.
Curious, have you or anyone else here tried to get this working on the Strategy Tester? I've evolved the script onto an indie in the live environment and all is OK, but no luck integrating in a backtesting envionment.
Sorry for late response. Here is what i did with your code. I just modified one function cMySqlGetRowField to use MultiByteToWideChar. The original code is commented for compare.
// return string representation of field's value
// should be called after MySqlCursorFetchRow()
// pCursorID - CURSOR IDENTIFIER
// pField - number of field from SELECT list (started from 0) - 0,1,2 e.t.c.
MT4_EXPFUNC wchar_t* __stdcall cMySqlGetRowField(int pCursorID, unsigned int pField)
if ((pCursorID >= 0) && (pCursorID < MAX_CURSORS) && (Cursors[pCursorID].Id!=-1))
if ((pField >= 0) && (pField < mysql_num_fields(Cursors[pCursorID].RecordSet)))
int unicodeLen = MultiByteToWideChar(CP_UTF8, 0, Cursors[pCursorID].CurrentRow[pField], -1, nullptr, 0);
MultiByteToWideChar(CP_UTF8, 0, Cursors[pCursorID].CurrentRow[pField], -1, Cursors[pCursorID].Value, unicodeLen);
//sprintf_s(Cursors[pCursorID].Value, "%s", Cursors[pCursorID].CurrentRow[pField]);
//swprintf(Cursors[pCursorID].Value, 1024, L"%S", Cursors[pCursorID].CurrentRow[pField]);
Cursors[pCursorID].CursorErrorNumber = -4;
swprintf(Cursors[pCursorID].CursorErrorDescription, 32, L"Wrong number of field.\x00");
CursorErrorNumber = -5;
swprintf(CursorErrorDescription, 32, L"Wrong CURSOR identifier.\x00");
Thanks your guys are great. I tried your code .Don't forget includ widechar head, or it'll not work.
Hi I have loaded dll in Libraries folder but it report an error " "Cnnot call 'cMySqlVersion', '....\Libraries\MQLMySQL.dll' is not loaded
How is it possible?
I have the same issue than you.
Using MT5 with Windows 10 - 64bits.