Adding horizontal lines without changing scale

jeremy1338

New member
I'm trying to create a basic indicator in ThinkScript that automatically plots horizontal lines based on Fib retracements from different timeframes for SPX. However, when I add lines that are outside of a timeframe (such as 1D), the scale of the chart gets messed up so that ToS shows every line it's plotting. Is there something simple I can add to my code so that it only shows the price range that would typically be visible in a given timeframe, without warping it to display every line?

Here is a sample of the code, it's all basically the same format with lines ranging from 2191 to 4813:
Code:
plot Fire1year1 = 3636;
Fire1year1.AssignValueColor(color.red);
Fire1year1.SetLineWeight(3);
 
I'm trying to create a basic indicator in ThinkScript that automatically plots horizontal lines based on Fib retracements from different timeframes for SPX. However, when I add lines that are outside of a timeframe (such as 1D), the scale of the chart gets messed up so that ToS shows every line it's plotting. Is there something simple I can add to my code so that it only shows the price range that would typically be visible in a given timeframe, without warping it to display every line?

Here is a sample of the code, it's all basically the same format with lines ranging from 2191 to 4813:
Code:
plot Fire1year1 = 3636;
Fire1year1.AssignValueColor(color.red);
Fire1year1.SetLineWeight(3);

i think i understand.
you don't want lines to draw when they are far away from the candles.


here is an example study to look at
it finds the highest and lowest $ on a chart.
then adds in a % factor to extend the vertical range,
if a price level is within the extended range, the line is drawn


Code:
# disable_lines_far_away_0

def na = double.nan;

def top2 = highestall(high);
def bot2 = lowestall(low);
def rng2 = top2 - bot2;
addlabel(1, "lowest " + bot2, color.yellow);
addlabel(1, "highest " + top2, color.yellow);


input range_exp_percent = 99;
def top = top2 + (rng2 * (range_exp_percent/2) / 100);
def bot = bot2 - (rng2 * (range_exp_percent/2) / 100);

addlabel(1, " " , color.black);
addlabel(1, "adjusted lower limit " + bot, color.yellow);
addlabel(1, "adjusted upper limit " + top, color.yellow);


input show_all_lines = yes;

input x1 = 50;
plot p1 = if show_all_lines or between(x1, bot, top) then x1 else na;
p1.AssignValueColor(color.red);
p1.SetLineWeight(3);

input x2 = 74;
plot p2 = if show_all_lines or between(x2, bot, top) then x2 else na;
p2.AssignValueColor(color.red);
p2.SetLineWeight(3);

input x3 = 100;
plot p3 = if show_all_lines or between(x3, bot, top) then x3 else na;
p3.AssignValueColor(color.red);
p3.SetLineWeight(3);

input x4 = 125;
plot p4 = if show_all_lines or between(x4, bot, top) then x4 else na;
p4.AssignValueColor(color.red);
p4.SetLineWeight(3);

#
 

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
608 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