Forex



Go Back   Forex Trading > Training > Metatrader > Metatrader 4 mql 4 - Development course
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
  #21 (permalink)  
Old 03-29-2008, 03:41 PM
Mistigri's Avatar
Member
 
Join Date: Mar 2006
Posts: 34
Mistigri is on a distinguished road
Quote:
Originally Posted by prasxz View Post
is it possible make mt4 dll connected to web service and make php script to shows MT4 open position through a website , so people with no MT4 can see it from website in a realtime ?
Someone posted a while ago a MQL / MySQL example which worked great, the only issue with it is that most hosting companies do not allow remote access to their database servers. However if you did have full access and control to your server you would write an EA which would connect to your database and insert the data for each new order. Then from your website simply connect to the database and read the data ... In my opinion this would be the best approach.

Now a MT4 DLL can connect to a php script but I have never tried to pass the information from the EA to the Website, I was able to successfully do it the other way around though ... You would have to look into windows sockets, and functions such as HTTP_GET / HTTP_POST.

Patrick

Last edited by Mistigri; 04-18-2009 at 06:16 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
  #22 (permalink)  
Old 03-29-2008, 06:22 PM
Mistigri's Avatar
Member
 
Join Date: Mar 2006
Posts: 34
Mistigri is on a distinguished road
How about something a little easier, using the FTP function in MT4

Set your FTP settings in Metatrader under Tools / Options / Publisher.

Then write an EA with something like this:

PHP Code:
//+------------------------------------------------------------------+
//|                                             MistigriFX - OOW.mq4 |
//|                                Copyright © 2008, Patrick Nouvion |
//|                                        http://www.mistigrifx.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Patrick Nouvion"
#property link      "http://www.mistigrifx.com"

//+------------------------------------------------------------------+
//| GlobalVars                                                       |
//+------------------------------------------------------------------+
string FileName "";
datetime CurrTime 0;
datetime PrevTime 0;
//+------------------------------------------------------------------+
//| expert init / deinit                                             |
//+------------------------------------------------------------------+
int init()   

   
FileName StringConcatenateAccountNumber(), "-Trades.php" ); 
   
CurrTime iTimeSymbol(), 1);
   
PrevTime iTimeSymbol(), 1);
   
//----
   
return(0); 
}
int deinit() { return(0); }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   
//----
   
CurrTime iTimeSymbol(), 1);
   if( 
CountAll() != && CurrTime != PrevTime )   
   {
         
int H1 FileOpenFileName FILE_CSV|FILE_READ|FILE_WRITE',' );
         if( 
H1 ) { AlertGetLastError() ); return(-1); }
         for( 
int i 0OrdersTotal(); i++ )
         {
            
OrderSelectiSELECT_BY_POSMODE_TRADES );
            
string Data StringConcatenateOrderSymbol()," "OrderLots(), " "OrderProfit() );
            
FileWriteH1Data );
            
FileWriteH1"<br />");
         }
         
FileCloseH1 );
         
//----
         
if( !SendFTP(FileName) ) { Print( GetLastError() ); }
         
PrevTime CurrTime;
   }
   
//----
   
   
return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//                              CountAll                             |
//+------------------------------------------------------------------+
int CountAll()
{
   
int count=0;
   for(
int i OrdersTotal()-1>=0i--)
   {
      
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      
int OrdMag OrderMagicNumber();
      
int OrdNum OrderTicket();
   
           if( 
OrderType() == OP_BUY  ) { count++; }
      else if( 
OrderType() == OP_SELL ) { count++; }
   }
 return(
count);
}
//+------------------------------------------------------------------+ 
On your website write a php page with something like this:

PHP Code:
<div id="bodyPan">
<h2>View Trades</h2>

<?php
$AccountPost 
0;
 
$AccountGet 0;
$Account 0;
$AccountPost $_POST['Account'];
 
$AccountGet $_GET['Account'];

if( 
$AccountPost != || $AccountGet != )
{
    if( 
$AccountPost != ) { $Account $AccountPost; }
    else              { 
$Account $AccountGet; }

    echo 
"<p>Account #: $Account </p>";
    
$FileSta "./OOW/";
    
$FileEnd "-Trades.php";
    
$myFile $FileSta $Account $FileEnd;
    
$fh fopen($myFile'r');
    
$theData fread($fhfilesize($myFile));
    
fclose($fh);
    echo 
"<p>";
    echo 
$theData;
    echo 
"</p>";
}
else
{
?>

<p>
<form name="ViewTrades" method="post" action="">
<label stle="margin-top: 5px;">Account:</label>
<input style="margin-top: 11px; margin-left: 15px;" type="text" name="Account" value="0" />
<input class="submit" type="submit" name="submit" value="Submit" style="background-color: #ffffff; margin-left: 100px; margin-top: 18px;" />
</form>
</p>

<?php
}
?>

