Indicator Visualizer V1.0
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Exmodaus

//@version=5
indicator("Indicator Visualizer", shorttitle="IVZ", overlay=true)

//__________________
//Inputs
deRsi = input.bool(true, "Default RSI On/Off", group="Indicator Source", tooltip="Turn this off if you want to use Close as your input source, Otherwise this option will default to visualize RSI(14) crossing over/under the levels. This will not affect the Source if you change it from Close.")
i_src = input.source(close, "Indicator", group="Indicator Source", tooltip="Select the Indicator you want to visualize on the chart. If this value is Close and the Default RSI is checked, then the indicator will use RSI(length 14) as the default.")
lines = input.bool(false, "Plot Lines", group="Plots On / Off", inline="Plots", tooltip="Do you want lines or boxes plotted?")
boxes = input.bool(true, "Plot Boxes", group="Plots On / Off", inline="Plots", tooltip="Do you want lines or boxes plotted?")

lvl1 = input.float(70, "level 1", group="Levels", inline="level1", tooltip="When the Indicator selected(Indicator source) crosses over this level it will begin plotting. When it crosses back under this level it will stop plotting")
lvl2 = input.float(30, "level 2", group="Levels", inline="level2", tooltip="When the Indicator selected(Indicator source) crosses under this level it will begin plotting. When it crosses back over this level it will stop plotting")


ext1 = input.int(1, "Line 1", group="Line Settings", inline="Line", tooltip="How many bars should the line extend after it stops plotting?")
ext2 = input.int(1, "Line 2", group="Line Settings", inline="Line", tooltip="How many bars should the line extend after it stops plotting?")


color co2color = input.color(color.rgb(14, 232, 72, 0), title="Cross Over Line", group="Line Settings", inline="COLORS")
color cu2color = input.color(color.rgb(255, 0, 0, 0), title="Cross Under Line", group="Line Settings", inline="COLORS")

color cocolor = input.color(color.rgb(14, 232, 72, 50), title="Cross Over Box", group="Box Colors", inline="Over COLORS")
color cucolor = input.color(color.rgb(255, 0, 0, 50), title="Cross Under Box", group="Box Colors", inline="Under COLORS")
color co1color = input.color(color.rgb(14, 232, 72, 50), title="Cross Over Border", group="Box Colors", inline="Over COLORS")
color cu1color = input.color(color.rgb(255, 0, 0, 50), title="Cross Under Border", group="Box Colors", inline="Under COLORS")

//________________________
//Variables


//Default RSI length of 14 if Source is close
i_src1= deRsi == true and i_src==close ? ta.rsi(close, 14) : i_src
//Lines
var line line1 = na
var line line2 = na
//Boxes
var box box1 = na
var box box2 = na


//Crossover
ob1 = (i_src1[0] > lvl1)? true : false
ob2 = (i_src1[1] > lvl1 and i_src1[0] < lvl1)? true : false
os1 = (i_src1[0] < lvl2)? true : false
os2 = (i_src1[0] > lvl2 and i_src1[1] < lvl2)? true : false





//______________________
//Conditions


//Lines

//Crossover Line
if ob1 and lines == true and ob1[1] == false
    line1 := line.new(bar_index,close,bar_index, close, extend=extend.right, color=co2color, width=3)
else if ob1[1] == true and ob1[0] == true
    line.set_x2(line1, bar_index)
    line.set_y2(line1, close)
else if ob2 and lines == true
    line.set_x2(line1, bar_index+ext1)
    line.set_extend(line1, extend.none)
    line.set_y2(line1, close)
    
    
//Crossunder Line
if os1 and lines == true and os1[1] == false
    line2 := line.new(bar_index,close,bar_index, close, extend=extend.right, color=cu2color, width=3)
else if os1[1] == true and os1[0] == true
    line.set_x2(line2, bar_index)
    line.set_y2(line2, close)
else if os2 and lines == true
    line.set_x2(line2, bar_index+ext2)
    line.set_extend(line2, extend.none)
    line.set_y2(line2, close)
    
//BOXES

//Crossover Box
if ob1 and boxes == true and ob1[1] == false
    box1 := box.new(bar_index,high,bar_index+(ta.barssince(os1)), low, extend=extend.right, bgcolor=cocolor, border_width=1, border_color= co1color)
else if ob1[1] == true and ob1[0] == true
    box.set_top(box1, ta.highest(high,(ta.barssince(ob1)>1?ta.barssince(ob1):1)))
else if ob2 and boxes == true
    box.set_right(box1, bar_index)
    box.set_extend(box1, extend.none)
    box.set_top(box1, ta.highest(high,(ta.barssince(ob1)>1?ta.barssince(ob1):1)))

    
//Crossunder Box
if os1 and boxes == true and os1[1] == false
    box2 := box.new(bar_index,high,bar_index, low, extend=extend.right, bgcolor=cucolor, border_width=1, border_color= cu1color)
else if os1[1] == true and os1[0] == true
    box.set_bottom(box2, ta.lowest(low,(ta.barssince(os1)>1?ta.barssince(os1):1)))
else if os2 and boxes == true
    box.set_right(box2, bar_index)
    box.set_extend(box2, extend.none)
    box.set_bottom(box2, ta.lowest(low,(ta.barssince(os1)>1?ta.barssince(os1):1)))
    
    
