QuestionConvert "RMA" function from tradingview to mt4

1
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;
}


Re: Convert "RMA" function from tradingview to mt4

2
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.
These users thanked the author mrtools for the post:
meemee

Who is online

Users browsing this forum: Amazon [Bot] and 28 guests