MT4 Files

Check-in [4b1266837b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added dll related files
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:4b1266837b836257b377ac832631d423ff56a40e
User & Date: onagano 2010-12-13 07:23:14
Context
2010-12-13
09:04
Name changed from candle to bar check-in: adf2e94f61 user: onagano tags: trunk
07:23
Added dll related files check-in: 4b1266837b user: onagano tags: trunk
2010-11-22
08:56
Imported my .mq4 files check-in: 47b6dcdf38 user: onagano tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added experts/include/mt4odbcbridge.mqh.





































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//+------------------------------------------------------------------+
//|                                                mt4odbcbridge.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

//+------------------------------------------------------------------+
//| defines                                                          |
//+------------------------------------------------------------------+
// #define MacrosHello   "Hello, world!"
// #define MacrosYear    2005

//+------------------------------------------------------------------+
//| DLL imports                                                      |
//+------------------------------------------------------------------+
#import "MT4ODBCBridge.dll"
int      MOB_create();
void     MOB_open(int conId, string dsn, string username, string password);
void     MOB_close(int conId);
void     MOB_execute(int conId, string sql);
int      MOB_getLastErrorNo(int conId);
string   MOB_getLastErrorMesg(int conId);
int      MOB_prepareStatement(int conId, string sql);
int      MOB_insertTick(int conId, int stmtId, datetime dt, int millis, double vals[], int size);
int      MOB_insertCandle(int conId, int stmtId, datetime dt, double vals[], int size);
double   MOB_selectDouble(int conId, string sql, double defaultVal);
int      MOB_selectInt(int conId, string sql, int defaultVal);
datetime MOB_selectDatetime(int conId, string sql, datetime defaultVal);
#import

//+------------------------------------------------------------------+
//| EX4 imports                                                      |
//+------------------------------------------------------------------+
// #import "stdlib.ex4"
//   string ErrorDescription(int error_code);
// #import


//+------------------------------------------------------------------+
//| Global variables                                                 |
//+------------------------------------------------------------------+
int conId;

//+------------------------------------------------------------------+
//| Functions                                                        |
//+------------------------------------------------------------------+

void db_create() {
   conId = MOB_create();
}

void db_open(string dsn, string username, string password) {
   MOB_open(conId, dsn, username, password);
}

void db_close() {
   MOB_close(conId);
}

void db_execute(string sql) {
   MOB_execute(conId, sql);
}

int db_getLastErrorNo() {
   return (MOB_getLastErrorNo(conId));
}

string db_getLastErrorMesg() {
   return (MOB_getLastErrorMesg(conId));
}

int db_prepareStatement(string sql) {
   return (MOB_prepareStatement(conId, sql));
}

int db_insertTick(int stmtId, datetime dt, int millis, double vals[]) {
   return (MOB_insertTick(conId, stmtId, dt, millis, vals, ArraySize(vals)));
}

int db_insertCandle(int stmtId, datetime dt, double vals[]) {
   return (MOB_insertCandle(conId, stmtId, dt, vals, ArraySize(vals)));
}

double db_selectDouble(string sql, double defaultVal) {
   return (MOB_selectDouble(conId, sql, defaultVal));
}

int db_selectInt(string sql, int defaultVal) {
   return (MOB_selectInt(conId, sql, defaultVal));
}

datetime db_selectDatetime(string sql, datetime defaultVal) {
   return (MOB_selectDatetime(conId, sql, defaultVal));
}

//+------------------------------------------------------------------+

Added experts/insertCandle.mq4.





































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//+------------------------------------------------------------------+
//|                                                 insertCandle.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

#include <mt4odbcbridge.mqh>

int insertCandle;
datetime lastTime;

//---- input parameters
extern int       ExtParam1;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if (!IsDllsAllowed()) {
      Alert("ERROR: [Allow DLL imports] NOT Checked.");
      return (0);
   }

   db_create();
   logIfError("db_create failed");
   
   db_open("testmysql", "onagano", "password");
   logIfError("db_open failed");
   
   string table = Symbol() + "_" + Period();
   db_execute("create table if not exists " + table + " ("
				  + "time datetime,"
				  + "open double,"
				  + "high double,"
				  + "low double,"
				  + "close double,"
				  + "vol double"
				  + ")"); 
	logIfError("Cannot create " + table);
	
	insertCandle = db_prepareStatement("insert into " + table + " values (?, ?, ?, ?, ?, ?)");
	logIfError("Cannot prepare insert " + table);
	
	lastTime = TimeCurrent();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   db_close();
   logIfError("db_close failed");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   int i = 1;
   datetime dt = Time[i];
   if (lastTime < dt) {
      lastTime = dt;
      
      double candleData[5];
      candleData[0] = Open[i];
      candleData[1] = High[i];
      candleData[2] = Low[i];
      candleData[3] = Close[i];
      candleData[4] = Volume[i];
   
      db_insertCandle(insertCandle, dt, candleData);
      logIfError("Insert candle failed");
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

void logIfError(string mesg) {
   int eno = GetLastError();
   if (eno != 0) {
      Print("ERROR (", eno, "): ", mesg);
   }
   int dbeno = db_getLastErrorNo();
   if (dbeno != 0) {
      Print("DB ERROR (", dbeno, "): ", db_getLastErrorMesg());
   }
}

Added experts/insertTick.mq4.













































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//+------------------------------------------------------------------+
//|                                                   insertTick.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

#include <mt4odbcbridge.mqh>

int insertTick;

//---- input parameters
extern int       ExtParam1;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if (!IsDllsAllowed()) {
      Alert("ERROR: [Allow DLL imports] NOT Checked.");
      return (0);
   }

   db_create();
   logIfError("db_create failed");
   
   db_open("testmysql", "onagano", "password");
   logIfError("db_open failed");
   
   string tickTable = Symbol() + "_TICK";
   db_execute("create table if not exists " + tickTable + " ("
				  + "time datetime,"
				  + "msec int,"
				  + "ask double,"
				  + "bid double"
				  + ")"); 
	logIfError("Cannot create " + tickTable);
	
	insertTick = db_prepareStatement("insert into " + tickTable + " values (?, ?, ?, ?)");
	logIfError("Cannot prepare insert " + tickTable);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   db_close();
   logIfError("db_close failed");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   datetime dt = TimeCurrent();
   int millis  = GetTickCount() % 1000;
   double tickData[2];
   tickData[0] = Ask;
   tickData[1] = Bid;
   
   db_insertTick(insertTick, dt, millis, tickData);
   logIfError("Insert tick failed");
//----
   return(0);
  }
//+------------------------------------------------------------------+

void logIfError(string mesg) {
   int eno = GetLastError();
   if (eno != 0) {
      Print("ERROR (", eno, "): ", mesg);
   }
   int dbeno = db_getLastErrorNo();
   if (dbeno != 0) {
      Print("DB ERROR (", dbeno, "): ", db_getLastErrorMesg());
   }
}

Added experts/scripts/testExpertSample.mq4.































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//+------------------------------------------------------------------+
//|                                             testExpertSample.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

#import "ExpertSample.dll"
int    GetIntValue         (int i);
double GetDoubleValue      (double d);
string GetStringValue      (string s);
double GetArrayItemValue   (double  arr[], int size, int index);
bool   SetArrayItemValue   (double& arr[], int size, int index, double val);
double GetRatesItemValue   (double rates[][6], int size, int shift, int tohlcv);
int    SortStringArray     (string& arr[], int size);
int    ProcessStringArray  (string& arr[], int size);
#import

#define TIME_INDEX   0
#define OPEN_INDEX   1
#define LOW_INDEX    2
#define HIGH_INDEX   3
#define CLOSE_INDEX  4
#define VOLUME_INDEX 5

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   if (!IsDllsAllowed()) {
      Alert("ERROR: [Allow DLL imports] NOT Checked.");
      return (0);
   }
//----
   double ret, some_value = 10.5;
   string sret;
   int    cnt, i, j;
   string strarray[6] = {"first", "second", "third", "fourth", "fifth"};

//---- simple dll-functions call
   cnt = GetIntValue(some_value);
   Print("Returned value is ", cnt);
   
   ret = GetDoubleValue(some_value);
   Print("Returned value is ", ret);
   
   sret = GetStringValue("some string");
   Print("Returned value is ", sret);

//----
   cnt = SortStringArray(strarray, ArraySize(strarray));
   Print("SortStringArray done.");
   for(i = 0; i < cnt; i++)
      Print(i, " - ", strarray[i]);

   // Useless unless the length of string becomes larger than actural.   
   cnt = ProcessStringArray(strarray, ArraySize(strarray));
   Print("ProcessStringArray done.");
   for(i = 0; i < cnt; i++)
      Print(i, " - ", strarray[i]);
//----


//----
   double price;
   double arr[5] = {1.5, 2.6, 3.7, 4.8, 5.9};
   double rates[][6];
   
//---- get first item from passed array
   price = GetArrayItemValue(arr, 5, 0);
   Print("Returned from arr[0] ", price);

   for (i = 0; i < 5; i++)
      Print("Dump arr[", i, "]: ", arr[i]);
   
//---- change second item in the passed array
   if(SetArrayItemValue(arr, 5, 1, 1234.5) == true)
      Print("Changed to ", arr[1]);
   
   for (i = 0; i < 5; i++)
      Print("Dump arr[", i, "]: ", arr[i]);
   
//---- get current close
   ArrayCopyRates(rates);
   price = GetRatesItemValue(rates, Bars, 0, CLOSE_INDEX);
   Print("Returned from Close ", price);   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Added experts/scripts/testMT4ODBCBridge.mq4.









































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//+------------------------------------------------------------------+
//|                                            testMT4ODBCBridge.mq4 |
//|                                                     Osamu Nagano |
//|                   http://www.google.com/profiles/onagano.g#about |
//+------------------------------------------------------------------+
#property copyright "Osamu Nagano"
#property link      "http://www.google.com/profiles/onagano.g#about"

#include <mt4odbcbridge.mqh>

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   if (!IsDllsAllowed()) {
      Alert("ERROR: [Allow DLL imports] NOT Checked.");
      return (0);
   }
   
   db_create();
   logIfError("create failed");
   
   db_open("testmysql", "onagano", "password");
   logIfError("open failed");
   
   int ti = db_selectInt("select count(*) from eurjpy_1", -1);
   Print("Count: ", ti);
   
   double td = db_selectDouble("select open from eurjpy_1 order by time", -1);
   Print("Double: ", td);
   
   datetime tt = db_selectDatetime("select time from eurjpy_1 order by time desc", TimeCurrent());
   Print("Datetime: ", TimeToStr(tt));
   Print("Datetime: ", TimeToStr(tt + 9 * 3600));
   Print("Current : ", TimeToStr(TimeCurrent()));

   db_close();
   logIfError("close failed");
//----
   return(0);
  }
//+------------------------------------------------------------------+

void logIfError(string mesg) {
   int eno = GetLastError();
   if (eno > 0) {
      Print("ERROR (", eno, "): ", mesg);
   }
}