Horizontal Lines In ThinkOrSwim

Hello there, need help.
I thought it was something basic, but I couldn't find nothing among the answers.
I would like to plot horizontal lines among consecutive prices, por example:
plot each 0.5 dollars,
plot each 1 dollar,
plot each 5 dollars,
plot each 10 dollars,

Would be 4 plots in total , so I can activate and deactivate them as I want. If its a penny stock I would use every 0.5 and if its AMZN I would use every 10..

The solutions I previously find suggest to put it manually, for example:
plot line1 = 5;
plot line2 = 10;
And you end up with hundreds of plots..
Im sure there is a more efficient way.
 

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

Hello there, need help.
I thought it was something basic, but I couldn't find nothing among the answers.
I would like to plot horizontal lines among consecutive prices, por example:
plot each 0.5 dollars,
plot each 1 dollar,
plot each 5 dollars,
plot each 10 dollars,

Would be 4 plots in total , so I can activate and deactivate them as I want. If its a penny stock I would use every 0.5 and if its AMZN I would use every 10..

The solutions I previously find suggest to put it manually, for example:
plot line1 = 5;
plot line2 = 10;
And you end up with hundreds of plots..
Im sure there is a more efficient way.

This may give you some ideas. There are no ways around having to create a 'plot' for each line. However, this can automate it somewhat. Add more lines and style by copying and pasting the current 7 groups and make the minor changes.

Screenshot-2021-08-13-144529.jpg
Ruby:
def price  = if SecondsFromTime(0930) == 0 then open else price[1];
def xopen  = if GetDay() == GetLastDay()
             then
             HighestAll(if IsNaN(close[-1]) and !IsNaN(close)
                        then open(period = AggregationPeriod.DAY)
                        else 0)
             else Double.NaN;
def range  = if Between(xopen, 0, 2)
             then .10 else
             if Between(xopen, 2, 100)
             then .25 else
             if Between(xopen, 100, 500)
             then 1.0     
             else
             10.0;

plot x1_       = xopen - range;
plot x2_       = xopen - range * 2;
plot x3_       = xopen - range * 3;
plot x4_       = xopen - range * 4;
plot x5_       = xopen - range * 5;
plot x6_       = xopen - range * 6;
plot x7_       = xopen - range * 7;


plot x1       = xopen + range;
plot x2       = xopen + range * 2;
plot x3       = xopen + range * 3;
plot x4       = xopen + range * 4;
plot x5       = xopen + range * 5;
plot x6       = xopen + range * 6;
plot x7       = xopen + range * 7;

input lines = {default LINE, POINTS};
def paint = if lines == lines.POINTS then PaintingStrategy.POINTS else  PaintingStrategy.LINE;

x1.SetPaintingStrategy(paint);
x2.SetPaintingStrategy(paint);
x3.SetPaintingStrategy(paint);
x4.SetPaintingStrategy(paint);
x5.SetPaintingStrategy(paint);
x6.SetPaintingStrategy(paint);
x7.SetPaintingStrategy(paint);

x1.SetDefaultColor(Color.LIGHT_GRAY);
x2.SetDefaultColor(Color.LIGHT_GRAY);
x3.SetDefaultColor(Color.LIGHT_GRAY);
x4.SetDefaultColor(Color.LIGHT_GRAY);
x5.SetDefaultColor(Color.LIGHT_GRAY);
x6.SetDefaultColor(Color.LIGHT_GRAY);
x7.SetDefaultColor(Color.LIGHT_GRAY);

x1_.SetPaintingStrategy(paint);
x2_.SetPaintingStrategy(paint);
x3_.SetPaintingStrategy(paint);
x4_.SetPaintingStrategy(paint);
x5_.SetPaintingStrategy(paint);
x6_.SetPaintingStrategy(paint);
x7_.SetPaintingStrategy(paint);

x1_.SetDefaultColor(Color.LIGHT_GRAY);
x2_.SetDefaultColor(Color.LIGHT_GRAY);
x3_.SetDefaultColor(Color.LIGHT_GRAY);
x4_.SetDefaultColor(Color.LIGHT_GRAY);
x5_.SetDefaultColor(Color.LIGHT_GRAY);
x6_.SetDefaultColor(Color.LIGHT_GRAY);
x7_.SetDefaultColor(Color.LIGHT_GRAY);
 
This may give you some ideas. There are no ways around having to create a 'plot' for each line. However, this can automate it somewhat. Add more lines and style by copying and pasting the current 7 groups and make the minor changes.

thank you for posting this @SleepyZ. i learned something. i don't think i have seen a varaible used to hold a PaintingStrategy before.

to everyone who is learning thinkscript, take the time to read/skim through the codes that are posted on this site, even if you think you know the headline topic. sometimes you come across a different way of doing something. sometimes you may learn something.
i almost skipped over this post, because i know how to plot a line. luckily i didn't.

the study uses input to choose 1 word from several. then uses the value to determine the value for another variable, to set the PaintingStrategy.
 
Okay.. I manage arrange this, now i'm stuck.
What I want to do, is to take the open price of the day, round it, and then plot 7 horizontal lines above and below the open.
The problem is i would like the lines to extend to the left forever, straight, tidy, without gaps or anything.
And I'm not being able to achieve that.


Code:
input aggregationPeriod = AggregationPeriod.day;

def Open = Round(open(period = aggregationPeriod)[1], -1);

def range  = 5;

plot x1_       = Open;
plot x2_       = Open - range;
plot x3_       = Open - range * 2;
plot x4_       = Open - range * 3;
plot x5_       = Open - range * 4;
plot x6_       = Open - range * 5;
plot x7_       = Open - range * 6;


plot x1       = Open + range;
plot x2       = Open + range * 2;
plot x3       = Open + range * 3;
plot x4       = Open + range * 4;
plot x5       = Open + range * 5;
plot x6       = Open + range * 6;
plot x7       = Open + range * 7;

input lines = {default LINE, POINTS};
def paint = if lines == lines.POINTS then PaintingStrategy.POINTS else  PaintingStrategy.LINE;

x1.SetPaintingStrategy(paint);
x2.SetPaintingStrategy(paint);
x3.SetPaintingStrategy(paint);
x4.SetPaintingStrategy(paint);
x5.SetPaintingStrategy(paint);
x6.SetPaintingStrategy(paint);
x7.SetPaintingStrategy(paint);

x1.SetDefaultColor(Color.GRAY);
x2.SetDefaultColor(Color.GRAY);
x3.SetDefaultColor(Color.GRAY);
x4.SetDefaultColor(Color.GRAY);
x5.SetDefaultColor(Color.GRAY);
x6.SetDefaultColor(Color.GRAY);
x7.SetDefaultColor(Color.GRAY);

x1_.SetPaintingStrategy(paint);
x2_.SetPaintingStrategy(paint);
x3_.SetPaintingStrategy(paint);
x4_.SetPaintingStrategy(paint);
x5_.SetPaintingStrategy(paint);
x6_.SetPaintingStrategy(paint);
x7_.SetPaintingStrategy(paint);

x1_.SetDefaultColor(Color.GRAY);
x2_.SetDefaultColor(Color.GRAY);
x3_.SetDefaultColor(Color.GRAY);
x4_.SetDefaultColor(Color.GRAY);
x5_.SetDefaultColor(Color.GRAY);
x6_.SetDefaultColor(Color.GRAY);
x7_.SetDefaultColor(Color.GRAY);
 
Okay.. I manage arrange this, now i'm stuck.
What I want to do, is to take the open price of the day, round it, and then plot 7 horizontal lines above and below the open.
The problem is i would like the lines to extend to the left forever, straight, tidy, without gaps or anything.
And I'm not being able to achieve that.

See if changing open to this does what you want.

Code:
def Open = highestall(Round(open(period = aggregationPeriod)[1], -1));
 
I have a study that posts an arrow whenever a condition is met. What I want is for it to plot a line all the way across the chart after "x" condition is met and to always have that level be there. Just adding more levels the more the condition is met. Right now it only plots up to the next signal of the same type.
 
@MerryDay so basically what I am looking for is it already plots a line after a condition but it goes away after the condition is met again and is replaced by the new line. I can post an image example too. But basically, I want each new trigger to show up as a new line instead of replacing an old line
 
I have a study that posts an arrow whenever a condition is met. What I want is for it to plot a line all the way across the chart after "x" condition is met and to always have that level be there. Just adding more levels the more the condition is met. Right now it only plots up to the next signal of the same type.

As MerryDay indicated there is no easy way to plot multiple horizontal lines across the chart. Here is an example of how to do 5 or less horizontal lines plotted across the chart based upon a 'cond'. You can easily make additional conditional plots by copying/pasting/editing from the existing plots in this code.

Screenshot-2021-08-26-172056.jpg
Ruby:
input display = 5;
input price   = high;
def cond      = if MACD().diff crosses 0 then 1 else Double.NaN;
def condx     = if !IsNaN(cond) then condx[1] + 1 else condx[1];
def xcond     = if condx != condx[1] then condx else Double.NaN;

plot x1 = HighestAll(if display >= 1 and (condx) == HighestAll(xcond) - 0 then price else Double.NaN);
x1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot x2 = HighestAll(if display >= 2 and (condx) == HighestAll(xcond) - 1 then price else Double.NaN);
x2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot x3 = HighestAll(if display >= 3 and (condx) == HighestAll(xcond) - 2 then price else Double.NaN);
x3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot x4 = HighestAll(if display >= 4 and (condx) == HighestAll(xcond) - 3 then price else Double.NaN);
x4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
plot x5 = HighestAll(if display >= 5 and (condx) == HighestAll(xcond) - 4 then price else Double.NaN);
x5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DefineGlobalColor("x", Color.CYAN);
x1.SetDefaultColor(GlobalColor("x"));
x2.SetDefaultColor(GlobalColor("x"));
x3.SetDefaultColor(GlobalColor("x"));
x4.SetDefaultColor(GlobalColor("x"));
x5.SetDefaultColor(GlobalColor("x"));
 
Last edited:
Hello, first time posting here. Please be kind if this is a dumb question.

I am trying to plot a defined length line, from the current date, for n# bars in the past. I use Ichimoku, so I'd like to be able to plot a line that goes back in the past for 26 bars from the current bar. Is that something that is possible to do in Thinkscript? I can write basic thinkscript, but cannot figure out how to do this.

I very much appreciate any suggestions that you can offer.


Thank you,


Mike M
 
Hello, first time posting here. Please be kind if this is a dumb question.

I am trying to plot a defined length line, from the current date, for n# bars in the past. I use Ichimoku, so I'd like to be able to plot a line that goes back in the past for 26 bars from the current bar. Is that something that is possible to do in Thinkscript? I can write basic thinkscript, but cannot figure out how to do this.

I very much appreciate any suggestions that you can offer.


Thank you,


Mike M

Here's one way

Ruby:
input barsback = 26;
def last  = HighestAll(if !IsNaN(close) and IsNaN(close[-1]) then BarNumber() else 0);
plot Data = if Between(BarNumber(), last - barsback, last) then close(period = AggregationPeriod.DAY) else Double.NaN;
 
Code:
plot signal = HighestAll(if display >= 1 and (cond1x) == HighestAll(x1cond) - 0 then price else Double.NaN);
     signal.setpaintingStrategy(PaintingStrategy.dashes);
     signal.setDefaultColor(Color.cyan);
     signal.SetLineWeight(3);

plot signalx = HighestAll(if display >= 2 and (cond1x) == HighestAll(x1cond) - 1 then price else Double.NaN);
     signalx.setpaintingStrategy(PaintingStrategy.dashes);
     signalx.setDefaultColor(Color.cyan);
     signalx.SetLineWeight(3);

plot signalxx = HighestAll(if display >= 3 and (cond1x) == HighestAll(x1cond) - 2 then price else Double.NaN);
     signalxx.setpaintingStrategy(PaintingStrategy.dashes);
     signalxx.setDefaultColor(Color.cyan);
     signalxx.SetLineWeight(3);

plot signalxxx = HighestAll(if display >= 4 and (cond1x) == HighestAll(x1cond) - 3 then price else Double.NaN);
     signalxxx.setpaintingStrategy(PaintingStrategy.dashes);
     signalxxx.setDefaultColor(Color.cyan);
     signalxxx.SetLineWeight(3);

plot signalxxxx = HighestAll(if display >= 5 and (cond1x) == HighestAll(x1cond) - 4 then price else Double.NaN);
     signalxxxx.setpaintingStrategy(PaintingStrategy.dashes);
     signalxxxx.setDefaultColor(Color.cyan);
     signalxxxx.SetLineWeight(3);

