Attachments forums

List of attachments posted on this forum.


All files on forums: 162089

Re: Convert "RMA" function from tradingview to mt4

mrtools, Wed Jun 10, 2020 11:43 am

meemee wrote: Tue Jun 09, 2020 9:28 pm 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)
Anmerkung 2020-06-09 161430.png

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;
}
Found a mt5 version by Mladen.
All files in topic