Download MetaTrader 5

OOP and the Type of the Program..

To add comments, please log in or register
Carl Schreiber
Moderator
8447
Carl Schreiber  

Hi,

is there a more elegant way of an object to know 'for what it is' used?

A class should know whether it is part of an EA, an indicator or a script so that  e.g. it knows how it should deal with e.g. sleep which does not work in indicators and must be treated differently.

Neither in the help of (Mql4 nor in) Mql5 I could find any thing that returns this info so I created this solution.

Normally (I guess) the OOP files with the classes are in various mqh files so that the use of the simple __PATH__ does not give any meaningful result.

So this results in a bit unpleasant solution as it requires a call in Oninit() while I would prefer a direct call in the initialization of the class.

Any idea of a better solution?

enum €PrgType {
   €EA,
   €Indi,
   €Script,
   €Undef
};
€PrgType getPrdType(const string path) {
   if (StringFind(path,"\\Experts\\")>=0) return(€EA);
   if (StringFind(path,"\\Indicators\\")>=0) return(€Indi);
   if (StringFind(path,"\\Scripts\\")>=0) return(€Indi);
   return(€Undef);
}
Amir Yacoby
1500
Amir Yacoby  

ENUM_PROGRAM_TYPE from MQL_PROGRAM_TYPE

Get the value using MqlInfoString

Example from doc:

   ENUM_PROGRAM_TYPE mql_program=(ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL_PROGRAM_TYPE); 
   switch(mql_program) 
     { 
      case PROGRAM_SCRIPT: 
        { 
         Print(__FILE__+" is script"); 
         break; 
        } 
      case PROGRAM_EXPERT: 
        { 
         Print(__FILE__+" is Expert Advisor"); 
         break; 
        } 
      case PROGRAM_INDICATOR: 
        { 
         Print(__FILE__+" is custom indicator"); 
         break; 
        } 
      default:Print("MQL5 program type value is ",mql_program); 
     }
Carl Schreiber
Moderator
8447
Carl Schreiber  
Thanks - I have found it.
To add comments, please log in or register