Forex
Google
New signals service!

Go Back   Forex Trading > Discussion Areas > Metatrader 4


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 04-12-2006, 08:06 PM
Member
 
Join Date: Apr 2006
Posts: 53
freak is on a distinguished road
Can MQL use Database connection?

Is it possible to do that?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-12-2006, 08:21 PM
Beluck's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 196
Beluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud of
in MQL - not, in MQ4 - yes, with the help of DLL
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-13-2006, 09:18 AM
Member
 
Join Date: Apr 2006
Posts: 53
freak is on a distinguished road
Do you know more about it? Can you point me out what/where to look for more?

I'm PHP/MySQL programmist. Don't know anything about DLL programming...

I would appreciate any info.

Last edited by freak; 04-13-2006 at 09:27 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-13-2006, 09:41 AM
Member
 
Join Date: Apr 2006
Posts: 53
freak is on a distinguished road
All right! I've just found everything I need here MT4 Files Functions Replacement.

Cheers!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-13-2006, 07:57 PM
Beluck's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 196
Beluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud of
you don't need to program a DLL, you can use existing.
for example MySQL:

Code:
#import "libmysql.dll"
int mysql_init(int db);
int mysql_errno(int TMYSQL);
int mysql_real_connect( int TMYSQL,string host,string user,string password, string DB,int port,int socket,int clientflag);
int mysql_real_query(int TMSQL,string query,int length);
void mysql_close(int TMSQL);
#import
int mysql;
int init(){

//----

   mysql=mysql_init(mysql);
   if (mysql!=0) Print("allocated");
   string host="localhost";
   string user="user";
   string password="pwd";
   string DB="mt4";
   int clientflag=0;
   int port=3306;
   string socket="";
   int
res=mysql_real_connect(mysql,host,user,password,DB,port,socket,clientflag);
   int err=GetLastError();
   if (res==mysql) Print("connected");
   else Print("error=",mysql," ",mysql_errno(mysql)," ");
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   mysql_close(mysql);
//----
   return(0);
  }


int start()
  {
   string query="";
   int length=0;
      query=StringConcatenate("insert into ticks(margin,freemargin,date,ask,bid,symbol,equity) values(",AccountMargin(),",",AccountFreeMargin(),",\"",TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS),"\",",NormalizeDouble(Ask,4),",",NormalizeDouble(Bid,4),",\"",Symbol(),"\",",AccountEquity(),");");
      length=StringLen(query);
      mysql_real_query(mysql,query,length);
      int myerr=mysql_errno(mysql);
      if (myerr>0)Print("error=",myerr);

  }
hope this helps.
read also MySQL documentation for DLL usage.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-14-2006, 06:00 AM
Member
 
Join Date: Apr 2006
Posts: 53
freak is on a distinguished road
Yes! Thats what I was looking for. libmysql.dll - where can I get it from? Is it avy special version?

NOTE: I've just downloaded MySQL 5.0 pack from mysql.com and grab it from INSTALATION_DIR/bin/libmysql.dll

It works as a dream!

Thank you again!!!

Last edited by freak; 04-14-2006 at 07:53 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-14-2006, 08:18 AM
Beluck's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 196
Beluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud ofBeluck has much to be proud of
for libmysql.dll look in "lib" subfolder of your mysql installation.

there is one problem though as metatrader can get only scalar datatypes from DLLs.
DDL and DML SQL statements work just fine, but if you need to read something from database with SELECT, it is not so trivial as result is in memory as some structure, which can not be read in MQ4.
to override this I had to output query result to a file and then read it in MQ4:

Code:
int GetClientTrades() {
   FileDelete(queryFile);
   string query="SELECT * INTO OUTFILE \'"+queryPFile+"\' FIELDS TERMINATED BY \';\' LINES TERMINATED BY \'\n\'FROM clients_trades;";
   Print(query);
   int length=StringLen(query);
   mysql_real_query(mysql,query,length);
   int myerr=mysql_errno(mysql);
   if (myerr>0) Print("error=",myerr);

   int handle,res,size,i;
  	ArrayResize(clientTrades,0);
	handle=FileOpen(queryFile,FILE_CSV|FILE_READ);
	if(handle<1) {
   	Print("File " + queryFile + " not found, the last error is ", GetLastError());
   	return(0);
	}
	while (!FileIsEnding(handle)) {
		size++;
		ArrayResize(clientTrades,size);
		clientTrades[size-1][0]=FileReadNumber(handle);
		clientTrades[size-1][1]=FileReadNumber(handle);
		clientTrades[size-1][2]=FileReadNumber(handle);
		clientTrades[size-1][3]=FileReadNumber(handle);
		clientTrades[size-1][4]=FileReadNumber(handle);
		clientTrades[size-1][5]=FileReadNumber(handle);
		clientTrades[size-1][6]=FileReadNumber(handle);
		clientTrades[size-1][7]=FileReadNumber(handle);
		clientTrades[size-1][8]=FileReadNumber(handle);
		clientTrades[size-1][9]=FileReadNumber(handle);
	}
	ArrayResize(clientTrades,size-1);
	size--;
	//if (clientTrades[size-1][0]==0.0) ArrayResize(clientTrades,size-1);
	FileClose(handle);
   return(1);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-14-2006, 11:43 AM
Member
 
Join Date: Apr 2006
Posts: 53
freak is on a distinguished road
Great trick You are THE BIG MAN!!!

I'll be posting any feedback using it here. So stay tuned

Cheers!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-01-2007, 04:30 PM
Junior Member
 
Join Date: Feb 2007
Posts: 5
jbwyme is on a distinguished road
sorry to bring up an older thread but I have successfully connected and inserted data into a mysql database via the EA but I can't seem to figure out your code to SELECT data. I copied the function but it came up with a lot of errors.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-01-2007, 04:50 PM
Junior Member
 
Join Date: Feb 2007
Posts: 5
jbwyme is on a distinguished road
okay Ive gotten most of it to work but it can't find the output file since the code deletes it. How does the file get created after it is deleted?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-4/1670-can-mql-use-database-connection.html
Posted By For Type Date
mql - learn to trade forex swicki - powered by eurekster This thread Refback 07-31-2007 11:33 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange connection prasxz Metatrader 4 5 07-04-2008 10:14 AM
Ask about internet connection? OhYes Expert Advisors - Metatrader 4 1 11-20-2006 03:56 PM
No Connection mart-hart Metatrader 4 3 08-13-2006 05:52 AM
Using database connection in MQ freak Tools and utilities 5 04-13-2006 08:00 PM


All times are GMT. The time now is 10:24 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.