Convert "RMA" function from tradingview to mt4
Posted: 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) My current MT4 Code
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;
}