• Join us

Detailed explanation of iCustom - page 4

To add comments, please log in or register
Fernando Carreiro
5004
Fernando Carreiro  
honest_knave: I never knew it was called camel case. Thanks!
Looks like the Moderator deleted my previous Post because it had a WikiPedia link, so just do a search on WikiPedia (or Google) for some history and details about "Camel Case".
Alain Verleyen
39060
Alain Verleyen  
Fernando Carreiro:
Looks like the Moderator deleted my previous Post because it had a WikiPedia link, so just do a search on WikiPedia (or Google) for some history and details about "Camel Case".
Your post was removed as it was a double. The same link is already posted.
William Roeder
20359
William Roeder  
Continuing from #23 and encapsulating in a function #26, I now show a struct that works on both MT4 and MT5. (For post-build 600, I've changed the invalid dots (#29) in variable names, and approprate ints to standard enumerations.)
Not compiled, not tested.
struct SFX{                            // SFX indicator at #1
   #define SFX_NAME_PATH   "SFX"       // Indicator filename without extension,
                                       // including blanks if any.
   enum SFXbuffer{SFX_STD, SFX_STDMA};
   string                  PairName;
   ENUM_TIMEFRAMES         tf;
   int                     StdDev_MA_Period;
   int                     StdDev_MA_Shift;
   ENUM_MA_METHOD          StdDev_MA_Method;
   ENUM_APPLIED_PRICE      StdDev_MA_Price;
   int                     MA_Fast_Period;
   ENUM_MA_METHOD          MA_Fast_Method;
   int                     MA_Fast_Shift;
   #define CheckOncePerBar true;
   void SFX()      : PairName(_Symbol),            tf(PERIOD_CURRENT),
                     StdDev_MA_Period(12),         StdDev_MA_Shift(0),
                     StdDev_MA_Method(MODE_SMA),   StdDev_MA_Price(PRICE_CLOSE),
                     MA_Fast_Period(3),            MA_Fast_Method(MODE_SMMA),
#ifndef __MQL5__
                     MA_Fast_Shift(0){}
   double get(SFXbuffer buf, int iBar = 0){
      return iCustom(PairName, tf, SFX_NAME_PATH,
                     StdDev_MA_Period,             StdDev_MA_Shift,
                     StdDev_MA_Method,             StdDev_MA_Price,
                     MA_Fast_Period,               MA_Fast_Method,
                     MA_Fast_Shift,                CheckOncePerBar,
                     buf, iBar);
   }  // get
#else // MQL5
                     MA_Fast_Shift(0),             Handle(INVALID_HANDLE){}
   void ~SFX(){   if(Handle != INVALID_HANDLE) IndicatorRelease(Handle);   }
   double get(SFXbuffer buf, int iBar = 0){
      if(Handle == INVALID_HANDLE){
         Handle = iCustom(PairName, tf, SFX_NAME_PATH,
                     StdDev_MA_Period,             StdDev_MA_Shift,
                     StdDev_MA_Method,             StdDev_MA_Price,
                     MA_Fast_Period,               MA_Fast_Method,
                     MA_Fast_Shift,                CheckOncePerBar);
         if(Handle == INVALID_HANDLE){
            PrintFormat("%s: iCustom(%s) Failed: %i",
                        __FUNCTION__, SFX_NAME_PATH, _LastError);
            return 0;
         }
      }
      double  value[1]; CopyBuffer(Handle, buf, iBar, 1, value);
      return  value[0];
   }  // get
 Private:
   int                  Handle;     // MT5 only
#endif   // __MQL5__
}; // SFX
///////////////////////////////////////////////////////////////////////////////
SFX   SFXindicator;
// SFXindicator.StdDev_MA_Period = ...;   // modification of default parameters.
:
double     STDBuffer = SFXindicator.get(SFX_STD,   0);   // example calls
double     stddevma  = SFXindicator.get(SFX_STDMA, 0);
Not compiled, not tested.
LandauMT4
32
LandauMT4  

Hello, i have a quick (and painless, i hope) question about iCustom: let's say that i have 3 indicators called Ind_A, Ind_B and Ind_C, and i have an Expert Advisor called EA.

the EA calls all the 3 indicators using icustom, passing their arguments and getting the results by indexing their respctive buffers.

i attach my 3 indicator on the EURUSD chart and i run my EA; let's focus on the indicator Ind_A, he is running as indicator but at the same time is executed by the EA: the instance is the same or we have two instances of ind_A running? (i mean, one instance runs on his own and the other instance lives inside the EA).

in suche case, each instance has his own buffer? or is the buffer shared between all the instances of the indicator?

Many thanks!

EUR/USD - Trading blogs and financial markets analysis
EUR/USD - Trading blogs and financial markets analysis
  • www.mql5.com
The EUR/USD (euro/United States dollar) is the most popular currency pair in the world, representing the economies of the European Union and the United States respectively.Trading the EUR/USD currency
To add comments, please log in or register