1

I have seen numerous posts in this forum asking about this function in pinescript but so far none of them provide an answer to how the third parameter "offset" is used to modify the computation inside the function.

Here is the description of that function provided by TradingView:

https://www.tradingview.com/pine-script-reference/v4/#fun_linreg

I found that if you provide a value of zero for the offset parameter in pinescript the output is exactly the same as a function named "Inertia()" on Thinkorswim. TD Ameritrade provides a detailed example of how their function is computed. Listed here:

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Statistical/Inertia

Here is the code from that link:

script inertiaTS {
    input y = close;
    input n = 20;
    def x = x[1] + 1;
    def a = (n * Sum(x * y, n) - Sum(x, n) * Sum(y, n) ) / ( n * Sum(Sqr(x), n) - Sqr(Sum(x, n)));
    def b = (Sum(Sqr(x), n) * Sum(y, n) - Sum(x, n) * Sum(x * y, n) ) / ( n * Sum(Sqr(x), n) - Sqr(Sum(x, n)));
    plot InertiaTS = a * x + b;
}

input length = 20;
plot LinReg1 = Inertia(close, length);
plot LinReg2 = InertiaTS(close, length);

My question is this. How to modify the formula in that code for Thinkorswim so that it includes a parameter that works equivalent to the "offset" parameter in pinescript.

Pete Hahn
  • 21
  • 6
  • were you able to figure this out ? – Yusuf May 13 '22 at 15:20
  • 1
    Yes. I found a built-in function on the TradeStation platform named "LinearReg". The third input parameter is named "TgtBar" and this functions the same exact way as the third input parameter from the TradingView version, which is named "offset". So you can use the TradeStation LingearReg function that comes with that platform. Details here: https://help.tradestation.com/10_00/eng/tsdevhelp/elword/function/linearreg_function_.htm?Highlight=linearreg If you are familiar with the language on TradeStation and Thinkorswim you should find it pretty simple to translate. – Pete Hahn May 14 '22 at 19:27

0 Answers0