DLLs and passing control

 

Is there a way to call a function in a DLL file (I'm using C++) and let it run while MT4 retains control.

Specifically, it's for a tick collector. I would like the DLL to periodically write the logs to file, but I don't want to miss any incoming ticks during the open/write/close process.

If not, the only solution seems to be to have two windows open per symbol.. either that or don't care so much.

 
alladir:

Is there a way to call a function in a DLL file (I'm using C++) and let it run while MT4 retains control.

Specifically, it's for a tick collector. I would like the DLL to periodically write the logs to file, but I don't want to miss any incoming ticks during the open/write/close process.

If not, the only solution seems to be to have two windows open per symbol.. either that or don't care so much.

Why do you care about missing ticks ? you will anyway whatever you do . . . do you think you can capture all ticks ?
 

Not all, but if it's possible, why not get the highest resolution? It gives me confidence that I'm catching all but the briefest of prices.

I feel it's useful for my high-frequency EA backtesting, and perhaps detecting foul play by a broker.

 
alladir:

Not all, but if it's possible, why not get the highest resolution? It gives me confidence that I'm catching all but the briefest of prices.

I feel it's useful for my high-frequency EA backtesting, and perhaps detecting foul play by a broker.

Have you compared tick counts for different Brokers ?
 
Yes, but why? :)
 

If you need it fast, do not use DLL at all, the MQL script does it faster. Don't close or flush the file until deinit().

Saving tick data to a file buffer takes far less than a millisecond, so if you miss a tick it is not caused by the tick collector speed.

 

I would have thought so too, but I'm just comparing my old mql collector and the dll one is dropping fewer ticks.

It's more than just writing to buffer, there's a few checks if it's a genuine tick, so maybe that is slowing down the mql one.

 
alladir:
Yes, but why? :)
The number of ticks can vary from Broker to Broker hugely, if you use a Broker with lots of ticks you will miss more than if you pick a Broker with a low tick count . . . which one is more "correct" ? even if you don't care about the missing ticks you should at least know how many ticks you are routinely missing . . . if it's 1 or 2% it may not be a big deal to you, if it's 20% then it might be more of an issue . . . if you don't know you can't make that call.
 

Yes, sometimes I check with the ticks recorded per minute with the volume figure and it's about 5-10% dropped with this broker at peak times.

Any ideas on the original question?

@Ovo, actually after a bit more testing the dll is dropping more, but I'll keep on as the ticks collected are more realistic to what my EA (using dll) will receive. If MT4 can somehow retain control, all these issues will be solved.

Maybe I will try to figure out a way with 2 charts

 
alladir:

Yes, sometimes I check with the ticks recorded per minute with the volume figure and it's about 5-10% dropped with this broker at peak times.

Any ideas on the original question?

Regarding DLLs ? no . . .

Regarding this ?

. . . but I don't want to miss any incoming ticks during the open/write/close process.

it can't be done . . . you will always miss ticks.

 
RaptorUK:

Regarding DLLs ? no . . .

Regarding this ?

it can't be done . . . you will always miss ticks.

Ok thanks, but I will try a few more things to see if I can reduce dropped ticks a bit.

Just testing some things I found something surprising. This little script takes 10 whole seconds to do the 9999 iterations

void start() {

   int tick = GetTickCount();
   string log = "";
   
   //first time
   for(int x=0; x<9999; x++) log = StringConcatenate(log,DoubleToStr(Bid,Digits),",",DoubleToStr(Ask,Digits),",",DoubleToStr(Volume[0],0),"\n");
            //log = log+DoubleToStr(Bid,Digits)+","+DoubleToStr(Ask,Digits)+","+DoubleToStr(Volume[0],0)+"\n";
   
   Alert(GetTickCount()-tick);
   return;
}

I realise an average 1ms per iteration is nothing really but the dll does more operations and takes 0.5 secs to do 1,000,000 iterations.

EDIT: That's also faster than writing each tick's values straight to file with FileWrite (3 secs) or user32 (5 secs). That's with the file already open

Reason: