Add overbought and oversold levels to MarkerIndicator

lmk99

Active member
VIP
Hi all,

This should be very simple but I haven't figured it out yet. MarkerIndicator doesn't have horizontal lines for overbought and oversold by default. The study displays the indicator in a lower chart that has a y-axis of 0 to 100%. I want to have lines appear at 30% and 70% so I wrote this and merged it into the same section:
Code:
input oversoldMI = 30;
input overboughtMI = 70;
plot line1 = oversoldMI;
plot line2 = overboughtMI;
line1.SetDefaultColor(GetColor(339700));
line2.SetDefaultColor(GetColor(339700));

What happens is the lines appear at the very top and bottom of the section instead of at 30% and 70%. If I try to change "input oversoldMI =" to "30%" instead of "30" then of course that doesn't work. How can I make the lines appear at 30% and 70%?
 

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
Here you go:

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2020
#

declare lower;

input overbought = 70;
input oversold = 30;

def high_diff = Max(0, high - high[1]);
def low_diff = Max(0, low[1] - low);

def high_avg = Average(high_diff, 8);
def low_avg = Average(low_diff, 8);
plot TD_I = if high_avg == 0 && low_avg == 0 then 0 else high_avg / (high_avg + low_avg) * 100;
TD_I.SetDefaultColor(GetColor(1));

plot ob = overbought;
plot os = oversold;
 

petergluis

Active member
I add colors to the indicator in order to show uptrends and downtrends.
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2020
#

declare lower;

input overbought = 70;
input oversold = 30;

def high_diff = Max(0, high - high[1]);
def low_diff = Max(0, low[1] - low);

def high_avg = Average(high_diff, 8);
def low_avg = Average(low_diff, 8);
plot TD_I = if high_avg == 0 && low_avg == 0 then 0 else high_avg / (high_avg + low_avg) * 100;
TD_I.SetDefaultColor(GetColor(1));

plot ob = overbought;
plot os = oversold;

TD_I.SetLineWeight(2);
TD_I.DefineColor("UP", Color.GREEN);
TD_I.DefineColor("DOWN", Color.RED);

TD_I.AssignValueColor(if TD_I > TD_I[1] then TD_I.Color("Up") else TD_I.Color("Down"));
 

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.
Top