Average of RSI and MFI

 
Hi there, 

Anyone can help to combine RSI and MFI indicator together? I am trying to create an indicator in separate windows which shows (RSI+MFI)/2. 

I tried to combine these 2 indicator with no luck. I appreciate your help. 
 
Maybe we can use iRSI & iMFI to calculate the numbers then create indicator windows using the result? I couldn't figure out how to do that. 
 
Really guys? no one here knows how to do this? 
 
n4r30s:
Really guys? no one here knows how to do this? 
maybe there are but they may not be interested doing this for free.....and if thats the case you simply use Freelance service!
 
Kenneth Parling:
maybe there are but they may not be interested doing this for free.....and if thats the case you simply use Freelance service!

Thank you Kenneth, I just needed some guidance or tips, That's not about money, I like to learn how to do it. 

 
Have a look in CodeBase for a simple indicator, then just change the logic to use iMFI and iRSI
 
n4r30s:

Thank you Kenneth, I just needed some guidance or tips, That's not about money, I like to learn how to do it. 

whether you like it or not...that's how things work - if no one helps you out for free then you have to pay a coder to do it for you

 

Thanks to iRick, I've managed to write this code, it's showing RSI and MFI.

The only part I couldn't figure out is how to get data from iMFIBuffer and iRSIBuffer and put their average into iAVGBuffer. 

I appreciate your help.

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3
#property indicator_label1  "RSI"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrNavy
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_label2  "MFI"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrDarkGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
#property indicator_label3  "AVG"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrSalmon
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1


#property indicator_maximum 100
#property indicator_minimum 0
#property indicator_level1  70.0
#property indicator_level2  30.0

input int                  ma_period=14;                 
input ENUM_APPLIED_PRICE   applied_price=PRICE_CLOSE;    
ENUM_APPLIED_VOLUME  applied_volume=VOLUME_TICK;   
string               symbol=" ";                   
ENUM_TIMEFRAMES      period=PERIOD_CURRENT;        

double         iRSIBuffer[],iMFIBuffer[],iAVGBuffer[];
int    handle,handle2;
string name=symbol;
int    bars_calculated=0;
int OnInit()
  {
   SetIndexBuffer(0,iRSIBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(0, PLOT_SHIFT, 0);
   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, ma_period);
   PlotIndexSetString(0, PLOT_LABEL, "RSI"); 

   SetIndexBuffer(1,iMFIBuffer,INDICATOR_DATA);      
   PlotIndexSetInteger(1, PLOT_SHIFT, 0);
   PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, ma_period);
   PlotIndexSetString(1, PLOT_LABEL, "MFI"); 

   SetIndexBuffer(2,iAVGBuffer,INDICATOR_DATA);      
   PlotIndexSetInteger(2, PLOT_SHIFT, 0);
   PlotIndexSetInteger(2, PLOT_DRAW_BEGIN, ma_period);
   PlotIndexSetString(2, PLOT_LABEL, "AVG"); 

   name=symbol;
   StringTrimRight(name);
   StringTrimLeft(name);
   if(StringLen(name)==0)
     {
      name=_Symbol;
     }
      handle=iRSI(name,period,ma_period,applied_price);
      handle2=iMFI(name,period,ma_period,applied_volume); 
      
   if(handle==INVALID_HANDLE || handle2==INVALID_HANDLE)
     {
      PrintFormat("Failed to create handle of the indicator for the symbol %s/%s, error code %d",
                  name,
                  EnumToString(period),
                  GetLastError());
      return(INIT_FAILED);
     }

//IndicatorSetString(INDICATOR_SHORTNAME,"Avg(RSI,MFI)");
   return(INIT_SUCCEEDED);
  }

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 values_to_copy;
   int calculated=BarsCalculated(handle);
   if(calculated<=0 )
     {
      PrintFormat("BarsCalculated() returned %d, error code %d",calculated,GetLastError());
      return(0);
     }
   if(prev_calculated==0 || calculated!=bars_calculated || rates_total>prev_calculated+1)
     {
      if(calculated>rates_total) values_to_copy=rates_total;
      else                       values_to_copy=calculated;
     }
   else
     {
      values_to_copy=(rates_total-prev_calculated)+1;
     }
     
  
   if(!FillArrayFromBuffer(iMFIBuffer,handle2,values_to_copy)) return(0);   
   if(!FillArrayFromBuffer(iRSIBuffer,handle,values_to_copy)) return(0);

   //Comment(StringFormat("Value = %f\nValue2 = %f",values_to_copy,calculated-1));

   bars_calculated=calculated;
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Filling indicator buffers from the indicator                |
//+------------------------------------------------------------------+

bool FillArrayFromBuffer(double &value[],  // indicator buffer of values
                         int ind_handle,        // handle of the indicator
                         int amount             // number of copied values
                         )
  {
   ResetLastError();
   if(CopyBuffer(ind_handle,0,0,amount,value)<0)
     {
      PrintFormat("Failed to copy data from the indicator, error code %d",GetLastError());
      return(false);
     }
   return(true);
  }
//+------------------------------------------------------------------+
//| Indicator deinitialization function                              |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   if(handle!=INVALID_HANDLE && handle2!=INVALID_HANDLE)
      IndicatorRelease(handle);
      IndicatorRelease(handle2);
//--- clear the chart after deleting the indicator
   Comment("");
  }     
 
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 3
#property indicator_plots   1
//--- plot MFRSI
#property indicator_label1  "MFRSI"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDeepSkyBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_level1  30
#property indicator_level2  70
//--- input parameters
input int      RSIPeriod=14;
input ENUM_APPLIED_PRICE RSIPrice=PRICE_CLOSE;
input int      MFIPeriod=14;
input ENUM_APPLIED_VOLUME MFIVolume=VOLUME_TICK;
//--- indicator buffers
double         RSIBuffer[];
double         MFIBuffer[];
double         MFRSIBuffer[];
//---
int handleRSI,handleMFI;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,MFRSIBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,RSIBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,MFIBuffer,INDICATOR_CALCULATIONS);
//---
   if((handleRSI=iRSI(_Symbol,_Period,RSIPeriod,RSIPrice))==INVALID_HANDLE ||
      (handleMFI=iMFI(_Symbol,_Period,MFIPeriod,MFIVolume))==INVALID_HANDLE)
      return(INIT_FAILED);
//---
   IndicatorSetInteger(INDICATOR_DIGITS,1);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
//---
   if(BarsCalculated(handleRSI)<rates_total ||
      BarsCalculated(handleMFI)<rates_total)
      return(0);
//---
   int toCopy=rates_total!=prev_calculated?rates_total-prev_calculated:1;
//---
   if(CopyBuffer(handleRSI,0,0,toCopy,RSIBuffer)!=toCopy ||
      CopyBuffer(handleMFI,0,0,toCopy,MFIBuffer)!=toCopy)
      return(0);
//---
   int limit=rates_total!=prev_calculated?prev_calculated:prev_calculated-1;
//---
   for(int i=limit;i<rates_total && !_StopFlag;i++)
      MFRSIBuffer[i]=(RSIBuffer[i]+MFIBuffer[i])/2;   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Files:
MFRSI.mq5  3 kb
 
Ernst Van Der Merwe:
Awesome, much simpler and beautiful. Thank you very much and I've learned a lot from your code.