Plot Specific Lines on Lower Study Depending on Input or Stock Symbol?

tradegeek

Active member
2019 Donor
I'm not a programmer and tried to find this by searching but I'm not getting much results so I figured I'll just ask here since some of you seem to be so knowledgeable.

I want to plot certain items depending on the input settings or the underlying symbol. For example, I want to plot the zero line plus lines at -10, -5, -1, 1, 5, 10 as default or when I'm charting ES but when I'm charting CL, I want lines plotted for -1.5, -1, -0.5, 0.5, 1, 1.5 instead. So instead of creating a different study for each asset, I was hoping to have it in the same study but have it dynamically set depending on the symbol selected.

My search points me to the switch and case functions but I'm not sure how to proceed. This would save some time if it can be done because there are studies where the settings are specific to certain symbol or even time-frame. Can it also be set according to time-frame/tick/ATR?
 
Quite straightforward, here's a study I crafted for you. I have added hooks for any different levels you might like for different symbols like /ZB, AAPL, etc, etc

Code:
declare lower;

def posL3;
def posL2;
def posL1;
def negL1;
def negL2;
def negL3;

if GetSymbol() == "/ES:XCME" {
    posL3 = 10;
        posL2 = 5;
        posL1 = 1;
        negL1 = -1;
        negL2 = -5;
        negL3 = -10;
}
else if GetSymbol() == "/CL:XNYM" {
        posL3 = 1.5;
        posL2 = 1;
        posL1 = 0.5;
        negL1 = -0.5;
        negL2 = -1;
        negL3 = -1.5;
}
else {
        posL3 = 15;
        posL2 = 10;
        posL1 = 5;
        negL1 = -5;
        negL2 = -10;
        negL3 = -15;
}

AddLabel(1, "Symbol = " + GetSymbol(), Color.Yellow);

plot posL3_ = posL3;
plot posL2_ = posL2;
plot posL1_ = posL1;
plot zero = 0;
plot negL1_ = negL1;
plot negL2_ = negL2;
plot negL3_ = negL3;
# END CODE
 
Since there is symmetry between the positive and negative values, here's another version that reduces the number of levels you need to define. Either way this should get you started to what you seek to achieve

Code:
declare lower;

def posL3;
def posL2;
def posL1;
def negL1;
def negL2;
def negL3;

if GetSymbol() == "/ES:XCME" {
    posL3 = 10;
        posL2 = 5;
        posL1 = 1;
        negL1 = -(posL1);
        negL2 = -(posL2);
        negL3 = -(posL3);
}
else if GetSymbol() == "/CL:XNYM" {
        posL3 = 1.5;
        posL2 = 1;
        posL1 = 0.5;
        negL1 = -(posL1);
        negL2 = -(posL2);
        negL3 = -(posL3);
}
else {
        posL3 = 15;
        posL2 = 10;
        posL1 = 5;
        negL1 = -(posL1);
        negL2 = -(posL2);
        negL3 = -(posL3);
}

AddLabel(1, "Symbol = " + GetSymbol(), Color.Yellow);

plot posL3_ = posL3;
plot posL2_ = posL2;
plot posL1_ = posL1;
plot zero = 0;
plot negL1_ = negL1;
plot negL2_ = negL2;
plot negL3_ = negL3;
 

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