</div>
Notice that I upload the file to a OOW folder ... You would obviously have to change that, but in the end the file would be uploaded every minute.

For an example Go to this link : MistigriFx - View Trades
Enter 123456 for the account number or Click on MistigriFx - View Trades?Account=123456

Patrick

Last edited by Mistigri; 03-29-2008 at 06:29 PM.
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
  #23 (permalink)  
Old 03-30-2008, 12:59 AM
Junior Member
 
Join Date: Mar 2007
Location: Copenhagen
Posts: 6
Magick is on a distinguished road
Thanks Patrick

thats a very interesting idea to use the FTP.

however I do want to be able to interact with MT - to send the tick and candle info to the .net app and this app communicate back to MT on when to trade.

I found this that I thought may help - Simplified Wrapper and Interface Generator
However I am a rather entry level programmer, and dont fully appreciate what is involved in having a c++ wrapper middle layer.

I would be interested to hear your opinion, if you think this could be a useful tool to use to help bridge between the c++ and .net?
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
  #24 (permalink)  
Old 03-31-2008, 03:16 PM
Mistigri's Avatar
Member
 
Join Date: Mar 2006
Posts: 34
Mistigri is on a distinguished road
You can certainly wrap a c# dll and get it to receive signals on MT4, however I am not sure about sending the price data from MT4 to the C# app/dll and how reliable it would be ... I don't really have time to investigate right now ( going on vacation next week and have to finish some projects :P ) but I will certainly try to look into that in the next few months

Good Luck with your project!
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
  #25 (permalink)  
Old 05-23-2008, 06:42 PM
Member
 
Join Date: Aug 2006
Posts: 97
bwilhite is on a distinguished road
Really a C++ question...external DLL for MT4

Hi all,

I have an external DLL that I've written in C++. However, I'm still quite new to C++, so I think that might be why I'm having this problem. I have another version I've written in C# that works fine, except to make C# DLLs callable by MQL I have to alter them, and this alteration appears to cause small memory leaks. I'm hoping someone here can help me out with the C++ version. Here's the story:

I've been slowly developing various libraries for programming trading strategies. One of the things I'm trying to do is develop a consistent set of services for various things like logging, locking (thread-safe access to resources), and event notification. So basically, I'm trying to pull MQL up by its bootstraps into a more modern programming paradigm. Anyway, currently I'm working on a library that will allow EAs to receive notification of various trade events (placed, filled, closed). These events could be as a result of trades taken by the event-subscribing EA or from other EAs. To accomplish this, I'm using an external DLL that basically facilitates communication between EAs via message passing. There is a publishing EA that just looks for new trade events and when one occurs, it puts a message onto a queue for the subscribing EA (each subscriber has its own queue).

So the problem is this...As long as it's only one message being passed at a time, all works fine. Obviously that's not acceptable at all though. When more than one message is passed at a time, what I'm finding is that the first message gets corrupted (it keeps returning the message as "1" when instead it should be something like "FILLED,1005167"). The second message is fine, but the first is not. I haven't tested more than two messages yet, but presumably we'd still see the same thing.

I'd love it if someone knew the answer to what it is I'm doing wrong and could shed some light on my problem. A few notes: 1) I'm eventually going to be releasing this code under Apache 2.0 and so this source file is also being put out there under Apache 2.0...I intend to release this to the community when it's working fairly smoothly. 2) I've repeatedly said 'queue' here, but if you look at the source code you'll see me using a vector instead, and basically using it like a stack. Originally I had a queue, but changed it to a vector just on the off-chance that I was doing something wrong with the STL queue that I wasn't aware of. No such luck. The real implementation will be a queue, but for now neither queue nor vector are working correctly for me.

Thanks in advance for any insight.

Brandon Wilhite
Attached Files
File Type: zip MqlServices.zip (2.0 KB, 125 views)

Last edited by bwilhite; 05-23-2008 at 08:53 PM.
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
  #26 (permalink)  
Old 05-23-2008, 09:04 PM
Member
 
Join Date: Aug 2006
Posts: 97
bwilhite is on a distinguished road
Since I was here, I thought I'd share my experience. What you are wanting to do can certainly be done, and I've done it many times myself.

When I first started writing DLLs for use in MT4 I couldn't ever get it to work in C++. I think the problem was/is that my project settings were always incorrect in Visual Studio (there's so d@$% many of them). Just recently I found an example from CodeGuru, which I was actually able to compile and use. Now I basically cleaned out that project and use it as a template.

