create MACDonRSI on array

 

hi

my code:

#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <RSIOnArray.mqh>
extern int bar=300;
extern int periodd;
int MA=3;
int RSIperiod=2;
int FastEMA=6;
int SlowEMA=12;
int SignalSMA=3;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
  ENUM_MA_METHOD ma_metthod=MODE_SMA;
  double closes[],MAs[],RSIs[],MACDs[];
  
  ArrayResize(closes,bar);
  ArrayResize(MAs,bar);
  ArrayResize(RSIs,bar);
  ArrayResize(MACDs,bar);
  for(int i=0;i<bar;i++)closes[i]=close(i);
  for(int i=0;i<bar;i++)MAs[i]=iMAOnArray(closes,MA,ma_metthod,i);
  for(int i=0;i<bar;i++)RSIs[i]=rsi(MAs,i);
  for(int i=0;i<bar;i++)MACDs[i]=8*(iMAOnArray(RSIs,FastEMA,MODE_EMA,i)-iMAOnArray(RSIs,SlowEMA,MODE_EMA,i));
  
  ArrayReverse(MACDs);
   Comment(MACDs[1]);
  }
//+------------------------------------------------------------------+
double close(int num){return iClose(_Symbol,0,num);}
double rsi(double &array[],int num){return NormalizeDouble(iRSIOnArray(array,0,RSIperiod,num),2);}
double iMAOnArray(double &array[],
                      int period,
                      int ma_method,
                      int shift)
  {
   double buf[],arr[];
   int total=0;
   int ma_shift=0;
   if(total==0) total=ArraySize(array);
   if(total>0 && total<=period) return(0);
   if(shift>total-period-ma_shift) return(0);
   switch(ma_method)
     {
      case MODE_SMA :
        {
         total=ArrayCopy(arr,array,0,shift+ma_shift,period);
         if(ArrayResize(buf,total)<0) return(0);
         double sum=0;
         int    i,pos=total-1;
         for(i=1;i<period;i++,pos--)
            sum+=arr[pos];
         while(pos>=0)
           {
            sum+=arr[pos];
            buf[pos]=sum/period;
            sum-=arr[pos+period-1];
            pos--;
           }
         return(buf[0]);
        }
      case MODE_EMA :
        {
         if(ArrayResize(buf,total)<0) return(0);
         double pr=2.0/(period+1);
         int    pos=total-2;
         while(pos>=0)
           {
            if(pos==total-2) buf[pos+1]=array[pos+1];
            buf[pos]=array[pos]*pr+buf[pos+1]*(1-pr);
            pos--;
           }
         return(buf[shift+ma_shift]);
        }
      case MODE_SMMA :
        {
         if(ArrayResize(buf,total)<0) return(0);
         double sum=0;
         int    i,k,pos;
         pos=total-period;
         while(pos>=0)
           {
            if(pos==total-period)
              {
               for(i=0,k=pos;i<period;i++,k++)
                 {
                  sum+=array[k];
                  buf[k]=0;
                 }
              }
            else sum=buf[pos+1]*(period-1)+array[pos];
            buf[pos]=sum/period;
            pos--;
           }
         return(buf[shift+ma_shift]);
        }
      case MODE_LWMA :
        {
         if(ArrayResize(buf,total)<0) return(0);
         double sum=0.0,lsum=0.0;
         double price;
         int    i,weight=0,pos=total-1;
         for(i=1;i<=period;i++,pos--)
           {
            price=array[pos];
            sum+=price*i;
            lsum+=price;
            weight+=i;
           }
         pos++;
         i=pos+period;
         while(pos>=0)
           {
            buf[pos]=sum/weight;
            if(pos==0) break;
            pos--;
            i--;
            price=array[pos];
            sum=sum-lsum+price*period;
            lsum-=array[i];
            lsum+=price;
           }
         return(buf[shift+ma_shift]);
        }
      default: return(0);
     }
   return(0);
  }

i copy iMAonarray from this site and download RSIonarray from this site too.

i have seen this structure in macdonrsi.ex4 source code in mt4 

please tell me why the result is wrong.

please  please  please help me! its very important for me to create my own macdonrsi

if you dont have an idea to modify my code do you have the functional that was previously posted on the site?
 

 

You want to create an indicator, no?

Then start by clicking on "New" to create a template for your indicator.

New