Unisciti alla nostra fan page
- Pubblicati da::
- Michael Schoen
- Visualizzazioni:
- 18145
- Valutazioni:
- Pubblicato:
- 2012.08.22 08:36
- Aggiornato:
- 2016.11.22 07:32
-
Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance
Accidently I ran into MQL5 and was forced to pull a MySQL library together. As for any library I hope the examples show how the library can be used. As for any library actually the most important things are examples how to use it ;)
Examples:
Reading Data
#include <EAX\EAX_Mysql.mqh> EAX_Mysql *db = new EAX_Mysql(); db.connect("myhost.mydomain.com", "myusername", "mypassword", "mydatabase", "mytable"); int iResults = db.read_rows("SELECT password, COUNT(*) as Hits FROM users GROUP BY password"); for (int i=0; i < iResults; i++) { string password = (string) db.get("password",i); int hits = (int) db.get("Hits", i); }
Feeding Data
#include <EAX\EAX_Mysql.mqh> // global EAX_Mysql *db = new EAX_Mysql(); void OnInit() { db.connect("myhost.mydomain.com", "myusername", "mypassword", "metatrader", "Ticks"; } void OnTick() { MqlTick tick; SymbolInfoTick(_Symbol,tick); // Add a new dataset for table Ticks db.AddNew("Ticks"); // fill it with values.. db.set("symbol", _Symbol); // You can send digits to digit DB fields if MySQL can convert db.set("ask", tick.ask); db.set("bid", tick.bid); db.set("last", tick.last); db.set("time", TimeToString(tick.time,TIME_DATE) + " " + TimeToString(tick.time,TIME_SECONDS)); db.set("volume", tick.volume); db.write(); } void OnDeinit() { // clean up memory delete db; }
Interacting with Data
EAX_Mysql *db = new EAX_Mysql(); db.connect("myhost.mydomain.com", "myusername", "mypassword", "metatrader", "mytable") // Select Table AgentsOnline (required to identify the correct Primary Key) db.select("AgentsOnline"); // Read Dataset with Primary Key 5 db.read("5"); // modify any column, db.set("lastupdate", (string) TimeLocal()); // write it back db.write();
Installing:
- Identify your MQL5 Data Directory (MQL5).
- Download Connector/C (libmysql) for your MetaTrader environment (32 or 64bit) and put libymsql.dll into "MQL5\Libraries".
- create an folder EAX under Include.
- Put EAX_Mysql.mqh in "MQL5\Include\EAX".
Issues:
- As it uses internally a shared connection pointer the library can't handle more than one DB connection at a time (I had no need to add/migrate a connection pooling).
- no real error (mysql) handling, dropping db connection.
- no error handling/reconnection to the DB (=> db pooling).
- no support for multiple column primary keys.
- still beta - please drop me an email if you want to beta/test.
- DataTypes are not handled (internally just strings) must be on code/database.
- Database communication is ISO - too lazy to adjust the pointer/string arithmetic for UTF-8.
Credits:
- http://mqlmagazine.com/mql-programming/mql5-connecting-to-mysql/
- https://www.mql5.com/en/articles/364
![ExtObjects](https://c.mql5.com/i/code/library.png)
Dedicated functions to read and write object properties.
![Momentum Color Fill](https://c.mql5.com/i/code/indicator.png)
The Momentum Technical Indicator measures the change of price of a financial instrument over a given time span.
![DaysOfWeekCheck](https://c.mql5.com/i/code/library.png)
The function is used to determine weekends on a server. It will be especially useful to those who use OnTimer() function in their Expert Advisors for events handling.
![OpenBuyPosition](https://c.mql5.com/i/code/script.png)
The script is developed for buying with fixed Stop Loss and Take Profit values in points from the current price.