Linear Regression Channel (5D1h) to be plotted on 5 min chart

waiwai006

New member
Hi, I am new here.

I am working on Thinkscript to display linear regression channel from a (5D1h) timeframe in a 5min chart.

I tried to to alter the aggreation period like below, however, the Linear Regression Channel's value plotted on 5min (in same interval of 5Days) chart is not the same as the 5D1h chart. Could anyone shed some light? Thanks!


input aggregationPeriod = AggregationPeriod.HOUR;
def price = close(period = aggregationPeriod);

plot MiddleLR = InertiaAll(price);
def dist = HighestAll(AbsValue(MiddleLR - price));
plot UpperLR = MiddleLR + dist;
plot LowerLR = MiddleLR - dist;

MiddleLR.setDefaultColor(GetColor(5));
UpperLR.setDefaultColor(GetColor(5));
LowerLR.setDefaultColor(GetColor(5));

plot MiddleLR2 = InertiaAll(price);
def dist2 = HighestAll(AbsValue(MiddleLR2 - price)) * 0.5;
plot UpperLR2 = MiddleLR2 + dist2;
plot LowerLR2 = MiddleLR2 - dist2;

MiddleLR2.setDefaultColor(GetColor(1));
UpperLR2.setDefaultColor(GetColor(1));
LowerLR2.setDefaultColor(GetColor(1));
 
Solution
Thanks for the detailed reply.

I tried to follow along your approach but it seems that the "HighestAll" method does not accept "length" as a parameter?

I got the following error: params expected but 2 found while calling highestall at 13:12

Sorry!
I was typing too fast on my phone.
No, there is no HighestAll, it's just Highest

Here Ya go:

So you would change:
plot MiddleLR = InertiaAll(price);
def dist = HighestAll(AbsValue(MiddleLR - price));
To:
input length = however many bars are on your hourly chart *12 ;
plot MiddleLR = InertiaAll(price,length);
def dist = Highest(AbsValue(MiddleLR - price),length);
Hi, I am new here.

I am working on Thinkscript to display linear regression channel from a (5D1h) timeframe in a 5min chart.

I tried to to alter the aggreation period like below, however, the Linear Regression Channel's value plotted on 5min (in same interval of 5Days) chart is not the same as the 5D1h chart. Could anyone shed some light? Thanks!


input aggregationPeriod = AggregationPeriod.HOUR;
def price = close(period = aggregationPeriod);

plot MiddleLR = InertiaAll(price);
def dist = HighestAll(AbsValue(MiddleLR - price));
plot UpperLR = MiddleLR + dist;
plot LowerLR = MiddleLR - dist;

MiddleLR.setDefaultColor(GetColor(5));
UpperLR.setDefaultColor(GetColor(5));
LowerLR.setDefaultColor(GetColor(5));

plot MiddleLR2 = InertiaAll(price);
def dist2 = HighestAll(AbsValue(MiddleLR2 - price)) * 0.5;
plot UpperLR2 = MiddleLR2 + dist2;
plot LowerLR2 = MiddleLR2 - dist2;

MiddleLR2.setDefaultColor(GetColor(1));
UpperLR2.setDefaultColor(GetColor(1));
LowerLR2.setDefaultColor(GetColor(1));


InertiaAll(price); and HighestAll have no length defined. Therefore, they default to using all the bars on your chart.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Statistical/InertiaAll

If you are attempting to "match" the MTF plot on your 5min chart to your plot on the hourly chart then your 5min chart requires 12 bars for every 1 bar on your hourly chart.
So if you have 40 candles on your hourly chart, you need to have exactly 480 candles on your 5min chart.

The workaround would be instead of using the default, provide the lengths to base your calculations on.

So you would change:
plot MiddleLR = InertiaAll(price);
def dist = HighestAll(AbsValue(MiddleLR - price));
To:
input length = however many bars are on your hourly chart *12 ;
plot MiddleLR = InertiaAll(price,length);
def dist = Highest(AbsValue(MiddleLR - price),length);
where the length for the 5min chart is set to 12x the length on whatever you set the length of the hourly chart. This would allow you to have apples and apples.

Keep in mind:
You will also have to deal with the fact that ToS no longer updates any of the ALL functions in real time. So they might not match until the hourly candle closes:
https://usethinkscript.com/threads/...e-no-update-in-real-time-in-thinkorswim.8794/
 
Last edited:
InertiaAll(price); and HighestAll have no length defined. Therefore, they default to using all the bars on your chart.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Statistical/InertiaAll

If you are attempting to "match" the MTF plot on your 5min chart to your plot on the hourly chart then your 5min chart requires 12 bars for every 1 bar on your hourly chart.
So if you have 40 candles on your hourly chart, you need to have exactly 480 candles on your 5min chart.

The workaround would be instead of using the default, provide the lengths to base your calculations on.

So you would change:

To:

where the length for the 5min chart is set to 12x the length on whatever you set the length of the hourly chart. This would allow you to have apples and apples.

Keep in mind:
You will also have to deal with the fact that ToS no longer updates any of the ALL functions in real time. So they might not match until the hourly candle closes:
https://usethinkscript.com/threads/...e-no-update-in-real-time-in-thinkorswim.8794/
Thanks for the detailed reply.

I tried to follow along your approach but it seems that the "HighestAll" method does not accept "length" as a parameter?

I got the following error: params expected but 2 found while calling highestall at 13:12
 
Thanks for the detailed reply.

I tried to follow along your approach but it seems that the "HighestAll" method does not accept "length" as a parameter?

I got the following error: params expected but 2 found while calling highestall at 13:12

Sorry!
I was typing too fast on my phone.
No, there is no HighestAll, it's just Highest

Here Ya go:

So you would change:
plot MiddleLR = InertiaAll(price);
def dist = HighestAll(AbsValue(MiddleLR - price));
To:
input length = however many bars are on your hourly chart *12 ;
plot MiddleLR = InertiaAll(price,length);
def dist = Highest(AbsValue(MiddleLR - price),length);
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
155 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top