@MerryDay @SleepyZ so in watching this using this code the line shows up after the signal but doesn't stay at the signal, it moves with the highs of following candles instead of just staying put, and I'm not sure why
 
Code:
plot signal = HighestAll(if display >= 1 and (cond1x) == HighestAll(x1cond) - 0 then price else Double.NaN);
     signal.setpaintingStrategy(PaintingStrategy.dashes);
     signal.setDefaultColor(Color.cyan);
     signal.SetLineWeight(3);

plot signalx = HighestAll(if display >= 2 and (cond1x) == HighestAll(x1cond) - 1 then price else Double.NaN);
     signalx.setpaintingStrategy(PaintingStrategy.dashes);
     signalx.setDefaultColor(Color.cyan);
     signalx.SetLineWeight(3);

plot signalxx = HighestAll(if display >= 3 and (cond1x) == HighestAll(x1cond) - 2 then price else Double.NaN);
     signalxx.setpaintingStrategy(PaintingStrategy.dashes);
     signalxx.setDefaultColor(Color.cyan);
     signalxx.SetLineWeight(3);

plot signalxxx = HighestAll(if display >= 4 and (cond1x) == HighestAll(x1cond) - 3 then price else Double.NaN);
     signalxxx.setpaintingStrategy(PaintingStrategy.dashes);
     signalxxx.setDefaultColor(Color.cyan);
     signalxxx.SetLineWeight(3);

plot signalxxxx = HighestAll(if display >= 5 and (cond1x) == HighestAll(x1cond) - 4 then price else Double.NaN);
     signalxxxx.setpaintingStrategy(PaintingStrategy.dashes);
     signalxxxx.setDefaultColor(Color.cyan);
     signalxxxx.SetLineWeight(3);

@MerryDay @SleepyZ so in watching this using this code the line shows up after the signal but doesn't stay at the signal, it moves with the highs of following candles instead of just staying put, and I'm not sure why
edit your post #5 to include all of your code.
 
edit your post #5 to include all of your code.
So I can't post all of the code because it isn't public access the conditions triggering the line, but the above code is the only "plot" code in the study, so nothing else should be causing the plot to change
 
So I can't post all of the code because it isn't public access the conditions triggering the line, but the above code is the only "plot" code in the study, so nothing else should be causing the plot to change
if we can't see what formulas you have for
cond1x and x1cond,
and formulas supplying them,
it will be near impossible to help you.
 
@Bobby Thank you for not posting proprietary content. Questions for commercial indicators need to be directed to the vendor.
 
Hello my fellow code geeks -

I've been a long time admirer of this community and i learnt little coding.
i was looking for SR Lines (Support Resistance lines) that joins two or more candles that has same close price. Something like below snip.
 
Last edited:
Hello my fellow code geeks -

I've been a long time admirer of this community and i learnt little coding.
i was looking for SR Lines (Support Resistance lines) that joins two or more candles that has same close price. Something like below snip.
##Custom_PrevDaysClosePrs_V2
#08/18/2020
##perf issue fix



Input length = 90;
##lenght should be automatic and should take the tottal bars on whatever time frame selected on chart

input BeginTime = 0130; ##default 0930
input EndTime = 1600;
def ORActive = if getday()==getlastday() AND secondsfromtime(EndTime)<=0 then 1 else 0;
def nan = double.nan;

#--------------------------------------------------------------------------------#
#Prev Day Close plot & formatting - plotted for today
def PrevDayClose = if ORActive then close(period = aggregationPeriod.day)[1] else double.nan;
Plot PreviousDayClose = PrevDayClose;

PreviousDayClose.SetStyle(Curve.SHORT_DASH);
PreviousDayClose.SetLineWeight(2);
#PreviousDayClose.SetDefaultColor(Color.Orange);

PreviousDayClose.AssignValueColor(if close > PrevDayClose then color.uptick else if close < PrevDayClose then color.downtick else Color.magenta);
#--------------------------------------------------------------------------------#

def CP2 = fold up2 = 0 to length with p2 do GetValue(if close == close[2] then close else nan, up2);

Plot SR2 = highestall(CP2);
SR2.SetStyle(Curve.SHORT_DASH);
SR2.SetLineWeight(1);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
282 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