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
SentimentZoneOscillator
https://tlc.thinkorswim.com/center/...s/studies-library/R-S/SentimentZoneOscillator
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);
#
SentimentZoneOscillator
https://tlc.thinkorswim.com/center/...s/studies-library/R-S/SentimentZoneOscillator