multiple Horizontal Lines with Names

ronviv1

New member
Please help me with plotting multiple horizontal lines at various price levels with names for a specific symbols showing on that specific chart (e.g. SPX, SPY, /ES) using TOS script. Thank you.

Example:
I want to plot a "dotted" horizontal line of "Yellow" color on SPX chart at the price level "5050.28" and Name it "0 Gamma" displayed on the left side of the line.
And a second "Solid" horizontal line of "Green" color at the price level :5025.25" and name it "Support" displayed on the left side of the line.
And a third "Solid" horizontal line of "Red" color at the price level :5100.50" and name it "Resistance" displayed on the left side of the line.

Similar plots for /ES at different price levels.
 
Last edited:
Please help me with plotting multiple horizontal lines at various price levels with names for a specific symbols showing on that specific chart (e.g. SPX, SPY, /ES) using TOS script. Thank you.

Example:
I want to plot a "dotted" horizontal line of "Yellow" color on SPX chart at the price level "5050.28" and Name it "0 Gamma" displayed on the left side of the line.
And a second "Solid" horizontal line of "Green" color at the price level :5025.25" and name it "Support" displayed on the left side of the line.
And a third "Solid" horizontal line of "Red" color at the price level :5100.50" and name it "Resistance" displayed on the left side of the line.

Similar plots for /ES at different price levels.

set up 3 symbols and 3 prices for each symbol.
if the chart symbol matches one of the symbols, 3 lines will be drawn.

i'm drawing a blank for the real symbol for /ES, so i left it out


Code:
# symbol_lines

#https://usethinkscript.com/threads/plotting-multiple-horizontal-lines-with-names.18496/
#Plotting multiple Horizontal Lines with Names
at the price level :5100.50" and name it "Resistance" displayed on the left side of the line.

def na = double.nan;
def bn = barnumber();

#def lastbarbn = HighestAll(If(IsNaN(close), 0, bn));
#def lastbar = if (bn == lastbarbn) then 1 else 0;
#def lastbar = !isnan(close[0]) and isnan(close[-1]);


input sym1 = "SPY";
input s1_resistance = 522.0;
input s1_0_gamma = 520.0;
input s1_Support = 518.0;

input sym2 = "SPX";
input s2_resistance = 5100.50;
input s2_0_gamma = 5050.28;
input s2_Support = 5025.25;

input sym3 = "C";
input s3_resistance = 60.0;
input s3_0_gamma = 59.5;
input s3_Support = 59.0;

def s1 = (GetSymbol() == sym1);
def s2 = (GetSymbol() == sym2);
def s3 = (GetSymbol() == sym3);

addlabel(1, " ", color.black);
addlabel(1, sym1, (if s1 then color.yellow else color.gray));
addlabel(1, sym2, (if s2 then color.yellow else color.gray));
addlabel(1, sym3, (if s3 then color.yellow else color.gray));
addlabel(1, " ", color.black);

def line1;
def line2;
def line3;
if GetSymbol() == sym1 then {
  line1 = s1_resistance;
  line2 = s1_0_gamma;
  line3 = s1_Support;
} else if GetSymbol() == sym2 then {
  line1 = s2_resistance;
  line2 = s2_0_gamma;
  line3 = s2_Support;
} else if GetSymbol() == sym3 then {
  line1 = s3_resistance;
  line2 = s3_0_gamma;
  line3 = s3_Support;
} else {
  line1 = 0;
  line2 = 0;
  line3 = 0;
}

plot l1 = if line1 > 0 and !isnan(close) then line1 else na;
plot l2 = if line2 > 0 and !isnan(close) then line2 else na;
plot l3 = if line3 > 0 and !isnan(close) then line3 else na;

l1.SetDefaultColor(Color.red);
#l1.setlineweight(1);
#l1.hidebubble();
l2.SetDefaultColor(Color.yellow);
l2.SetStyle(Curve.MEDIUM_DASH);
#l2.setlineweight(1);
#l2.hidebubble();
l3.SetDefaultColor(Color.green);
#l3.setlineweight(1);
#l3.hidebubble();
#
 
Last edited:

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