MQL4 - automated forex trading   /  

Forum

What´s easier for the computer to calculate, with or without iCustom() function?

Back to topics list To post a new topic, please log in or register

avatar
124
Heino 2008.01.14 20:49 
Hello, what's easier for the computer to calculate, if the values are calculate in the same script/file or to pick it up with iCustom function from other files?
article

All about Automated Trading Championship: Interviews with the Participants'06

Interviews with the Participants of Automated Trading Championship 2006 demonstrated a great variety of views of automated trading and trading as a whole. You can see yourselves which ideas turned out to work better during the Championship and which of them could not pass the critical verification through a three-month long "test-drive" on a contest account.


avatar
1230
BarrowBoy 2008.01.15 18:45 

I haven't tested this in MT but from other programming situations I'd expect that calling other executables at run-time adds overhead.

If an MT app developer can write and say that all MT4 indicators are memory resident, multi-instance & free-threaded that would change things :)

You can save CPU by only evaluating what & when you need to, typically I evaluate close options every tick but evaluate open options once per bar.

Also rem out any calls you are not using (unused complete functions are left out by the compiler anyway)

Good Luck

BB


avatar
Moderator
33772
Rosh 2008.01.16 13:10 
Let's write a simple custom indicator, for example test.mq4 named

//+------------------------------------------------------------------+
//|                                                         Test.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net/ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/ru/"
 
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
 
extern int val=5;
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   int    res_int=0,i;
   double res_double=0;
//----
   for(i=0;i<=10000000;i++)
     {
      res_int+=i*i;
      res_int++;
      res_double+=i*i;
      res_double++;
     }
   ExtMapBuffer1[0]=res_double;      
//----
   return(0);
  }
//+------------------------------------------------------------------+


avatar
Moderator
33772
Rosh 2008.01.16 13:12 
And will write the script which contains numerous calls of this custom indicator

//+------------------------------------------------------------------+
//|                                             CheckCustomSpeed.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net/ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/ru/"
 
#property show_inputs
 
 
//+------------------------------------------------------------------+
//|  implemented Test functiom                                       |
//+------------------------------------------------------------------+
double test()
   {
   int    res_int=0,i;
   double res_double=0;
//----
   for(i=0;i<=10000000;i++)
     {
      res_int+=i*i;
      res_int++;
      res_double+=i*i;
      res_double++;
     }
   return(res_double);
   }
 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
  double Impl=test();
  double Custom=iCustom(NULL,0,"Test",5,0,0);
//----
   Print("Implemented retuns ",Impl,",   iCustom returns ",Custom,", diiff=",Impl-Custom);
   
//----
   int i,start,stop;
   //Measuring time for test function
   start=GetTickCount();
   for (i=0;i<100;i++) test();
   stop=GetTickCount();
   int testTime=(stop-start)/1000.0;
 
   //Measuring time for Custom function
   start=GetTickCount();
   for (i=0;i<100;i++) Custom=iCustom(NULL,0,"Test",i,0,0);
   stop=GetTickCount();
   int customTime=(stop-start)/1000.0;
   string text=StringConcatenate("Time for implemented function test() is ",testTime,"  seconds");
   text=StringConcatenate(text,"\n Time for custom function iCustom(\"test\") is ",customTime,"  seconds");
   Comment(text);
 
//----
   return(0);
  }
//+------------------------------------------------------------------+


avatar
Moderator
33772
Rosh 2008.01.16 13:18 
As shown this script may give us the answer about of difference between the custom indicator and implemented function. Run it and you may be will see like this





avatar
1230
BarrowBoy 2008.01.17 16:26 

Rosh

Good practical example thanks :)

Shows that calls to Custom Indicators are efficient & can be made without extra overhead - which

a) Simplifies coding no end

b) Shows how well MT4 is put together under the bonnet!

BB

Back to topics list  

To add comments, please log in or register