Applying called indicator to chart

 

If a custom indicator uses values from a 2nd indicator, is it possible to attach that 2nd indicator on the chart from within the customer indicator without replicating the code of the 2nd indicator in the custom indicator ?

For instance if my customer indicator uses values from a bollinger band and I want that bollinger band to be seen on the chart, is there a way to apply the bollinger bands to the chart from within the customer indicator without replicating the BB code within the custom indicator ?

 
Create an indicator buffer and simply fill it with iBands() values.
 
hasayama:
Create an indicator buffer and simply fill it with iBands() values.


I tried that I couldnt get it to work I always have a hell of a time writing indicators all I 'm getting is a horizontal line how do I get this indicator to use the previous values from all the previous bars do i need to create an array of the bollinger bands previous values or something like that ?

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
double Buf_0[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
SetIndexBuffer(0,Buf_0);
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);         
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i, counted_bars=IndicatorCounted();
//----
      i=Bars-counted_bars-1;
      while(i>=0)
         {
         Buf_0[i]=iBands(NULL,0,3,2,0,1,1,0);
         i--;
         }
//----
   return(0);
 

I changed the line with the buffer to shift the bands by "i"

Buf_0[i]=iBands(NULL,0,3,2,0,1,1, i );
it appears to work this way is that how it should be done ?

int start()
  {
   int i, counted_bars=IndicatorCounted();
//----
      i=Bars-counted_bars-1;
      while(i>=0)
         {
         Buf_0[i]=iBands(NULL,0,3,2,0,1,1,i);
         i--;
         }
//----
   return(0);
  }
 
SDC:

I changed the line with the buffer to shift the bands by "i"

Buf_0[i]=iBands(NULL,0,3,2,0,1,1, i );
it appears to work this way is that how it should be done ?


u teel me
 
SDC:

I changed the line with the buffer to shift the bands by "i"

Buf_0[i]=iBands(NULL,0,3,2,0,1,1, i );
it appears to work this way is that how it should be done ?

Apply the real Bands indicator to the same chart and compare, if results match - you're ok=)
 

OK thanks it works then, I just wasn't sure if that should be done in the start function or not, I didn't want it re calculating all those bars every tick

 
SDC:

OK thanks it works then, I just wasn't sure if that should be done in the start function or not, I didn't want it re calculating all those bars every tick

It's not. It's only recalculating what has changed (bars one and zero)
i=Bars-counted_bars-1;
while(i>=0)
Reason: