I am attempting to replicate an indicator I have used on other platforms. I am getting an error on one portion of the code when attempting to compile. The error seems to be related to the LinReg indicator/function.
The indicator is named Squeeze Momentum Indicator in the Ninjatrader public library, and it attempts to mimic the TTM Squeeze from Thinkorswim. This iteration seems to have been taken from Tradingview Pinescript. The LinReg function is used to plot the histogram of the indicator.
------------------------------------------------------------------------------------------------------------
Thinkorswim Thinkscript Code (Inertia is the Thinkorswim version of LinReg):
def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length);
def momo = Inertia(price - K / 2, length); <<<< histogram values
-------------------------------------------------------------------------------------------------------
Tradingview Pinescript Code:
K = (highest(high,length) + lowest(low,length)) / 2 + ema(close,length)
Momo = linreg(source-K/2,length,0) <<<< histogram values
-------------------------------------------------------------------------------------------------------
Ninjatrader Code that isn't working:
double h = High[HighestBar(High, LengthKC)];
double l = Low[LowestBar(Low, LengthKC)];
// calculate Value
data[0] = Close[0];
double ema = EMA(data,LengthBB)[0];
double avg = ((h + l) / 2) + ema;
IsSqueezes[0] = 0.0;
SqueezeDef[0] = LinReg(data[0]-avg/2,LengthBB); <<<< histogram values
-------------------------------------------------------------------------------------------------------
I've attached a screenshot of the bulk of the code in Ninjatrader, which also includes the error codes that have been generated. It looks like LinReg might require the 'series' data type in the first input (second screenshot attached), so I'm not sure how to proceed here, but there must be a way to do this if other similar trading applications can manage it.
Any help would be much appreciated!!
Thank you
Comment