I have the function below in Thinkscript and I want to translate it into NinjaScript. I am struglling with the averages in the NetChgAvg1 and TotChgAvg1. Can someone please help me?
What I'm trying to do is calculate the average of the difference between the close of the current candle and the previous one for the past 14 periods.
Thanks in advance!
#------ ThinkScript ---------------
def NetChgAvg1 = MovingAverage(AverageType.WILDERS, close - close[1], 14);
def TotChgAvg1 = MovingAverage(AverageType.WILDERS, AbsValue(close - close[1]), 14);
def ChgRatio1 = if TotChgAvg1 != 0 then NetChgAvg1 / TotChgAvg1 else 0;
def RSI = 50 * (ChgRatio1 + 1);
//------ NinjaScript ---------------
//First attempt
private Series<double> NetChgAvg1;
private Series<double> TotChgAvg1;
private double ChgRatio1;
private double RSI_custom;
// The above is in the declarations
NetChgAvg1 = (Close - Close[1]).Avg(14);
TotChgAvg1 = Math.Abs(Close - Close[1]).Avg(14);
if (TotChgAvg1 != 0)
{
ChgRatio1 = NetChgAvg1 / TotChgAvg1;
}else
{
ChgRatio1 = 0;
}
;
RSI_custom = 50 * (ChgRatio1 + 1);
Comment