how to code "first indicator's data" into your indicator

 

let me explain my question that i think is different from others', or not?

1 i wanted to make my indicator shows the parameter tab 

2 in that parameter tab it shows "apply to" option with the drop-down menu offering various ENUM_MA_METHOD including the previous and first indicator's data
similar to the attached pic mt4 ma options


i've searched in the forum and still not finding the sample code that will enable me to do the above for my indicator. and indicators come with mt4 don't include 

the source code that i can use as an example to do so. can someone please give me some sample code for me to solve my problem? 

 

Do not double post!!

I have deleted your duplicate topic.

 
//--- input parameters
input int      MAPeriod=9;
input int      MAShift=0;
input ENUM_MA_METHOD MAMethod=MODE_SMA;
input int      CCIPeriod=14;
input ENUM_APPLIED_PRICE CCIPrice=PRICE_TYPICAL;
input int      RSIPeriod=14;
input ENUM_APPLIED_PRICE RSIPrice=PRICE_CLOSE;
enum APPLY_TO
  {
   APPLY_TO_Close=PRICE_CLOSE,         //Close
   APPLY_TO_Open=PRICE_OPEN,           //Open
   APPLY_TO_High=PRICE_HIGH,           //High
   APPLY_TO_Low=PRICE_LOW,             //Low
   APPLY_TO_Median=PRICE_MEDIAN,       //Median
   APPLY_TO_Typical=PRICE_TYPICAL,     //Typical
   APPLY_TO_Weighted=PRICE_WEIGHTED,   //Weighted
   APPLY_TO_CCI,                       //Commodity Channel Index
   APPLY_TO_RSI                        //Relative Strength Index
  };
input APPLY_TO ApplyTo=APPLY_TO_Close;
//--- indicator buffers
double         MABuffer[];
double         IndBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   string name=StringFormat(" %s(%d)",StringSubstr(EnumToString(MAMethod),5),MAPeriod);
//--- indicator buffers mapping
   SetIndexBuffer(0,MABuffer);
   SetIndexShift(0,MAShift);
   SetIndexLabel(0,name);
   SetIndexDrawBegin(0,MAPeriod);
   SetIndexBuffer(1,IndBuffer);
   string name1=StringFormat("%s",StringSubstr(EnumToString(ApplyTo),9));
   SetIndexLabel(1,name1);
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
   if(ApplyTo==APPLY_TO_CCI)
     { 
      name1+=StringFormat("(%d)",CCIPeriod);
      SetIndexLabel(1,name1);
      IndicatorSetInteger(INDICATOR_DIGITS,0);
     }
   if(ApplyTo==APPLY_TO_RSI)
     { 
      name1+=StringFormat("(%d)",RSIPeriod);
      SetIndexLabel(1,name1);
      IndicatorSetInteger(INDICATOR_DIGITS,1);
     }
   IndicatorSetString(INDICATOR_SHORTNAME,name1+name);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   int begin=(rates_total!=prev_calculated)?rates_total-prev_calculated-1:0;
//--- apply to CCI
   if(ApplyTo==APPLY_TO_CCI)
     { 
      for(int i=begin;i>=0;i--)
         IndBuffer[i]=iCCI(_Symbol,_Period,CCIPeriod,CCIPrice,i);
      for(int i=begin;i>=0;i--)
         MABuffer[i]=iMAOnArray(IndBuffer,rates_total,MAPeriod,0,MAMethod,i);
     }
//--- apply to RSI
   else if(ApplyTo==APPLY_TO_RSI)
     {
      for(int i=begin;i>=0;i--)
         IndBuffer[i]=iRSI(_Symbol,_Period,RSIPeriod,RSIPrice,i);
      for(int i=begin;i>=0;i--)
         MABuffer[i]=iMAOnArray(IndBuffer,rates_total,MAPeriod,0,MAMethod,i);
     }
//--- apply to price
   else
      for(int i=begin;i>=0;i--)
        { 
         IndBuffer[i]=iMA(_Symbol,_Period,1,0,MODE_SMA,(ENUM_APPLIED_PRICE)ApplyTo,i);
         MABuffer[i]=iMA(_Symbol,_Period,MAPeriod,0,MAMethod,(ENUM_APPLIED_PRICE)ApplyTo,i);
        }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Files:
Apply_To.mq4  5 kb
 
Ernst Van Der Merwe #:
Hi, thank you for sharing your codes. I manage to replicate my manual indicator setup. I have been trying to change the source price in RSI function for the past 3 days with the help of chatgpt but it all fail to show any value.

Chatgpt never recommend me to use iRSIOnArray so I able to use any variable for storing source price i want instead of fixed double.

It was fun journey tho 😂 
 
beee:i've searched in the forum and still not finding the sample code that will enable me to do the above for my indicator.
Use the format of OnCalculate as defined in MT5 documentation containing price.
 
@William Roeder #: Use the format of OnCalculate as defined in MT5 documentation containing price.

This is the MQL4 section. It does not support the second format using "price", as defined in the MQL5 documentation.

 
@hundredX #: Hi, thank you for sharing your codes. I manage to replicate my manual indicator setup. I have been trying to change the source price in RSI function for the past 3 days with the help of chatgpt but it all fail to show any value. Chatgpt never recommend me to use iRSIOnArray so I able to use any variable for storing source price i want instead of fixed double. It was fun journey tho 😂 
Please stop using ChatGPT AI to generate MQL code. It produces horrible results. Learn to code it properly yourself.
 
Ernst Van Der Merwe #:

Help me!

I want to code a hybrid indicator for an mt4 application. I will use the Accumulation/Distribution indicator as the main indicator, then I will add 3 Moving Averages with 3 different periods to the Accumulation/Distribution indicator, the data of the Moving Average indicator will take data of the Accumulation/distribution indicator as input in the form of "first indicator's data"

I have the file thanks to "chat box" write the help code below

Thanks !

Files:
ADMA.mq4  3 kb