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 08-31-2009, 10:42 AM
Junior Member
 
Join Date: Aug 2009
Posts: 5
Pere Callahan is on a distinguished road
Dll doesn't work from MT4

Hi there,

I have a tiny question and I hope someone here will be able and willing to help me out.

The basic issue is using external functions in MT4 via a DLL. My basic problem is that it doesn't work but doesn't give any errors either.
So let me be more specific:

I used the MATLAB C++ Shared Library to convert an m-file into a DLL. That worked fine. Then I wrote, or rather copied, a wrapper dll, which converts my input to the format understood by the matlab dll.

Anyway I end up having a dll which is supposed to provide one function
Code:
double GetMaxEigenValue( double s1, double s2, double s3 )
I define the function as
Code:
__declspec(dllexport) double _stdcall GetMaxEigenValue( double s1, double s2, double s3)
This should be fine.
In my .def file I have
Code:
LIBRARY      "EV Arbitrage"
EXPORTS
			 GetMaxEigenValue
Ok. I then tried to test what I did so far by writing a simple c++ script which uses this function:
Code:
#include <iostream>
using namespace std;
double _stdcall GetMaxEigenValue(double s1, double s2, double s3); 
void main(void) 
{ 
	double Ret = GetMaxEigenValue(5.,2.,3.);
	cout << Ret;
}
This worked alright, giving me the impression that there is nothing wrong with my DLL.

However, now I tried to use the function from MQL4. SO that's what I did: I copied the dll, as well as the dll generated by matlab (not sure if that's necessary) into the experts/libraries folder, put the following script, "EV Arbitrage Library.mqh"
Code:
#import "EV Arbitrage.dll"
   //double GetMaxEigenValue( double Rates1[][6], int MaximumRecords1, double Rates2[][6], int MaximumRecords2, double Rates3[][6], int MaximumRecords3, int z );
   double GetMaxEigenValue( double s1, double s2, double s3);
#import
into the experts/include folder and tried the following in a Custom Indicator:
Code:
#include <EV Arbitrage Library.mqh>
...
Alert("before")
double val = GetMaxEigenValue(5.,2.,3.);
Alert("after");
Everything compiled just fine, but when I attached the indicator to a chart, it announced the first alert but not the second one. Everything behind the call to my dll seems to be geting evaluated.

I would appreciate any idea what I could be doing wrong If more code is needed I will provide it of course.

Thanks a lot
Pere
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 08-31-2009, 10:48 AM
Junior Member
 
Join Date: Aug 2009
Posts: 5
Pere Callahan is on a distinguished road
Two EDIT's: (I seem to not be allowed to edit my posts)

Of course, vverything behind the call to my dll seems to NOT be getting evaluated.

In my mql4 import section, the commented line was just another try I had, but can safely be ignored.

One idea I have, is the following:

When compiling the C++ script I had to link to the corresponding lib file. I didn't do that or something similar when calling the dll from mql4. (and wouldn't know how to anyway). Might that be the reason?

thanks again
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 08-31-2009, 11:40 AM
Senior Member
 
Join Date: Dec 2007
Posts: 492
Enforcer is on a distinguished road
Quote:
Originally Posted by Pere Callahan View Post
However, now I tried to use the function from MQL4. SO that's what I did: I copied the dll, as well as the dll generated by matlab (not sure if that's necessary)
If you linked mathlab.lib in your dll you must have it in your system.
However, put mathlab.dll in windows/system32 as it happens to me, whole thing wasn't working until I moved linked dll to system32.
(but buils your dll as static if possible)
check your experts tab to see if you get error 126 or error 127
Hope it helps.
__________________
www.signalcopy.com - Most advanced tools for copy Metatrader signals.
Free MT4 account statistics - advanced stats and graphs for MT4 accounts
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 08-31-2009, 01:59 PM
Junior Member
 
Join Date: Aug 2009
Posts: 5
Pere Callahan is on a distinguished road
Thank you very much for your response. I will try that later today.
So you think it's just about putting the *.lib file in the correct folder? Wouldn't we have to tell the mql4 compiler ( or linker if there is such a thing ) to actually look for it. Because when I compiled without the lib there was no error so apparently the mql compiler didn't expect to find it.. Am I right with this? I have to admit, my understanding of how these different compilers linkers, libraries and so on work together is rather limited.

I will keep you posted on the result of your suggestion.

Pere
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 08-31-2009, 02:27 PM
Senior Member
 
Join Date: Dec 2007
Posts: 492
Enforcer is on a distinguished road
Quote:
Originally Posted by Pere Callahan View Post
Thank you very much for your response. I will try that later today.
So you think it's just about putting the *.lib file in the correct folder? Wouldn't we have to tell the mql4 compiler ( or linker if there is such a thing ) to actually look for it. Because when I compiled without the lib there was no error so apparently the mql compiler didn't expect to find it.. Am I right with this? I have to admit, my understanding of how these different compilers linkers, libraries and so on work together is rather limited.

I will keep you posted on the result of your suggestion.

Pere
You have to put *.lib file only in linker. Mql compiler won't look for any *lib file.
Your dll will look for dll specified in linker. If your lib file is called mathlab.lib then you must have mathlab.dll in your sytem.
__________________
www.signalcopy.com - Most advanced tools for copy Metatrader signals.
Free MT4 account statistics - advanced stats and graphs for MT4 accounts
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 08-31-2009, 02:49 PM
Junior Member
 
Join Date: Aug 2009
Posts: 5
Pere Callahan is on a distinguished road
I see. I tried copying both dll's in the experts/library folder (without success), but I will try and put them in the system32 folder as well... even though for my test script it was enough to simply put the *.exe and the two dll's in the same folder.

Anyway I will be happy if the whole problem is simply about putting my files in the correct folder.
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 08-31-2009, 06:10 PM
Senior Member
 
Join Date: Dec 2007
Posts: 492
Enforcer is on a distinguished road
I don't know if is only a matter of correct folder... in library folder may or may not work, in system32 should work (dependencies to other system dlls - is OS is Vista check UAC or whatever is called Vista permissions system).
Check for errors in experts tab, create a simple function in your dll and call it from EA, put a alert window in your function to show result returned by that function.. well, some debug ideas...
__________________
www.signalcopy.com - Most advanced tools for copy Metatrader signals.
Free MT4 account statistics - advanced stats and graphs for MT4 accounts
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 09-01-2009, 09:22 PM
Junior Member
 
Join Date: Aug 2009
Posts: 5
Pere Callahan is on a distinguished road
It appears that it was the folder after all. I put the files in system32, and it went fine. Thanks for your help!
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 09-02-2009, 12:17 AM
Senior Member
 
Join Date: Dec 2007
Posts: 492
Enforcer is on a distinguished road
You're welcome.
__________________
www.signalcopy.com - Most advanced tools for copy Metatrader signals.
Free MT4 account statistics - advanced stats and graphs for MT4 accounts
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


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
will this work? stevenali Suggestions for Trading Systems 6 07-24-2007 03:19 PM
Need Help With EA that does not work shorttermtrader Metatrader 4 0 05-02-2007 02:55 PM
This Ea Really Work sps8 Expert Advisors - Metatrader 4 18 04-02-2007 09:30 PM
Help me!!!! Why this EA doesn't work???? metastock Expert Advisors - Metatrader 4 3 02-17-2007 06:31 AM
How does this really work? Ayo Questions 0 12-19-2005 03:30 PM


All times are GMT. The time now is 05:37 AM.



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