0

I'm lookin for a solution, how to export currency exchange from metatrader (4 or 5) to web (json, csv, xml...)

I saw that it is possible export to excel file.

manlio
  • 18,345
  • 14
  • 76
  • 126
jasne
  • 53
  • 1
  • 11

2 Answers2

1

Online soft-RealTime export

MT4 can serve as anEventFACTORY process and send live-Quote(s) aka "Tick(s)" to further processing, be it internal ( via a function call ) or external ( via a ZeroMQ or nanomsg communication framework )

Architecture

MT4 has a default internal EventLOOP that triggers int start(){ <_code-block_> } upon each Quote arrival in both Expert Advisor and Custom Indicator. Besides that a Script can handle Quote arrivals on it's own near-RT loop with a use of bool RefreshRates()

Time Resolution

MT4 has rather a poor TimeDOMAIN resolution and can work down to about 1 msec via int GetTickCount()

Do-s & Don't-s

MT4 cannot run more than one Expert Advisor + one Script + a few Custom Indicators per MT4.Graph

MT4 threading is rather a fragile fabric to build any high-workload software

MT4 code inside MQL4 can block the whole "receiving engine" of the MT4 ( not speaking about MT4.TradingCONTEXT ... , so be carefull and place reasonable void Sleep( int msecs2sleep ) where not in an RT-sensitive part of any code.

Beware of Blocking

MT4 fileIO blocks, avoid as much as possible and if pressed to, cache and deferr disk write(s) to situations, where you are sure to have 15-40 msec "free-time" to rest in a fileIO-blocked <code-block> execution <state>. While this may seem funny on a first sight, this may hang your MT4 platform if you happen to arrange such "export" processing in a poor manner and MT4 threading model get beyond their MUTEX/LOCKs resilience treshold.

Does it sound like building a RealTime Software inside MetaTrader?

Yes.

Correct.

Verba docent. Exempla trahunt.

Try to use such an approach to use a thin-soft-RT-client inside MT4 and either cache-writes as MQL4 RT-scanners TAMARA & SONAR do, where you will see, that it soon takes several minutes (MINUTES) of a sustained-fileIO-write-s to store just a few majors on localhost disk ... , or better -- distribute locally collected data-chunks to a remote loggerPROCESS ( syslog alike ) or any other { online | offline } post-processing

Community
  • 1
  • 1
user3666197
  • 1
  • 6
  • 50
  • 92
0

You can create an EA to do that. I personally collect the rates (every tick) and push to an SQL server. Pushing to an SQL server is more tricky (I use a custom DLL to do that). But you can easily just append it to a csv or tab-delimited file. This will give you a tab-delimited file which you can import into Excel. But be warned that this can get really huge. Also, although there is a time element in there, the TimeCurrent() is accurate to the second only. To get accuracy down to milisecond, you will need something more tricky. But the rates will be appended in sequence.

int start()     {
    logRates();
    return(0);
}

void logRates( string pvsSymbol, double pviAsk, double pviBid ) {
    string  vsFilename  = "Rates (" + Symbol() + ") " + Month() + "-" + Day() + ".txt";
    int     handle      = FileOpen(vsFilename + ".txt", FILE_CSV|FILE_READ|FILE_WRITE, '\t');
    if(handle>0) {
        FileSeek(handle, 0, SEEK_END);
        FileWrite(handle, TimeCurrent(), pvsSymbol, pviBid, pviAsk);
        FileClose(handle);
    }
}
jlee88my
  • 2,935
  • 21
  • 28
  • ok , if I'll export 10 pairs to csv one and same file in every second. is it possible to read that file every second ? – jasne Jun 18 '13 at 07:21
  • yes you can. but in general, it is better to split each ccy to its own file. – jlee88my Jun 27 '13 at 04:59
  • @Joseph logging is possible, however at a cost of immense `fileIO` overhead, which makes it unusable in production-grade environment. Much better approach is to use a **thin-soft-RT-client** inside MT4 and either cache-writes as [MQL4 RT-scanners TAMARA & SONAR do](http://jonathan.mach.sweb.cz/DEMO/FxTOOLS_DEMO.html), where one should # **be aware** #, that it takes several minutes (**MINUTES**) of a `sustained-fileIO-write`-s to store just a few majors on disk ... , or distribute data-chunks to a remote logger ( **syslog** alike ) or even dispatch these to JSON or whatever forward processing – user3666197 Jun 13 '14 at 11:03