Download MetaTrader 5

How to get multiple indexbuffers from iCustom

To add comments, please log in or register
Track all payments in your profile. It is easy!
Brandsma
42
Brandsma 2015.12.17 15:51 

Hi there,

 

When you call the iCustom function to a (custom) indicator, somehow like this ->

 

TrendDirection = iCustom(NULL,0,"_trend", 0,1);

 

You get only 1 indexBuffer from inside the indicator.. But what if you want more data from the indicator? Lets say indexBuffer1, indexBuffer2, indexBuffer3

Could you do 

TrendDirection2 = iCustom(NULL,0,"_trend", 0, 2);
TrendDirection3 = iCustom(NULL,0,"_trend", 0, 3);

 

I wonder if the indicator gets 're-run' again, so practically you would run the indicator to many times and create loads of overhead.

Is that theory correct? 

/****** INDICATOR ******/
int start() {
      int    counted_bars=IndicatorCounted();
      
      int limit=Bars-counted_bars;
      if(counted_bars>0) limit++;
      
      for(int i=1; i<limit; i++)
      {
         MA1=iMA(NULL,0,MA1_Period,0,MODE_SMA,PRICE_CLOSE,i);
         //MA2=iMA(NULL,0,MA2_Period,0,MODE_SMA,PRICE_CLOSE,i);
         MA2= iBands(Symbol(),0,20,2,0,PRICE_CLOSE,0,i);
         
         MA1_Buffer[i]=MA1;
         MA2_Buffer[i]=MA2;
      }
}

 The real question is: Is it safe to 'repeat' the iCustom function, to retrieve different indexBuffers?

 Thanks!

Daniel Stein
24788
Daniel Stein 2015.12.17 17:27  

Hi Brandsma, 

your iCustom request is wrong.

TrendDirection2 = iCustom(NULL,0,"_trend", 0, 2); //asks the same index buffer at candle 2 (current -2)
TrendDirection3 = iCustom(NULL,0,"_trend", 0, 3); //asks the same index buffer at candle 3 (current -3)

This is the correct request for buffer 2 and 3 

TrendDirection2 = iCustom(NULL,0,"_trend", 1, 0); /asks the buffer 2 of the Trend Indicator on candle 0 (current)
TrendDirection3 = iCustom(NULL,0,"_trend", 2, 0); //asks the buffer 3 of the Trend indicator on candle 0 (current)

Please keep in mind that the index buffer count starts with 0  

 

You can use as many iCustom requests as you want.

A simple MA or any other standard indicator isn't very complicated and quick to calculate.

To add comments, please log in or register