NexusFi: Find Your Edge


Home Menu

 





Help about TOS function


Discussion in ThinkOrSwim

Updated
    1. trending_up 4,714 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 alchemist74 
Sofia, Bulgaria
 
Experience: Advanced
Platform: IB,TOS
Broker: IB
Trading: Options,ES,6E,ZB,SPX,RUT,CL
Posts: 47 since Jul 2010
Thanks Given: 6
Thanks Received: 42

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;
}

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

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.


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
April 2026 Jobs Report: +115k vs +65k Expected
Traders Hideout
One Wallet Made $200K in Hours: AP Probes Polymarket Cea …
Prediction Markets & Event Contracts
Cboe Files for Near 24x5 Equities Trading -- December 20 …
Traders Hideout
Iran Fired a Missile at Israel Last Night. The $8M June …
Prediction Markets & Event Contracts
$134M Ground Entry Contract in Disputed Final Review Aft …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
132 thanks
Sober Journey With S&P
33 thanks
500 MES points a week
13 thanks
Understanding Risk
6 thanks
MES Trader Journal & Market Structure Discussion
6 thanks
  #2 (permalink)
 RHcZL0Mfs 
Chicago
 
Experience: Advanced
Platform: ThinkOrSwim
Trading: options
Posts: 11 since Dec 2013
Thanks Given: 3
Thanks Received: 8

I could be incorrect saying this.

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
 
Code
plot yHigh = high (period = "day")[1];

If I want to see what the prior day was two days ago I would do this
 
Code
plot yHigh = high (period = "day")[2];

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?


Reply With Quote
Thanked by:
  #3 (permalink)
 alchemist74 
Sofia, Bulgaria
 
Experience: Advanced
Platform: IB,TOS
Broker: IB
Trading: Options,ES,6E,ZB,SPX,RUT,CL
Posts: 47 since Jul 2010
Thanks Given: 6
Thanks Received: 42


Thx RHcZL0Mfs for your answer.

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 ?

thx again for your answer and Happy New Year !


Started this thread Reply With Quote
  #4 (permalink)
jonshengit
Pleasanton CA/USA
 
Posts: 1 since Aug 2020
Thanks Given: 0
Thanks Received: 0

i came cross this post.

I am looking at LeavittConvolutionSlope. I notice the LeavittConvolutionSlope use Time Series Forecast which use Inertia.

The ta-lib provides TSF - Time Series Forecast.

if your purpose is to get LeavittConvolutionSlope work, Inertia can be bypass using ta-lib.TSF.


Reply With Quote




Last Updated on August 25, 2020


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts