New MetaTrader 4 Platform Build 900: Class Templates in MQL4 and Optimized Memory Use

 

New MetaTrader 4 Platform Build 900: Class Templates in MQL4 and Optimized Memory Use

MetaTrader 4 platform update is to be released on Thursday, October 22, 2015. The update will feature the following changes:


MetaTrader 4 Client Terminal build 900

  1. Terminal: Fixed changing a password for an inactive (unconnected) account.




  2. Terminal: Optimized use and release of memory when working with large amounts of historical data.
  3. Terminal: Fixed and optimized working with a large number of news categories.
  4. Signals: Fixed unsubscribing from signals via the Navigator window context menu.




  5. MQL4: Added class templates allowing you to create parametrized classes like in C++. That enables even greater abstraction and ability to use the same code for working with objects of different classes in a uniform manner. An example of using:
    //+------------------------------------------------------------------+
    //|                                                    TemplTest.mq5 |
    //|                        Copyright 2015, MetaQuotes Software Corp. |
    //|                                             https://www.mql5.com |
    //+------------------------------------------------------------------+
    #property copyright "Copyright 2015, MetaQuotes Software Corp."
    #property link      "https://www.mql5.com"
    #property version   "1.00"
    //+------------------------------------------------------------------+
    //| Declare a template class                                         |
    //+------------------------------------------------------------------+
    template<typename T>
    class TArray
      {
    protected:
       T                 m_data[];
    
    public:
    
       bool              Append(T item)
         {
          int new_size=ArraySize(m_data)+1;
          int reserve =(new_size/2+15)&~15;
          //---
          if(ArrayResize(m_data,new_size,reserve)!=new_size)
             return(false);
          //---
          m_data[new_size-1]=item;
          return(true);
         }
       T                 operator[](int index)
         {
          static T invalid_index;
          //---
          if(index<0 || index>=ArraySize(m_data))
             return(invalid_index);
          //---
          return(m_data[index]);
         }   
      };
    //+------------------------------------------------------------------+
    //| Template class of a pointer array. In the destructor, it deletes |
    //| the objects, the pointers to which were stored in the array.     |
    //|                                                                  |
    //| Please note the inheritance from the TArray template class       |
    //+------------------------------------------------------------------+
    template<typename T>
    class TArrayPtr : public TArray<T *>
      {
    public:
       void             ~TArrayPtr()
         {
          for(int n=0,count=ArraySize(m_data);n<count;n++)
             if(CheckPointer(m_data[n])==POINTER_DYNAMIC)
                delete m_data[n];
         }
      };
    //+------------------------------------------------------------------------+
    //| Declare the class. Pointers to its objects will be stored in the array |
    //+------------------------------------------------------------------------+
    class CFoo
      {
       int               m_x;
    public:
                         CFoo(int x):m_x(x) { }
       int               X(void) const { return(m_x); }
      };
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    TArray<int>     ExtIntArray;   // instantiate TArray template (specialize TArray template by the int type)
    TArray<double>  ExtDblArray;   // instantiate TArray template (specialize TArray template by the double type)
    TArrayPtr<CFoo> ExtPtrArray;   // instantiate TArrayPtr template (specialize TArrayPtr template by the CFoo type)
    //+------------------------------------------------------------------+
    //| Script program start function                                    |
    //+------------------------------------------------------------------+
    void OnStart()
      {
    //--- fill arrays with data
       for(int i=0;i<10;i++)
         {
          int integer=i+10;
          ExtIntArray.Append(integer);
          
          double dbl=i+20.0;
          ExtDblArray.Append(dbl);
          
          CFoo *ptr=new CFoo(i+30);
          ExtPtrArray.Append(ptr);
         }
    //--- output the array contents
       string str="Int:";
       for(i=0;i<10;i++)
          str+=" "+(string)ExtIntArray[i];      
       Print(str);   
       str="Dbl:";
       for(i=0;i<10;i++)
          str+=" "+DoubleToString(ExtDblArray[i],1);
       Print(str);   
       str="Ptr:";
       for(i=0;i<10;i++)
          str+=" "+(string)ExtPtrArray[i].X();      
       Print(str);
    //--- CFoo objects created via new should not be deleted, since they are deleted in the TArrayPtr<CFoo> object destructor  
      }
    Execution result:
    TemplTest EURUSD,M1: Ptr: 30 31 32 33 34 35 36 37 38 39
    TemplTest EURUSD,M1: Dbl: 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0
    TemplTest EURUSD,M1: Int: 10 11 12 13 14 15 16 17 18 19
  6. MQL4: Fixed memory reallocation in the ArrayCopy function that could occasionally cause crashes of MQL4 programs.
  7. Tester: Fixed an error that occasionally caused nulling of the variables declared on the global level after testing an indicator.
  8. Tester: Fixed testing when connection to a trade server is lost.
  9. MetaEditor: Fixed defining a function name in MetaAssist in the presence of type casting.
  10. MetaEditor: Fixed opening large files.
  11. MetaEditor: Added F hotkey to call the search function from the Code Base tab, as well as multiple tips in the status bar for the commands for working with a code: increasing/decreasing indentation, navigation, case shift, etc.
  12. Fixed errors reported in crash logs.


The update will be available through the LiveUpdate system.
 

Hello,

I don't know if this is the place to say but, an update I really would like to see is the storing location of the indicators , experts , includes, ....

I would love to see a centralised place for these when using multiple instances of MT4. I'm using 6 different ones. So I have to copy all my personal indicators and stuffs 6 times. No problem but it is getting a mess when working on different projects that use the same include files. Sometimes that is confusing cause opening the editor from within mt4 doen't always open the same editor and this causes me to work on the wrong files. The indicator compiles in another mt4 then.

 

It would be nice if MT4 loads all these things from the terminal folder level instead of the mql4 folder. That way only one folder would be needed that has all EA's for all MT4's. That would make my life much easier and probably a lot of other coders to. Another advantage would be we can have all templates there also. So all instances of MT4 load the same things. 

This shouldn't be very difficult to do I think. 

Something to think about maybe?

Thank you

regards

Youri 

 
Youri De Groeve:

Hello,

I don't know if this is the place to say but, an update I really would like to see is the storing location of the indicators , experts , includes, ....


Hi Youri

I agree it would be a good feature to add. In the meantime, there is a work around if you're using windows by creating link folders with the MKLINK command. Check out some info here

 
can we get more time frame on mt4. like - 4,8 12 hours chart, that would be very helpful for us.
 
Stuart Browne:

Hi Youri

I agree it would be a good feature to add. In the meantime, there is a work around if you're using windows by creating link folders with the MKLINK command. Check out some info here

Thanks for the tip Stuart, this will save me some headaches ;-)

Think I will use /go?link=http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html 

Since I have some indi's tied to specific accounts I can't just link all of them. 

grts

Link Shell Extension
  • schinagl.priv.at
Version 3.9.0.0 Complete support for UNC path in any Smart Move/Copy/Clone & Delorean Operation. Lots of little fixes/improvements, I always wanted to do, but never had the time to. Version 3.8.6.3 Files with a size beeing a multiple of 16777216 were copied properly, but in the logfile generated an error message even if there was none...
 
Youri De Groeve:


It would be nice if MT4 loads all these things from the terminal folder level instead of the mql4 folder. That way only one folder would be needed that has all EA's for all MT4's. That would make my life much easier and probably a lot of other coders to. Another advantage would be we can have all templates there also. So all instances of MT4 load the same things. 


+1 

Great idea. 

 
I hope Any better modern IDE for developing EA in metatrader
 
Faisal Rahman:
I hope Any better modern IDE for developing EA in metatrader
+1 to that!
 

Hi,

I would like to see flexibility in what optimizations can be worked with in the MT4 STRATEGY TESTER. I have and use lots of MT4 code and my broker uses MT4 and I do not want to move to MT5.


For example, I am looking at the "Optimization Results" tab. Here only a fixed number of OUTPUT parameter statistics are shown such as Profit, Total Trades etc. How about other stats such as "Total Losses", "Total Wins" etc similarly as it is shown on the "Report" tab for a single run of the tester?


A second useful addition would be to have the ability to choose the test parameters and have a number of them optimized, one at a time, rather than one optimized against all the others simultaneously which requires an exponential amount of computations.

Like this it would allow a user to find an approximate optimal value especially when testing EAs in different trading pairs.


I can imagine that this extra functionality would not be difficult to add into the Results and graph tabs of the Strategy Tester?

 
Alex Arancibia:

I would like to see flexibility in what optimizations can be worked with in the MT4 STRATEGY TESTER. I have and use lots of MT4 code and my broker uses MT4 and I do not want to move to MT5.

For example, I am looking at the "Optimization Results" tab. Here only a fixed number of OUTPUT parameter statistics are shown such as Profit, Total Trades etc. How about other stats such as "Total Losses", "Total Wins" etc similarly as it is shown on the "Report" tab for a single run of the tester?

Some time ago I have used Excel for such purposes. See https://www.mql5.com/ru/forum/102365

It is Russian but you can use Google Translate

Обработка результатов оптимизации в Excel - MQL4 форум
  • www.mql5.com
Обработка результатов оптимизации в Excel - MQL4 форум
 
Thanks Rashid. But do you still need to the tests one at a time to get these statistics?
Reason: