This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:

We work extremely hard to keep things positive on our forums.

We do not tolerate rude behavior, trolling, or vendor advertising in posts.

We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.

We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

Hi,
can anyone to help me with this TOS function for Inertia:
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;
}

My question is what is X (def x = x[1] + 1 and what is n=20 (maybe it is default length? )
I am totaly confused of X meaning.
Is there anybody who can translate this to Java or C++ ?
Thanks in advance.

There is a built-in study called Inertia. I am unsure if is the same thing as the sample code provided. Information about the study is at tlc.thinkorswim.com/center/charting/studies/studies-library/G-L/Inertia.html (<--- this is a url and i can't post links yet)

The study takes two parameters
- length for "The number of bars used to calculate the linear regression curve." I believe this is what the 20 value represents in the code.
- rvi lenght for "The number of bars used to calculate the Relative Volatility Index." I believe this is what X is.

With thinkScript (the API for thinkDesktop or what people usually call thinkOrSwim) the [1] means the prior bar/day/whatever.

For example, if I want to see what the prior day high was I would do this

If I want to see what the prior day was two days ago I would do this

This code can be easily ported to C++ or JAVA. However, with that being said I am sure you use a particular platform that has C++/JAVA as a API?

The following user says Thank You to RHcZL0Mfs for this post:

i dont use API for now. My broker is IB and they have API but i trying to develop simple soft to help me with my option trading. Unfortunately my level of programing(and math) is 0 and my programer trading level is 0 too

so what u mean with: "rvi lenght for "The number of bars used to calculate the Relative Volatility Index." I believe this is what X is." just rvi length or rvi number for that length ?