OS/OB Oscillator Boxes on Upper Chart For ThinkOrSwim

halcyonguy

Moderator - Expert
VIP
Lifetime
draw rectangles on the upper chart, when the SentiMent Zone Oscillator moves beyond overbought or oversold.

when the lower signal is above the overbought level, draw a shaded red rectangle above the price candles.
if it is above for only 1 bar, then draw a red vertical line. can be turned on/off.

when the signal is below the oversold level, draw a shaded green rectangle below the price candles.
if it is below for only 1 bar, then draw a green vertical line. can be turned on/off.

can adjust the vertical location of rectangle, with 2 variables.
. this controls how far away from the candles the rectangle is.
. box_vertical_offset_per = 0.6
. this controls the rectangle height
. box_vertical_height_per = 0.8
they are percentages, that are multiplied by highest or lowest prices. (ex. 0.6/100 * highest)

this could be modified to read data from other studies

Ruby:
# ob_os_box_00c
#  halcyonguy
# 22-03-05

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

input box_vertical_offset_per = 0.6;
input box_vertical_height_per = 0.8;
input draw_vertical_line_for_single_bar_triggers = yes;

# -----------------------------------
# read data from other study

def szosc = SentimentZoneOscillator().szo;
def szo_ob = SentimentZoneOscillator().OverBought;
def szo_os = SentimentZoneOscillator().oversold;

def ob = if szosc >= szo_ob then 1 else 0;
def os = if szosc <= szo_os then 1 else 0;

# -----------------------------------

# OB - overbought

def big = 999999;
def obfirst = if (ob[1] == 0 and ob[0] == 1) then 1 else 0;
def obstartbn = if bn == 1 then big else if obfirst then bn else obstartbn[1];

#  find highest high of OB range
# run loop on 1st bar of OB range
def obstopbn;
def obhi;
if obfirst then {
  obstopbn = fold i = 0 to 100
  with p
  while getvalue(ob, -i) == 1
  do bn + i;

  obhi = fold j = 0 to 100
  with q
  while getvalue(ob, -j) == 1
  do max(q, getvalue(high, -j));

} else {
  obstopbn = obstopbn[1];
  obhi = obhi[1];
}

def ob_x1 = ( bn >= obstartbn and bn <= obstopbn);
input test_ob_vert = no;
addverticalline(test_ob_vert and ob_x1,"ob", color.gray);

# if just 1 bar, then draw a vertical line , can't draw a cloud
def ob1bar = if (draw_vertical_line_for_single_bar_triggers and obfirst and ob[-1] == 0) then 1 else 0;
addverticalline(ob1bar and ob_x1,"OB  1  BAR", color.red);

# highest high of ob range
# plot obhiline = if ob_x1 then obhi else na;

# box bottom
plot ob_box_bot = if ob_x1 then (obhi * (1 + (box_vertical_offset_per/100))) else na;
ob_box_bot.setdefaultcolor(color.red);

# box top
plot ob_box_top = if ob_x1 then (ob_box_bot * (1 + (box_vertical_height_per/100))) else na;
ob_box_top.setdefaultcolor(color.red);

#   cloud( big, small, color, color)
addcloud( ob_box_top, ob_box_bot, color.red, color.red);

# ------------------------------------------------------------------------

# OS - oversold

def osfirst = if (os[1] == 0 and os[0] == 1) then 1 else 0;
def osstartbn = if bn == 1 then big else if osfirst then bn else osstartbn[1];

# find lowest low of OS range
# run loop on 1st bar of OS range
def osstopbn;
def oslo;
if osfirst then {
  osstopbn = fold k = 0 to 100
  with r
  while getvalue(os, -k) == 1
  do bn + k;

  oslo = fold l = 0 to 100
  with s = big
  while getvalue(os, -l) == 1
  do min(s, getvalue(low, -l));

} else {
  osstopbn = osstopbn[1];
  oslo = oslo[1];
}

def os_x1 = ( bn >= osstartbn and bn <= osstopbn);
input test_os_vert = no;
addverticalline(test_os_vert and os_x1,"ob", color.gray);

# if just 1 bar, then draw a vertical line , can't draw a cloud
def os1bar = if (draw_vertical_line_for_single_bar_triggers and osfirst and os[-1] == 0) then 1 else 0;
addverticalline(os1bar and os_x1,"OS  1  BAR", color.green);

# lowest low  of os range
# plot osloline = if os_x1 then oslo else na;

# OS box top , under bars
plot os_box_top = if os_x1 then (oslo * (1 - (box_vertical_offset_per/100))) else na;
os_box_top.setdefaultcolor(color.green);

# OS box bottom
plot os_box_bot = if os_x1 then (os_box_top * (1 - (box_vertical_height_per/100))) else na;
os_box_bot.setdefaultcolor(color.green);

#   cloud( big, small, color, color)
addcloud( os_box_top, os_box_bot, color.green, color.green);
#


hnVS2bO.jpg



SentimentZoneOscillator
https://tlc.thinkorswim.com/center/...s/studies-library/R-S/SentimentZoneOscillator
 
draw rectangles on the upper chart, when the SentiMent Zone Oscillator moves beyond overbought or oversold.

when the lower signal is above the overbought level, draw a shaded red rectangle above the price candles.
if it is above for only 1 bar, then draw a red vertical line. can be turned on/off.

when the signal is below the oversold level, draw a shaded green rectangle below the price candles.
if it is below for only 1 bar, then draw a green vertical line. can be turned on/off.

can adjust the vertical location of rectangle, with 2 variables.
. this controls how far away from the candles the rectangle is.
. box_vertical_offset_per = 0.6
. this controls the rectangle height
. box_vertical_height_per = 0.8
they are percentages, that are multiplied by highest or lowest prices. (ex. 0.6/100 * highest)

this could be modified to read data from other studies

Ruby:
# ob_os_box_00c
#  halcyonguy
# 22-03-05

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

input box_vertical_offset_per = 0.6;
input box_vertical_height_per = 0.8;
input draw_vertical_line_for_single_bar_triggers = yes;

# -----------------------------------
# read data from other study

def szosc = SentimentZoneOscillator().szo;
def szo_ob = SentimentZoneOscillator().OverBought;
def szo_os = SentimentZoneOscillator().oversold;

def ob = if szosc >= szo_ob then 1 else 0;
def os = if szosc <= szo_os then 1 else 0;

# -----------------------------------

# OB - overbought

def big = 999999;
def obfirst = if (ob[1] == 0 and ob[0] == 1) then 1 else 0;
def obstartbn = if bn == 1 then big else if obfirst then bn else obstartbn[1];

#  find highest high of OB range
# run loop on 1st bar of OB range
def obstopbn;
def obhi;
if obfirst then {
  obstopbn = fold i = 0 to 100
  with p
  while getvalue(ob, -i) == 1
  do bn + i;

  obhi = fold j = 0 to 100
  with q
  while getvalue(ob, -j) == 1
  do max(q, getvalue(high, -j));

} else {
  obstopbn = obstopbn[1];
  obhi = obhi[1];
}

def ob_x1 = ( bn >= obstartbn and bn <= obstopbn);
input test_ob_vert = no;
addverticalline(test_ob_vert and ob_x1,"ob", color.gray);

# if just 1 bar, then draw a vertical line , can't draw a cloud
def ob1bar = if (draw_vertical_line_for_single_bar_triggers and obfirst and ob[-1] == 0) then 1 else 0;
addverticalline(ob1bar and ob_x1,"OB  1  BAR", color.red);

# highest high of ob range
# plot obhiline = if ob_x1 then obhi else na;

# box bottom
plot ob_box_bot = if ob_x1 then (obhi * (1 + (box_vertical_offset_per/100))) else na;
ob_box_bot.setdefaultcolor(color.red);

# box top
plot ob_box_top = if ob_x1 then (ob_box_bot * (1 + (box_vertical_height_per/100))) else na;
ob_box_top.setdefaultcolor(color.red);

#   cloud( big, small, color, color)
addcloud( ob_box_top, ob_box_bot, color.red, color.red);

# ------------------------------------------------------------------------

# OS - oversold

def osfirst = if (os[1] == 0 and os[0] == 1) then 1 else 0;
def osstartbn = if bn == 1 then big else if osfirst then bn else osstartbn[1];

# find lowest low of OS range
# run loop on 1st bar of OS range
def osstopbn;
def oslo;
if osfirst then {
  osstopbn = fold k = 0 to 100
  with r
  while getvalue(os, -k) == 1
  do bn + k;

  oslo = fold l = 0 to 100
  with s = big
  while getvalue(os, -l) == 1
  do min(s, getvalue(low, -l));

} else {
  osstopbn = osstopbn[1];
  oslo = oslo[1];
}

def os_x1 = ( bn >= osstartbn and bn <= osstopbn);
input test_os_vert = no;
addverticalline(test_os_vert and os_x1,"ob", color.gray);

# if just 1 bar, then draw a vertical line , can't draw a cloud
def os1bar = if (draw_vertical_line_for_single_bar_triggers and osfirst and os[-1] == 0) then 1 else 0;
addverticalline(os1bar and os_x1,"OS  1  BAR", color.green);

# lowest low  of os range
# plot osloline = if os_x1 then oslo else na;

# OS box top , under bars
plot os_box_top = if os_x1 then (oslo * (1 - (box_vertical_offset_per/100))) else na;
os_box_top.setdefaultcolor(color.green);

# OS box bottom
plot os_box_bot = if os_x1 then (os_box_top * (1 - (box_vertical_height_per/100))) else na;
os_box_bot.setdefaultcolor(color.green);

#   cloud( big, small, color, color)
addcloud( os_box_top, os_box_bot, color.green, color.green);
#


hnVS2bO.jpg



SentimentZoneOscillator
https://tlc.thinkorswim.com/center/...s/studies-library/R-S/SentimentZoneOscillator
can code something like this for macd? when both histogram and lines are above zero show bullish, when both lines and histogram are below zero line show bearish
 

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