MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Automated Trading and Strategy Testing Forum

Screenshot
USDJPY, M1
Demo
Painting DealsPainting Deals Try product
Painting Deals
Author: song_song
MQL5 Wizard - Trade Signals Based on Dark Cloud Cover/Piercing Line + Stochastic Expert Advisor
MQL5 Wizard - Trade Signals Based on Dark Cloud Cover/Piercing Line + Stochastic
Author: MetaQuotes
Subscribe to signal
Hpstz com 1
14.16%, 1 168.11 USD
Here Comes the New MetaTrader 5 and MQL5 Here Comes the New MetaTrader 5 and MQL5

// Scripts: sTimeToVariables

To add comments, please log in or register

Automated-Trading
Admin
20480
Automated-Trading 2011.05.12 10:19

sTimeToVariables:

The script converts the time, represented as datetime variable into the year, month, day, hour, minutes and seconds.

It doen't uses MQL5 functions!

Author: Дмитрий

ATC Champions League: Interview with Boris Odintsov (ATC 2011)
Interview with Boris Odintsov (bobsley) is the last one within the ATC Champions League project. Boris won the Automated Trading Championship 2010 - the first Championship held for the Expert Advisors in the new MQL5 language. Having appeared in the top ten already in the first week of the ATC 2010, his EA brought it to the finish and earned $77,000. This year, Boris participates in the competition with the same Expert Advisor with modified settings. Perhaps the robot would still be able to repeat its success.
Gabor Torma
1918
VincentX 2012.08.03 16:15

yours quicker?
onewithzachy
953
onewithzachy 2012.08.04 00:40

Waste of time ! 

Gabor Torma
1918
VincentX 2012.08.04 11:52
onewithzachy:

Waste of time ! 

No, if it's quicker...
Gabor Torma
1918
VincentX 2012.08.04 12:25

TimeToStruct 4 times quicker then sTimeToVariable

Result:
2012.08.04 12:23:09    sTimeToVariables (GOLD,M1)    sTimeToVariables performace: 24.190035%
2012.08.04 12:23:09    sTimeToVariables (GOLD,M1)    sTimeToVariables: 42891604
2012.08.04 12:22:55    sTimeToVariables (GOLD,M1)    TimeToStruct: 10375494

#import "kernel32.dll"
bool QueryPerformanceCounter(int &counter[]);
#import
//+------------------------------------------------------------------+
//| Script start function                                            |
//+------------------------------------------------------------------+
int OnStart()
  {
   int counter[2];
   int start;

   datetime TimeNow=TimeCurrent();
   MqlDateTime tm;

   long today=TimeCurrent();

   QueryPerformanceCounter(counter);
   start=counter[0];
   for(int i=0;i<100000000;i++)
      TimeToStruct(TimeNow,tm);
   QueryPerformanceCounter(counter);
   long T1=counter[0]-start;
   Print("TimeToStruct: ",T1);

   QueryPerformanceCounter(counter);
   start=counter[0];
   for(int i=0;i<100000000;i++)
      fTimeToVariables(TimeNow,tm);
   QueryPerformanceCounter(counter);
   long T2=counter[0]-start;
   Print("fTimeToVariables: ",T2);

   PrintFormat("fTimeToVariables performace: %f%%",double(T1)/double(T2)*100);

   return(0);
  }
//+------------------------------------------------------------------+
//| fTimeToVariables                                                 |
//+------------------------------------------------------------------+
void fTimeToVariables(datetime TIME,MqlDateTime&  dt_struct )
  {
   int dst=(int)TIME%86400;
   dt_struct.hour=dst/3600;
   dst-=(dt_struct.hour*3600);
   dt_struct.min=dst/60;
   dt_struct.sec=dst%60;
   int dn=(int)TIME/86400;
   int edn=dn+365;
   int qen=edn/1461;
   int dfqs=edn-(qen*1461);
   int yfqs;
   int dfys;
   if(dfqs<1095)
     {
      yfqs=dfqs/365;
      dt_struct.year=1969+qen*4+yfqs;
      dfys=dfqs-(yfqs*365);
     }
   else
     {
      yfqs=3;
      dt_struct.year=1969+qen*4+yfqs;
      dfys=dfqs-(yfqs*365);
      if(dfys==59)
        {
         dt_struct.mon=2;
         dt_struct.day=29;
         return;
        }
      else if(dfys>59)
        {
         dfys--;
        }
     }
   int mei[]={-1,30,58,89,119,150,180,211,242,272,303,333,364};
   for(dt_struct.mon=1;dt_struct.mon<13;dt_struct.mon++)
     {
      if(dfys<=mei[dt_struct.mon])
        {
         dt_struct.day=dfys-mei[dt_struct.mon-1];
         return;
        }
     }
  }
onewithzachy
953
onewithzachy 2012.08.04 16:12
VincentX:

TimeToStruct 4 times quicker then sTimeToVariable

Waste of time ! 

Well, at least it shows how to extract time components. 


Hi VincentX,

Nice code using kernel32's QueryPerformanceCounter, and I thanks for it.

 

 

Gabor Torma
1918
VincentX 2012.08.04 18:09

onewithzachy: Would you repost the code using SRC butt-on

Thanx for help!

Gabor Torma
1918
VincentX 2012.08.05 10:39
onewithzachy:

Hi VincentX,

What help ???

;)

 

The SRC button...

I posted source first time.

/

To add comments, please log in or register