Download MetaTrader 5

Indicator of an Indicator - Still perplexed

To add comments, please log in or register
Publish your article. We will translate it into other languages!
RichyF1
46
RichyF1 2016.06.21 00:03 

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 

Alain Verleyen
Moderator
30722
Alain Verleyen 2016.06.21 09:19  
RichyF1:
it doesnt seem to work.
What that means exactly ?
Ernst Van Der Merwe
4729
Ernst Van Der Merwe 2016.06.21 10:08  

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);
  }

RichyF1
46
RichyF1 2016.06.26 00:13  
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



To add comments, please log in or register