Detailed explanation of iCustom - page 2

 
NewCoder47:


Thanks for that RaptorUK, however it is the actual coding that I am having difficulties with. I am very new to MQL4, and have only been doing it a couple of months, and am still learning - so I am needing a simple explanation of the coding and how to set it up in the indicator.

Didn't you read what I wrote ? " No changes are needed to the Indicators . . . . the EA simply accesses the buffers it needs at the shift values it needs. "
 
dabbler:
No you can't. I just tried it. It won't compile if you leave out one of the parameters by just leaving an empty place between the commas.
I knew I should have correct the last statement. Take-out the comma's for the parameters.
 
ubzen:
I knew I should have correct the last statement. Take-out the comma's for the parameters.

I just complied this Indicator as TOR.mqh within my Indicator Folder. Then I wrote the following Code in the Expert Folder.

void start(){
    iCustom(Symbol(),0,"TOR",0,1);
}
It complied fine for me without passing any parameters.
 
ubzen:

I just complied this Indicator as TOR.mqh within my Indicator Folder. Then I wrote the following Code in the Expert Folder.

It compiled fine for me without passing any parameters.
But does it actually work?
 
dabbler:
But does it actually work?
Yes. All the time. I'm talking about Extern Values. And I'm guessing you're talking about Buffers.
 

Thanks for your help guys, Ill have a look tomorrow night and see what I can figure out.

Thanks

 

Hey Guys. I still seem to be having some difficulty.

Here is the code, in the indicator ( I Have not changed anything in the indicator), I am showing what I think is the relevant part. Please note that these do not follow each other in the indicator, there is lots more that I have stripped.

//---- indicator buffers
double     STDBuffer[];
double     stddevma[];


//---- macd counted in the 1-st buffer
  for(int i=limit-1; i>=0; i--){
     STDBuffer[i]=iStdDev(Pair1,0,StdDev.MA.Period, StdDev.MA.Shift, StdDev.MA.Method, StdDev.MA.Price, i);
     }
  for(i=limit-1; i>=0; i--){
     stddevma[i] = iMAOnArray(STDBuffer, 0, MA.Fast.Period, MA.Fast.Shift, MA.Fast.Method, i);
     } 

Now here is the code in the EA

                double FastMA = iMA(NULL,0,FastMAPeriod,0,0,0,0);
                double SlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,0);
                double     STDBuffer = iCustom(Null,0,"SFX", , ,0,0);
                double     stddevma = iCustom(Null,0,"SFX", , ,1,0);
                

What I don't understand is the parameters part. What values do I put in here? This is the part which I am struggling with. I am wanting to use the values of the STDBuffer and stddevma in a test further down the EA. For example, do I include Pair1 (which is elsewhere in the Indicator declared as the current chart)? As its already declared as Null at the start of iCustom.

Also, is there any way to physically see what values are being sent to the EA?

Any help would be greatly appreciated.

Thanks

 
NewCoder47:

Here is the code, in the indicator ( I Have not changed anything in the indicator), I am showing what I think is the relevant part. Please note that these do not follow each other in the indicator, there is lots more that I have stripped.

Now here is the code in the EA

What I don't understand is the parameters part. What values do I put in here? This is the part which I am struggling with. I am wanting to use the values of the STDBuffer and stddevma in a test further down the EA. For example, do I include Pair1 (which is elsewhere in the Indicator declared as the current chart)? As its already declared as Null at the start of iCustom.

You have not shown the relevant parts of the indicator. You need to show all the extern statements AND the order in which they occur.

You need to show all the SetIndexBuffer statements. When you understand why you need to show these you will probably see what you have to do.

Oh, and you can't have blanks in between commas in the iCustom statements; it won't compile.

Try re-reading the iCustom documentation, taking into account it was originally in Russian. You have to study it carefully.

 
dabbler:

You have not shown the relevant parts of the indicator. You need to show all the extern statements AND the order in which they occur.

You need to show all the SetIndexBuffer statements. When you understand why you need to show these you will probably see what you have to do.

Oh, and you can't have blanks in between commas in the iCustom statements; it won't compile.

Try re-reading the iCustom documentation, taking into account it was originally in Russian. You have to study it carefully.

Thanks Dabbler. I have attached the full EA and Indicator. I have read the statements on iCustom, and understand everything apart from the parameters part, it is extremely vague. The EA is very cut down thou, as I am only testing at the mo.

Thanks,

Mike.

Indicator:

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Yellow
#property  indicator_color2  Red
#property  indicator_width1  1

//---- indicator parameters
extern string PairName = "";   // Leave blank for the pair of the chart, enter other pair name to compare correlated pairs

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=Smoothed 3=Linear Weighted
extern int StdDev.MA.Price = 0;  // 0 Close price, 1 Open price, 2 High price, 3 Low price, 4 Median price, (high+low)/2, 5 Typical price, (high+low+close)/3, 6 Weighted close price, (high+low+close+close)/4

extern int MA.Fast.Period = 3;
extern int MA.Fast.Method = 2;   //  0=SMA 1=EMA 2=Smoothed 3=Linear Weighted
extern int MA.Fast.Shift = 0;

extern bool CheckOncePerBar = true;

int i, limit, counted_bars;
static string Pair1;

datetime CurrentTimeStamp;

//---- indicator buffers
double     STDBuffer[];
double     stddevma[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  
   IndicatorDigits(Digits+1);
     
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE); // 
   SetIndexStyle(1,DRAW_LINE);

      
//---- indicator buffers mapping
   SetIndexBuffer(0, STDBuffer);
   SetIndexBuffer(1, stddevma);

   
   if (PairName == "") Pair1 = Symbol();
   else Pair1 = PairName;

//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("SFX TOR: "+Pair1+"("+StdDev.MA.Period+")");
   SetIndexLabel(0,"StdDev");
   SetIndexLabel(1,"StdDev MA");

//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {

   counted_bars=IndicatorCounted();
   
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
//---- macd counted in the 1-st buffer
  for(int i=limit-1; i>=0; i--){
     STDBuffer[i]=iStdDev(Pair1,0,StdDev.MA.Period, StdDev.MA.Shift, StdDev.MA.Method, StdDev.MA.Price, i);
     }
  for(i=limit-1; i>=0; i--){
     stddevma[i] = iMAOnArray(STDBuffer, 0, MA.Fast.Period, MA.Fast.Shift, MA.Fast.Method, i);
     } 
    
//Execute on bar Open
    if( CheckOncePerBar == true ){
      if( CurrentTimeStamp == Time[0] )
         return( 0 );
   }
   
   CurrentTimeStamp = Time [0];
   
          
//---- done
   return(0);
  }

EA:

//+------------------------------------------------------------------+
//|                                                       Simple.mq4 |
//|                                                       Mike Clegg |
//|                                                                  |
//+------------------------------------------------------------------+

#property copyright "Mike Clegg"


// External variables
extern double LotSize = 1;

extern int MagicNumber = 123;

extern int FastMAPeriod = 12;
extern int SlowMAPeriod = 26;


// Global variables
int BuyTicket;
int SellTicket;


// Start function
int start()
        {
                // Moving averages
                double FastMA = iMA(NULL,0,FastMAPeriod,0,0,0,0);
                double SlowMA = iMA(NULL,0,SlowMAPeriod,0,0,0,0);
                double     STDBuffer = iCustom(NULL,0,"SFX",0,0);
      double     stddevma = iCustom(NULL,0,"SFX",1,0);
                
                // Buy order 
                if(FastMA > SlowMA && BuyTicket == 0 && stddevma > STDBuffer)
                        {PlaySound("alert.wav");
         Alert(Symbol(),"All Crossing",Period(),"All Crossing");
                        }
                                
                return(0);
        }

Please ignore the fact that the EA is doing the job of an indicator, as I said, I am testing at the moment.

 
NewCoder47:

Thanks Dabbler. I have attached the full EA and Indicator. I have read the statements on iCustom, and understand everything apart from the parameters part, it is extremely vague. The EA is very cut down thou, as I am only testing at the mo.

Thanks,

Mike.

Indicator:

EA:

Please ignore the fact that the EA is doing the job of an indicator, as I said, I am testing at the moment.


You had have some great advice here and still you are struggling....

To know how iCustom works with your indicator you can make a helpEA or helpIndicator to check what is inside the buffers of the indicator

This way you learn the most about checking commands in MT4. Read here https://www.mql5.com/en/forum/138379

make something like that and you will learn how to use it..... in the EA's you wanna make

Reason: