Attachments forums

List of attachments posted on this forum.


All files on forums: 135651

Convert "RMA" function from tradingview to mt4

meemee, Wed Jun 10, 2020 12:15 am

Can someone help me convert this function from tradingview to mt4? I'm currently learning both languages while trying to convert an indicator from the one to the other. I'm now stuck with this function.

The code I'm stuck with (pine script) My current MT4 Code

Code: Select all

double rma(const double & high[],const double & low[], const double & close[], int shift,int length){
   double sum = getTrSMA(high,low,close,shift,length); 
   double alpha = 1.0/length; 
   
   for(int i = shift+length;i >= shift; i--){
      sum = alpha * MathMax(high[i]-low[i],MathMax(MathAbs(high[i]-close[i+1]),MathAbs(low[i]-close[i+1]))) + (1.0-alpha)*sum;
   }
   
   return sum;
}

// Truerange SMA
double getTrSMA(const double & high[], const double & low[], const double & close[],int shift, int length){
   double avg = 0.0;
   for(int i = length+shift-1; i >= shift;i--){
      avg = avg + MathMax(high[i]-low[i],MathMax(MathAbs(high[i]-close[i+1]),MathAbs(low[i]-close[i+1])));
   }
   
   return avg / length;
}
All files in topic