Forex



Go Back   Forex Trading > Discussion Areas > Metatrader 4
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 04-12-2006, 09: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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 04-12-2006, 09:21 PM
Beluck's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 207
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 04-13-2006, 10: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 10:27 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 04-13-2006, 10: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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 04-13-2006, 08:57 PM
Beluck's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 207
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 04-14-2006, 07: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 08:53 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 04-14-2006, 09:18 AM
Beluck's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 207
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #8 (permalink)  
Old 04-14-2006, 12:43 PM
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #9 (permalink)  
Old 02-01-2007, 05: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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #10 (permalink)  
Old 02-01-2007, 05: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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
mysql


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
Forum Jump

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


All times are GMT. The time now is 03:53 PM.



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