거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Telegram에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

EAX_Mysql - MySQL library - MetaTrader 5용 라이브러리

게시자:
Michael Schoen
조회수:
17837
평가:
(40)
게시됨:
2012.08.22 08:36
업데이트됨:
2016.11.22 07:32
eax_mysql.mqh (29.79 KB) 조회
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

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 ExtObjects

Dedicated functions to read and write object properties.

Momentum Color Fill Momentum Color Fill

The Momentum Technical Indicator measures the change of price of a financial instrument over a given time span.

DaysOfWeekCheck DaysOfWeekCheck

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 OpenBuyPosition

The script is developed for buying with fixed Stop Loss and Take Profit values in points from the current price.