iCustom using for an EA

 

Hello,

I know, this topic was often discussed here, but I have still questions.

I try to get values of this Indicator https://www.mql5.com/en/code/7760 for my EA.

In this topic https://www.mql5.com/en/forum/138577/page3 I found this tab(thx to whroeder1):


Indicator
EA
Indicator filename without extension, including blanks if any.
#define SFX "SFX"
#define since it is constant. Define it once so there's no typos.
extern string PairName = "";     // Leave blank for ...

extern int StdDev.MA.Period=12;  // D1=20
extern int StdDev.MA.Shift=0;    //
extern int StdDev.MA.Method = 0; // 0=SMA 1=EMA 2=Sm...
extern int StdDev.MA.Price = 0;  // 0 Close price, 1 O...
extern int MA.Fast.Period = 3;
extern int MA.Fast.Method = 2;   //  0=SMA 1=EMA 2=Sm ...
extern int MA.Fast.Shift = 0;

extern bool CheckOncePerBar = true;
string  PairName            = "";     
int     StdDev.MA.Period    = 12;  
int     StdDev.MA.Shift     =  0;    
int     StdDev.MA.Method    =  MODE_SMA; 
int     StdDev.MA.Price     =  PRICE_CLOSE;  
int     MA.Fast.Period      =  3;
int     MA.Fast.Method      =  MODE_SMMA;
int     MA.Fast.Shift       =  0;
#define CheckOncePerBar        true;
Values that do NOT affect the buffers, can be made constant.
   SetIndexBuffer(0, STDBuffer);
   SetIndexBuffer(1, stddevma);
May have to read the code to find the meaning of the buffers. E.g.
STDBuffer[i]= iStdDev(...)
stddevma[i] = iMAOnArray(
#define SFX_STD   0
#define SFX_STDMA 1


my inputs and buffers are:

//---- input parameters
extern int       PerATR=40;
extern double    kATR=2.0;
extern bool      useSendMail=true;
//---- buffers
double SellBuffer[];
double BuyBuffer[];
double Ceil[];
double Floor[];
double Trend[];
int sm_Bars

so I should get this:

Indicator
EA
Indicator filename without extension, including blanks if any.
#define SFX "SFX" means suffix?????????
#define since it is constant. Define it once so there's no typos.
extern int       PerATR=40;
extern double    kATR=2.0;
extern bool      useSendMail=true;

int       PerATR=40;
double    kATR=2.0;
bool      useSendMail=false;
I dont need to send mail

SetIndexBuffer(0,SellBuffer);
SetIndexBuffer(1,BuyBuffer);
SetIndexBuffer(2,Ceil);
SetIndexBuffer(3,Floor);
SetIndexBuffer(4,Trend);
sm_Bars should be used here?



#define SFX_SELL   0
#define SFX_BUY    1
#define SFX_CEIL   2
#define SFX_FLOOR  3
#define SFX_TREND  4



But the first and the last lines are not really clear to me. What is SFX? What should happen with indicator name ?

call

double     SellBuffer = iCustom(NULL,0,SFX,PerATR, kATR, useSendMail,SFX_SELL, 0)

encapsulated

double getSFX(int eBuf, int iBar = 0, int eTF=0){ 
   return( iCustom(NULL, eTF ,SFX,
                   PerATR, kATR, useSendMail,
                   eBuf, iBar) ); 
}

:
:
double     Sell = getSFX(SFX_SELL, 0);
:
:

Does it always have to be encapsulated or can I use also "normal" call ?

Buffer "Trend" is just "1" or "-1" do I get problems with call than ?

Have I done everything correctly?
Is there more code to add, or is it all?


thx for helping and regards

NRTR
NRTR
  • votes: 7
  • 2008.02.02
  • MetaQuotes Software Corp.
  • www.mql5.com
A variation of a well-known Nick Rypock Trailing Reverse indicator.
 

L0rd: What is SFX? What should happen with indicator name ?

sm_Bars should be used here?

Does it always have to be encapsulated or can I use also "normal" call ?

Buffer "Trend" is just "1" or "-1" do I get problems with call than ?

Have I done everything correctly? Is there more code to add, or is it all?



  1. SFX was the indicator name in https://www.mql5.com/en/forum/138577/page3#comment_3505551 Your indicator's name is:
       #define NRTR "NRTR_Rosh" // https://www.mql5.com/en/code/7760
       return iCustom(NULL, eTF ,NRTR,
                      PerATR, kATR, useSendMail,
                      eBuf, iBar); 
    
  2. What is sm_Bars?
  3. Could be either, but why duplicate the code when you get another buffer. Make is a function, good style.
  4. Why would it?
  5. #define SFX_TREND  4
    double     Sell = getSFX(SFX_SELL, 0);
    The name of your indicator is NRTR, don't call it SFX.
  6.  Back in 2012 there was no enumerations
     Make it self documenting.
    #define SFX_SELL   0
    #define SFX_BUY    1
    #define SFX_CEIL   2
    #define SFX_FLOOR  3
    #define SFX_TREND  4
    
    enum NRTR_buffers={NRTR_SELL, NRTR_BUY, NRTR_CEIL, NRTR_FLOOR, NRTR_TREND};
 

thx for fast response!

1. ok, "NRTR_Rosh" is filename w/o extention

2. sm_Bars is int var from last line in "my inputs and buffers are:". Its not an array, so I think its not needed in EA.

3. ok

4. ok

5. I will replace SFX

6. I like 2012 style, because of simplicity. I would use it, if its still working today.

 
L0rd: . I like 2012 style, because of simplicity. I would use it, if its still working today.
Both will work, the latter is better if you use two or more indicators
Using defines
#define NRTR_SELL 0
double getNRTR(int eBuf, int iBar = 0, int eTF=0){ ... }
:
#define SFX_BUY  0
#define SFX_SELL 1
double getSFX(int eBuf, int iBar = 0, int eTF=0){ ... 

double     Sell = getNRTR(SFX_SELL, 0); // This compiles but uses the wrong buffer.
Using enums will not compile
enum NRTRbuffer={NRTR_SELL, ...};
double getNRTR(NRTRbuffer eBuf, int iBar = 0, int eTF=0){ ... }
:
enum SFXbuffer={SFX_BUY, SFX_SELL, ...};
double getSFX(SFXbuffer eBuf, int iBar = 0, int eTF=0){ ... 

double     Sell = getNRTR(SFX_SELL, 0); // This wont compile.

Reason: