Download MetaTrader 5

Expert Advisors: Ask Bid Ticks

To add comments, please log in or register
Automated-Trading
Admin
101243
Automated-Trading  

Ask Bid Ticks:

"Ask Bid Ticks" stores all tick-by-tick data of ask and bid prices to a txt file. It uses local time with milliseconds for catching the time of each tick in high precision. You can use it for microstructure analysis, and see the real nature of market.

output

Author: Erdem Sen

Francisco Garcia Garcia
314
Francisco Garcia Garcia  
Automated-Trading:

Ask Bid Ticks:

Author: Erdem Sen

Interesting, How could you use it in backtesting? Any idea?
vanvolxem
18
vanvolxem  
Hello, can you equivalent in Bar M5 M15 H1 H4
Erdem Sen
1720
Erdem Sen  
vanvolxem:
Hello, can you equivalent in Bar M5 M15 H1 H4
i am sorry i couldn't understand, could you be more specific
vanvolxem
18
vanvolxem  

Hello,

 

Time                   Symbol OPEM   CLOSE   PH       PB    

2013.01.04 04:55 EURGBP 0.81065 0.81078 0.81086 0.81065 172

2013.01.04 05:00 EURGBP 0.81079 0.81046 0.81080 0.81044 90

2013.01.04 05:05 EURGBP 0.81047 0.81044 0.81056 0.81044 89

2013.01.04 05:10 EURGBP 0.81043 0.81059 0.81059 0.81033 111

2013.01.04 05:15 EURGBP 0.81057 0.81052 0.81059 0.81048 78

2013.01.04 05:20 EURGBP 0.81051 0.81065 0.81071 0.81050 124

2013.01.04 05:25 EURGBP 0.81067 0.81066 0.81070 0.81060 243

2013.01.04 05:30 EURGBP 0.81067 0.81076 0.81080 0.81063 108 

 

 

 

 


Erdem Sen
1720
Erdem Sen  
vanvolxem:

Hello,

Time                   Symbol OPEM   CLOSE   PH       PB    

2013.01.04 04:55 EURGBP 0.81065 0.81078 0.81086 0.81065 172

2013.01.04 05:00 EURGBP 0.81079 0.81046 0.81080 0.81044 90



The best way to get periodic data (according to me) is to use MT4 history, u can download and export (to excel) the historic data. but if u want a reedit of this code for periodic data, I think this will work for u:

//+------------------------------------------------------------------+
//|                                   PeriodicRealTimeDataStream.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

datetime t1;
double   arro[1],arrh[1],arrl[1],arrc[1];
string   T,O,H,L,C;
long     arrv[1],V;

//+------------------------------------------------------------------+
void OnTick()
  {  

   t1 = (datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE);
   static datetime  t0 = t1;
//--- obtain values for the specified chart     
   if (t0!=t1)
      {  
         //--- copy values to arrays
         CopyOpen(_Symbol,_Period,0,1,arro);
         CopyHigh(_Symbol,_Period,0,1,arrh);
         CopyLow(_Symbol,_Period,0,1,arrl);
         CopyClose(_Symbol,_Period,0,1,arrc);
         CopyTickVolume(_Symbol,_Period,0,1,arrv);
         //--
         T=TimeToString(t1,TIME_DATE|TIME_MINUTES);
         O=DoubleToString(arro[0],_Digits);
         H=DoubleToString(arrh[0],_Digits);
         L=DoubleToString(arrl[0],_Digits);
         C=DoubleToString(arrc[0],_Digits);
         V=arrv[0];
         //--- output the values
         printf("%s  %s  %s  %s  %s  %s  %d",T,_Symbol,O,H,L,C,V);
         //--- set the time again
         t0=t1;     
      }
//---
  }
//+------------------------------------------------------------------+

 

if u wish csv export, u can use the file functions and variables as in the main code  

Simon Gniadkowski
Moderator
18003
Simon Gniadkowski  
What about the ticks you miss ?  do you add anything into the TXT file for them ?  if you don't then you are not ". . .  stores all tick-by-tick data of ask and bid prices to a txt file."
Erdem Sen
1720
Erdem Sen  
RaptorUK:
What about the ticks you miss ?  do you add anything into the TXT file for them ?  if you don't then you are not ". . .  stores all tick-by-tick data of ask and bid prices to a txt file."

You're right there is a possibilty of missing quotes because of the way of NewTick event handling, but the code is fast enough to make this possibility  very small (almost zero). if missing ticks occur more than I thought (that can affect the significancy of analysis), then Ontick() is bugged, not my code.

and about that phrase ". . .  stores all tick-by-tick data of ask and bid prices to a txt file.", I had realised it a long time ago and changed it :) there is no "all" anymore, but in the forum it stayed same - sorry I have no ability to change it, i like reedit the comments but it's impossible for that phrase :(

Simon Gniadkowski
Moderator
18003
Simon Gniadkowski  
erdogenes:

You're right there is a possibilty of missing quotes because of the way of NewTick event handling, but the code is fast enough to make this possibility  very small (almost zero). if missing ticks occur more than I thought (that can affect the significancy of analysis), then Ontick() is bugged, not my code.

and about that phrase ". . .  stores all tick-by-tick data of ask and bid prices to a txt file.", I had realised it a long time ago and changed it :) there is no "all" anymore, but in the forum it stayed same - sorry I have no ability to change it, i like reedit the comments but it's impossible for that phrase :(

It's not a bug,  it's just how it works . . . if OnTick() is running when a neew tick arrives the new tick is ignored . . .

NewTick

The NewTick event is generated if there are new quotes, it is processed by OnTick() of Expert Advisors attached. In case when OnTick function for the previous quote is being processed when a new quote is received, the new quote will be ignored by an Expert Advisor, because the corresponding event will not enqueued.

All new quotes that are received while the program is running are ignored until the OnTick() is completed. After that the function will run only after a new quote is received.

  . . .  have you tested to see how many ticks you typically miss ?

Erdem Sen
1720
Erdem Sen  
RaptorUK:

It's not a bug,  it's just how it works . . . if OnTick() is running when a neew tick arrives the new tick is ignored . . .

I am confused, so you think it is the way of newtick handling and so do I:)

erdogenes:

You're right there is a possibilty of missing quotes because of the way of NewTick event handling

 

may be you misunderstood: if missing ticks has a significant effect on analysis then ontick is bugged, not normaly (because it is the "new tick" event handler, if it can't handle enough it is bugged) but i dont think it cant handle I dont think it is bugged.

 

RaptorUK: 

. . .  have you tested to see how many ticks you typically miss ?

 

I dont know about missing ticks, I obtain what program obtains, how can i calculate it? or can it be calculated somehow?, I cant know how many ticks that Ontick miss in a day (I am not developing mql5). I cant speak for MetaQuotes. I dont have a direct acces to a trading server to compare the feeds. I cant calculate it for a program, it wont be changed when the program is mine, I can speak only statistically.

for you, i have edit an example with HF data processing. I get the rate of tick arrivals in same millisecond with the interbank rates 27.01.2011- program for calculation is Gretl, codes you can use and data are sent by PM (I cant share that data publicly sorry). the result is ~0.003 (it is the rate of arrivals in same millisecond and it was an active day).

Lets assume that data is handled in MT5 and (absurdly) that all of them (~0.003) are missing. So, does a signal which randomly resapmled with a rate of ~0.003, loss any significancy? my answer is no. we use resampling with higher rates already in analysis.

Sure it was just hypothetical, and not from a broker, but I hope you will understand my point. And again, i dont have the ability to get the real number of missing ticks.

and one thing more: if it is the "no queue" policy of the NewTick event handler which cause the missing ticks  (and it is), then I think the number of missing ones may depend on your hardware speed, too. Then it cant be calculated as a astandart value.

(I reedit the comment: I fixed the code I sent to you, it was bugged, the real result is ~0.003 the code is enclosed) 

Files:
codes.zip 1 kb
Simon Gniadkowski
Moderator
18003
Simon Gniadkowski  
erdogenes:

I am confused, so you think it is the way of newtick handling and so do I:)

may be you misunderstood: if missing ticks has a significant effect on analysis then ontick is bugged, not normaly (because it is the "new tick" event handler, if it can't handle enough it is bugged) but i dont think it cant handle I dont think it is bugged.

I dont know about missing ticks, I obtain what program obtains, how can i calculate it? or can it be calculated somehow?, I cant know how many ticks that Ontick miss in a day (I am not developing mql5). 

Yes you can . . .  you can count the ticks as you see them for the current bar and check the value of the tick volume for the current bar,  when your count and the tick volume don't match then you have missed one or more ticks . . . 
12
To add comments, please log in or register