In the meantime, I've been writing C# DLLs and using this excellent tool here. It basically takes the IL and alters it so that it can be called from unmanaged code. The only problem is that MT4 seems to exhibit a memory leak when doing this. I haven't definitively determined if that's due to MT4 or the altering of the IL, or what, but it happens.

Next I'll either be learning to write wrappers on C++ and/or just go ahead and learn C++. Hopefully that will address the memory issue.

Anyway, what you are wanting to do can definitely be accomplished. I've managed to write some pretty complicated DLLs for MT4 in C#, including things like remoting, raw sockets, http, WinForms. Pretty much anything you can do with .NET can be called from MT4 this way (you name it, and I've probably done it). And it's very reliable. The only problem is the relatively slow memory leak.

Quote:
Originally Posted by Magick View Post
Thanks Patrick

thats a very interesting idea to use the FTP.

however I do want to be able to interact with MT - to send the tick and candle info to the .net app and this app communicate back to MT on when to trade.

I found this that I thought may help - Simplified Wrapper and Interface Generator
However I am a rather entry level programmer, and dont fully appreciate what is involved in having a c++ wrapper middle layer.

I would be interested to hear your opinion, if you think this could be a useful tool to use to help bridge between the c++ and .net?
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
  #27 (permalink)  
Old 05-29-2008, 09:18 PM
Junior Member
 
Join Date: Mar 2007
Location: Copenhagen
Posts: 6
Magick is on a distinguished road
Quote:
Originally Posted by bwilhite View Post
Since I was here, I thought I'd share my experience. What you are wanting to do can certainly be done, and I've done it many times myself.

When I first started writing DLLs for use in MT4 I couldn't ever get it to work in C++. I think the problem was/is that my project settings were always incorrect in Visual Studio (there's so d@$% many of them). Just recently I found an example from CodeGuru, which I was actually able to compile and use. Now I basically cleaned out that project and use it as a template.

In the meantime, I've been writing C# DLLs and using this excellent tool here. It basically takes the IL and alters it so that it can be called from unmanaged code. The only problem is that MT4 seems to exhibit a memory leak when doing this. I haven't definitively determined if that's due to MT4 or the altering of the IL, or what, but it happens.

Next I'll either be learning to write wrappers on C++ and/or just go ahead and learn C++. Hopefully that will address the memory issue.

Anyway, what you are wanting to do can definitely be accomplished. I've managed to write some pretty complicated DLLs for MT4 in C#, including things like remoting, raw sockets, http, WinForms. Pretty much anything you can do with .NET can be called from MT4 this way (you name it, and I've probably done it). And it's very reliable. The only problem is the relatively slow memory leak.
bwilhite you are a life saver! That looks like a great tool. Do you, by chance, have a c# project that demonstrates communicating with MT from C#? What I am wanting to do is have my .net app tell MT when to trade. Or perhaps you can recommend a link that could help. Any help would be greatly appreciated.
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
  #28 (permalink)  
Old 08-06-2008, 09:34 AM
Senior Member
 
Join Date: Mar 2006
Posts: 310
vladv is on a distinguished road
Many many thanks!
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
  #29 (permalink)  
Old 08-21-2008, 10:58 AM
Junior Member
 
Join Date: Jan 2008
Posts: 8
Latino is on a distinguished road
Dll

Hi ,

Can the DLL be used to send and receive orders via an excel spreadsheet?
Where can i learn this aspect of the DLL.

Kind Regards

Latino
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
  #30 (permalink)  
Old 09-20-2008, 04:14 AM
Junior Member
 
Join Date: Sep 2008
Posts: 17
RealFx is on a distinguished road
Quote:
Originally Posted by codersguru View Post
Anybody interested in creating his/her own MetaTrader extension (dll) may go to:

Create your own MetaTrader extension (dll) - Part 1
Create your own MetaTrader extension (dll) - Part 2

There'll be another part (or 2) which I'm writing them!

Hope you enjoy them!

Please, update your course to Visual C++ 2008 Express Edition
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
c# metatrader, dll, dll forex, dll metatrader, dll mt4, ExpertSample.dll, file, FILE EXTENSION EX4, forex, internet, metatrader, metatrader c# DLL, metatrader dll, metatrader socket, metatrader sockets, MistigriFX, mql dll, mt4 dll


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
How do I use the files with .ex4 extension. NEEL123 General Discussion 6 12-19-2008 09:35 AM
About Fibo extension phildunn General Discussion 11 03-30-2008 01:31 PM
there is any script/program to create walk forward test data for metatrader???? giraia_br Metatrader 4 1 03-26-2007 01:44 AM
Please create an EA matrixebiz Expert Advisors - Metatrader 4 0 11-28-2006 08:19 PM


All times are GMT. The time now is 08:11 AM.



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