indicator - how to enable 'apply to first indicators value'

 

Default indicators have extra 'apply to' options, namely 'previous indicators data' and 'first indicators data'

How do you add this ability to custom indicators such as below ?

e.g. Donchian.mq4

//+------------------------------------------------------------------+
//|                                                 Donchian Channel |
//+------------------------------------------------------------------+

#property  copyright "ps"
#property  link      ""
//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 2
#property  indicator_color1  Gold
#property  indicator_color2  Gold
#property  indicator_width1  1
#property  indicator_width2  1

//---- indicator parameters
extern int periods=20;

//---- indicator buffers
double     upper[];
double     lower[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   
//---- indicator buffers mapping
   SetIndexBuffer(0,upper);
   SetIndexBuffer(1,lower);
   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Donchian Channel("+periods+")");
   SetIndexLabel(0,"Upper");
   SetIndexLabel(1,"Lower");
   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| now do the dance.                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

//---- calculate values
   for(int i=0; i<limit; i++) {
      upper[i]=iHigh(Symbol(),Period(),iHighest(Symbol(),Period(),MODE_HIGH,periods,i));
      lower[i]=iLow(Symbol(),Period(),iLowest(Symbol(),Period(),MODE_LOW,periods,i));
   }
   
   return(0);
  }
  

i suppose the idea is to apply the 2nd indicator to the first using code in a seperate and complete indicator, rather than enhancing the 2nd indicator ????

e.g. BB_RSI_v1.mq4

//+------------------------------------------------------------------+
//|                                                       SMARSI.mq4 |
//|                          Typical RSI revised By TrendLaboratory  |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                       E-mail: igorad2004@list.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, TrendLaboratory Ltd."
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 30
#property indicator_level2 70
#property indicator_buffers 4
#property indicator_color1 DodgerBlue
#property indicator_color2 Yellow
#property indicator_color3 Yellow
#property indicator_color4 Yellow

//---- input parameters
extern int RSIPeriod=14;
extern int BBPeriod=20;
extern int Price=0;
extern int Deviation=2;
//---- buffers
double RSIBuffer[];
double BBBuffer[];
double UpBuffer[];
double DnBuffer[];

double PosBuffer[];
double NegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(6);
   SetIndexBuffer(4,PosBuffer);
   SetIndexBuffer(5,NegBuffer);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,RSIBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,BBBuffer);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,UpBuffer);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,DnBuffer);


//---- name for DataWindow and indicator subwindow label
   short_name="BBRSI("+RSIPeriod+","+BBPeriod+","+Price+","+Deviation+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
   SetIndexLabel(1,"BB mid");
   SetIndexLabel(2,"BB up");
   SetIndexLabel(3,"BB down");
   
//----
   SetIndexDrawBegin(0,RSIPeriod+BBPeriod);
   SetIndexDrawBegin(1,RSIPeriod+BBPeriod);
   SetIndexDrawBegin(2,RSIPeriod+BBPeriod);
   SetIndexDrawBegin(3,RSIPeriod+BBPeriod);


//----
   return(0);
  }
//+------------------------------------------------------------------+
//| BB and Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive;
//----
   if(Bars<=RSIPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=RSIPeriod;i++) RSIBuffer[Bars-i]=0.0;
//----
   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   int MAPeriod=1;
   while(i>=0)
     {
      double sumn=0.0,sump=0.0;
      for (int k=RSIPeriod-1;k>=0;k--)
           { 
            rel=iMA(NULL,0,MAPeriod,0,MODE_SMA,Price,i+k)-iMA(NULL,0,MAPeriod,0,MODE_SMA,Price,i+k+1);
            if(rel>0) sump+=rel;
            else      sumn-=rel;
           }
         positive=sump/RSIPeriod;
         negative=sumn/RSIPeriod;
      
      PosBuffer[i]=positive;
      NegBuffer[i]=negative;
      if(negative==0.0) RSIBuffer[i]=0.0;
      else RSIBuffer[i]=100.0-100.0/(1+positive/negative);
       
      i--;
     }
     int total=0;
     for (i=Bars-RSIPeriod-BBPeriod-1;i>=0;i--)
     {
     UpBuffer[i]=iBandsOnArray(RSIBuffer,total,BBPeriod,2,0,MODE_UPPER,i);
     DnBuffer[i]=iBandsOnArray(RSIBuffer,total,BBPeriod,2,0,MODE_LOWER,i);
     BBBuffer[i]=0.5*(UpBuffer[i]+DnBuffer[i]);
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

What are the options?

 
Perhaps this will help.
 
mrmedia:

Default indicators have extra 'apply to' options, namely 'previous indicators data' and 'first indicators data'

How do you add this ability to custom indicators such as below ?

e.g. Donchian.mq4

i suppose the idea is to apply the 2nd indicator to the first using code in a seperate and complete indicator, rather than enhancing the 2nd indicator ????

e.g. BB_RSI_v1.mq4

What are the options?


Me too facing the same problem,din't find any solution, please suggest any solution.
Reason: