Indicator of an Indicator - Still perplexed

 

Hi all

Recently I have been creating my own indicators and trying to look at markets in different ways, Pairs trading, or adding them together, basket trading.

In doing this I have been creating my own indicators to monitor the movements etc. I would like to place standard indicators on these, hence an indicator on an indicator.

This can be completed fine in MT5 UI, however doing this in code doesn't seem to work...... (ARGGHHHH). 

 

An example, I am trying to export the data for the last 10000 bars of m5 data of my indicators and have created a script that loads my custom indicator. That works fine, but I would like to run iBands on this also. I have done this by passing the handle through of the custom indicator, however it doesnt seem to work.

//load custom indicator

int hPairPR = iCustom(Symbol(),0,"PairsX2",SecondSymbol,MA_Period,StDev_Period,0.005); 

//load 2 bollingerbands indicattrs on it

int hBollinger1 = iBands(Symbol(),0,MA_Period,0,   0.5,  hPairPR);
int hBollinger2 = iBands(Symbol(),0,MA_Period,0,   1,    hPairPR);

 

 Does anyone know the best way to run an indicator on another indicator, in code?

 Sorry if this seems dumb, still trying to get my head around it. (Would also like to run a stochastic on it!!!) 

Thanks in advance.

Rich 

 
RichyF1:
it doesnt seem to work.
What that means exactly ?
 

It's working fine for me.

int OnInit()
  {
   IndicatorSetString(INDICATOR_SHORTNAME,StringFormat("Bands on CCI(%d,%.1f)",BandsPeriod,Deviation));
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- indicator handles
   handleCCI=iCustom(NULL,0,"CCI_OHLC");
   handleBands=iBands(NULL,0,BandsPeriod,0,Deviation,handleCCI);
//--- indicator buffers mapping
   SetIndexBuffer(0,OpenBuffer);
   SetIndexBuffer(1,HighBuffer);
   SetIndexBuffer(2,LowBuffer);
   SetIndexBuffer(3,CloseBuffer);
   SetIndexBuffer(4,ColorBuffer,INDICATOR_COLOR_INDEX);
//---
   SetIndexBuffer(5,BaseBuffer);
   SetIndexBuffer(6,UpperBuffer);
   SetIndexBuffer(7,LowerBuffer);
//---
   return(INIT_SUCCEEDED);
  }

 
pipPod:

It's working fine for me.

Hi pipPod and Alain

Thank you very very much, your suggestion worked very well for me. Really appreciate your help, hope I can return the favor sometime :)

For reference, if others are having this problem. I nested the custom indicator into another to get it to work, and it seems to work very well.

  int OnInit()
   //--- indicator handles
   handlePairX=iCustom(Symbol(),0,"PairsX2",Symbol2,MA,StandardDev1,0.005);
   handleRSI1=iRSI(NULL,0,RSI1,handlePairX);
   handleRSI2=iRSI(NULL,0,RSI2,handlePairX);


//and then in OnCalculate

   if(prev_calculated-1<rates_total)
     {
      for(int i=0;i<rates_total-1;i++)

            CopyBuffer(handleRSI1,0,i,1,tempbuff3);
            CopyBuffer(handleRSI2,0,i,1,tempbuff4);

            ind1[i]=tempbuff3[0];     //RSI1
            ind2[i]=tempbuff4[0];     //RSI2



Reason: