Download MetaTrader 5
To add comments, please log in or register
Deposit to your account in any convenient way. There are 4 of them here!
Jon Grah
367
Jon Grah 2014.02.06 14:55 

For mt4 build 509, I implemented the following code so that I could print the bid, ask, and volume of each incoming tick on a backtest or in live trading.

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   Print( DoubleToStr( Ask, Digits ), " ", DoubleToStr( Bid, Digits ), " ", DoubleToStr( Volume[0], Digits ), " " );
   return(0);
  }
//+------------------------------------------------------------------+

on dukascopy tick data using Birt's csv2fxt with UseRealSpreads=true and this is the output (for 1 second of data)

21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67923 1.67885 0.00038 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67923 1.67880 0.00043 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67922 1.67880 0.00042 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67916 1.67880 0.00036 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67914 1.67881 0.00033 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67922 1.67887 0.00035 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67922 1.67889 0.00033 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67919 1.67892 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67922 1.67892 0.00030 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67922 1.67895 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67920 1.67893 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67918 1.67893 0.00025 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67921 1.67893 0.00028 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67927 1.67893 0.00034 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67921 1.67894 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67917 1.67894 0.00023 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67921 1.67894 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67919 1.67891 0.00028 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67917 1.67891 0.00026 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67916 1.67891 0.00025 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67917 1.67888 0.00029 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67917 1.67893 0.00024 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67917 1.67890 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67915 1.67890 0.00025 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67916 1.67888 0.00028 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67913 1.67888 0.00025 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67903 1.67888 0.00015 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67910 1.67888 0.00022 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67913 1.67888 0.00025 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67919 1.67888 0.00031 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67916 1.67889 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67918 1.67891 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67919 1.67893 0.00026 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67926 1.67893 0.00033 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67936 1.67893 0.00043 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67934 1.67894 0.00040 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67932 1.67897 0.00035 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67923 1.67897 0.00026 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67932 1.67897 0.00035 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67928 1.67901 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67926 1.67899 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67927 1.67900 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67924 1.67900 0.00024 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67926 1.67897 0.00029 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67925 1.67893 0.00032 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67921 1.67893 0.00028 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67920 1.67893 0.00027 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67919 1.67890 0.00029 
21:28:56 2013.11.04 23:59  TickPrinter509 GBPAUD,M1: 1.67921 1.67892 0.00029 

This is correct behavior. It shows the bid/ask/and volume to floating point precision. The volume stores the variable spread, but that was done when using the csv2fxt 0.43.

but now check out the revised code to compile in mt4 build 600:

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//----
   
//----
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//----
   
//----
   return;
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void OnTick()
  {
   if ( Volume[0] < 0 )
      Print( DoubleToStr( Ask, Digits ), " ", DoubleToStr( Bid, Digits ), " ", DoubleToStr( Volume[0], Digits ), " " );
   else
      Print( DoubleToStr( Ask, Digits ), " ", DoubleToStr( Bid, Digits ), " ", IntegerToString( Volume[0], 0 ), " " );
   return;
  }
//+------------------------------------------------------------------+

And look at the output for the same ticks.

21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67923 1.67885 163208757249 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67923 1.67880 184683593730 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67922 1.67880 180388626435 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67916 1.67880 154618822660 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67913 1.67881 137438953477 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67922 1.67887 150323855366 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67921 1.67889 137438953479 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67918 1.67892 111669149704 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67921 1.67892 124554051593 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67921 1.67895 111669149706 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67919 1.67893 111669149707 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67918 1.67893 107374182412 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67920 1.67893 115964117005 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67927 1.67893 146028888078 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67920 1.67894 111669149711 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67917 1.67894 98784247824 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67920 1.67894 111669149713 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67918 1.67891 115964117010 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67916 1.67891 107374182419 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67915 1.67891 103079215124 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67917 1.67888 124554051605 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67917 1.67893 103079215126 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67916 1.67890 111669149719 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67914 1.67890 103079215128 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67916 1.67888 120259084313 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67913 1.67888 107374182426 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67903 1.67888 64424509467 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67910 1.67888 94489280540 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67913 1.67888 107374182429 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67919 1.67888 133143986206 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67915 1.67889 111669149727 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67917 1.67891 111669149728 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67918 1.67893 107374182433 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67925 1.67893 137438953506 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67935 1.67893 180388626467 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67934 1.67894 171798691876 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67932 1.67897 150323855397 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67922 1.67897 107374182438 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67932 1.67897 150323855399 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67927 1.67901 111669149736 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67925 1.67899 111669149737 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67926 1.67900 111669149738 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67924 1.67900 103079215147 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67925 1.67897 120259084332 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67925 1.67893 137438953517 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67920 1.67893 115964117038 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67919 1.67893 111669149743 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67918 1.67890 120259084336 
21:28:51 2013.11.04 23:59  TickPrinter GBPAUD.,M1: 1.67920 1.67892 120259084337 

You can see the volume figures are messed up (should be stored variable spread, which is much smaller number....less than 0). Why is this happening? and how can I get it fixed? I also tried running tickprinter509 on the b600 terminal and the results are identical to the b600 test above.

I also noticed that the bid price on the majority of the ticks are 1/10 of a pip lower (0.00001) on the b600 test run. The exact same ticks.

Also, which function should be used: DoubleToStr or DoubleToString?


edit: the title of this thread is misleading. Originally I thought it was the doubleToStr function that was not correct. But now I suspect it could be how the newer mt4 is handling/storing information in the volume field (as an int vs as a double).

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.06 16:43  
4evermaat:

For mt4 build 509, I implemented the following code so that I could print the bid, ask, and volume of each incoming tick on a backtest or in live trading.

on dukascopy tick data using Birt's csv2fxt with UseRealSpreads=true and this is the output (for 1 second of data)

This is correct behavior. It shows the bid/ask/and volume to floating point precision. The volume stores the variable spread, but that was done when using the csv2fxt 0.43.


Why ? you have Bid and Ask why do you need the spread to be stored ? Volume[0] should return the tick count for the current bar.
whroeder1
13609
whroeder1 2014.02.06 17:55  
The MqlRates structure contains two volumes. The old volume is now TickVolume
/
To add comments, please log in or register