how to use getSymbol to draw support and resistance in specific symbol?

kaflesu

New member
I have multiple support and resistance for different stocks. How write a script so that the horizontal line is created based on that?

For example:

If I am viewing apple:
I want to draw a horizontal support/resistance line at 150, and 147. 145

If I am viewing IWM:
I want to draw horizontal support/resistance at 188, and 185. 182
 
Solution
I have multiple support and resistance for different stocks. How write a script so that the horizontal line is created based on that?

For example:

If I am viewing apple:
I want to draw a horizontal support/resistance line at 150, and 147. 145

If I am viewing IWM:
I want to draw horizontal support/resistance at 188, and 185. 182

Try

Code:
plot line1;
plot line2;
plot line3;

if GetSymbol() == "AAPL" {

    line1 = 150;
    line2 = 147;
    line3 = 145;
} else if GetSymbol() == "IWM" {
    line1 = 188;
    line2 = 185;
    line3 = 182;
} else {
    line1 = Double.NaN;
    line2 = Double.NaN;
    line3 = Double.NaN;
}
I have multiple support and resistance for different stocks. How write a script so that the horizontal line is created based on that?

For example:

If I am viewing apple:
I want to draw a horizontal support/resistance line at 150, and 147. 145

If I am viewing IWM:
I want to draw horizontal support/resistance at 188, and 185. 182

Try

Code:
plot line1;
plot line2;
plot line3;

if GetSymbol() == "AAPL" {

    line1 = 150;
    line2 = 147;
    line3 = 145;
} else if GetSymbol() == "IWM" {
    line1 = 188;
    line2 = 185;
    line3 = 182;
} else {
    line1 = Double.NaN;
    line2 = Double.NaN;
    line3 = Double.NaN;
}
 
Solution
Try

Code:
plot line1;
plot line2;
plot line3;

if GetSymbol() == "AAPL" {

    line1 = 150;
    line2 = 147;
    line3 = 145;
} else if GetSymbol() == "IWM" {
    line1 = 188;
    line2 = 185;
    line3 = 182;
} else {
    line1 = Double.NaN;
    line2 = Double.NaN;
    line3 = Double.NaN;
}

This will add bubbles that you can move sideways and add text to display in them

Capture.jpg
Code:
plot line1;
plot line2;
plot line3;

if GetSymbol() == "AAPL" {

    line1 = 150;
    line2 = 147;
    line3 = 145;
} else if GetSymbol() == "IWM" {
    line1 = 188;
    line2 = 185;
    line3 = 182;
} else {
    line1 = Double.NaN;
    line2 = Double.NaN;
    line3 = Double.NaN;
}

line1.SetDefaultColor(Color.WHITE);
line2.SetDefaultColor(Color.CYAN);
line3.SetDefaultColor(Color.YELLOW);


input bubbles     = yes;
input bubblemover = 5;
def bm  = bubblemover;
def bm1 = bm + 1;
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]), line1[bm1], " ?????", line1.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]), line2[bm1], " ?????", line2.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]), line3[bm1], " ?????", line3.TakeValueColor());
 
Hi @SleepyZ , Is there a way to draw the support line from a specific time?
For example, if I need to draw a line of spy starting from 10:45 am.

This should work for that

Ruby:
input time1 = 1045;
def   line1 = if secondsfromtime(time1)==0 then high else line1[1];
plot time_line1  = line1;
time_line1.setpaintingStrategy(paintingStrategy.HORIZONTAL);
 
Hi @SleepyZ , with your help I am able to write the desired script. The script is working in the Day timeframe but not in the lower time frame.

Can you suggest what I need to change? This is for TSLA.


CODE:

def dat = GetYYYYMMDD();
plot Data100027 = if secondsfromtime(1511)==0 and dat >= 20220609 and dat <= 20220610 then 729.56 else double.nan;; Data100027.AssignValueColor(Color.LIGHT_RED); Data100027.SetLineWeight (1);

plot Data100026 = if secondsfromtime(1509)==0 and dat >= 20220609 and dat <= 20220610 then 731.0 else double.nan;; Data100026.AssignValueColor(Color.LIGHT_RED); Data100026.SetLineWeight (1);

plot Data100024 = if secondsfromtime(1508)==0 and dat >= 20220609 and dat <= 20220610 then 731.21 else double.nan;; Data100024.AssignValueColor(Color.LIGHT_RED); Data100024.SetLineWeight (1);

plot Data100025 = if secondsfromtime(1508)==0 and dat >= 20220609 and dat <= 20220610 then 730.54 else double.nan;; Data100025.AssignValueColor(Color.LIGHT_RED); Data100025.SetLineWeight (1);
 
Hi @SleepyZ , with your help I am able to write the desired script. The script is working in the Day timeframe but not in the lower time frame.

Can you suggest what I need to change? This is for TSLA.


CODE:

def dat = GetYYYYMMDD();
plot Data100027 = if secondsfromtime(1511)==0 and dat >= 20220609 and dat <= 20220610 then 729.56 else double.nan;; Data100027.AssignValueColor(Color.LIGHT_RED); Data100027.SetLineWeight (1);

plot Data100026 = if secondsfromtime(1509)==0 and dat >= 20220609 and dat <= 20220610 then 731.0 else double.nan;; Data100026.AssignValueColor(Color.LIGHT_RED); Data100026.SetLineWeight (1);

plot Data100024 = if secondsfromtime(1508)==0 and dat >= 20220609 and dat <= 20220610 then 731.21 else double.nan;; Data100024.AssignValueColor(Color.LIGHT_RED); Data100024.SetLineWeight (1);

plot Data100025 = if secondsfromtime(1508)==0 and dat >= 20220609 and dat <= 20220610 then 730.54 else double.nan;; Data100025.AssignValueColor(Color.LIGHT_RED); Data100025.SetLineWeight (1);
Example:
Let's say when the stock is at 3:11 pm, I want to draw a line @ 729.56 but the bar high or low may not be 729.56.
 

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