Opens, Closes, Highs and Lows.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Lenny_Kiruthu

//@version=5
indicator(title="Opens, Closes, High and Lows.", shorttitle="Top Down OCHL", overlay=true)

// USER INPUTS
// Today's Inputs
THigh = input.bool(defval=true, title="Today's High", inline="1", group="Today's Settings")
TLow = input.bool(defval=true, title="Today's Low", inline="2", group="Today's Settings")
TOpen = input.bool(defval=true, title="Today's Open", inline="3", group="Today's Settings")
TClose = input.bool(defval=true, title="Today's Close", inline="4", group="Today's Settings")

// Input criteria for Today's line type and width
LineType1 = input.string(defval="line.style_solid", title="Line Type", options=["line.style_solid","line.style_dotted","line.style_dashed"], group="Today's Settings")
Linewidth1 = input.int(defval=1, title="Line Width", minval=1, maxval=6, group="Today's Settings")

// Input criteria for Today's line colors
THighColor = input.color(defval=color.green, title="| Today's High color", group="Today's Settings", inline="1")
TLowColor = input.color(defval=color.red, title="| Today's Low color", group="Today's Settings", inline="2")
TOpenColor = input.color(defval=color.orange, title="| Today's Open color", group="Today's Settings", inline="3")
TCloseColor = input.color(defval=color.blue, title="| Today's Close Color", group="Today's Settings", inline="4")

// Yesterday's Inputs
YHigh = input.bool(defval=false, title="Yesterday's High", inline="5", group="Yesterday's Settings")
YLow = input.bool(defval=false, title="Yesterday's Low", inline="6", group="Yesterday's Settings")
YOpen = input.bool(defval=false, title="Yesterday's Open", inline="7", group="Yesterday's Settings")
YClose = input.bool(defval=false, title="Yesterday's Close", inline="8", group="Yesterday's Settings")

// Input criteria for Yesterday's line type and width
LineType2 = input.string(defval="line.style_solid", title="Line Type", options=["line.style_solid","line.style_dotted","line.style_dashed"], group="Yesterday's Settings")
Linewidth2 = input.int(defval=2, title="Line Width", minval=1, maxval=6, group="Yesterday's Settings")

// Input criteria for Yesterday's line colors
YHighColor = input.color(defval=color.green, title="| Yesterday's High color", group="Yesterday's Settings", inline="5")
YLowColor = input.color(defval=color.red, title="| Yesterday's Low color", group="Yesterday's Settings", inline="6")
YOpenColor = input.color(defval=color.orange, title="| Yesterday's Open color", group="Yesterday's Settings", inline="7")
YCloseColor = input.color(defval=color.blue, title="| Yesterday's Close color", group="Yesterday's Settings", inline="8")

// Weekly inputs
WHigh = input.bool(defval=true, title="Week's High", inline="9", group="Weekly Settings")
WLow = input.bool(defval=true, title="Week's Low", inline="10", group="Weekly Settings")
WOpen = input.bool(defval=true, title="Week's Open", inline="11", group="Weekly Settings")
WClose = input.bool(defval=true, title="Week's Close", inline="12", group="Weekly Settings")

// Input criteria for Weekly line type and width
LineType3 = input.string(defval="line.style_solid", title="Line Type", options=["line.style_solid","line.style_dotted","line.style_dashed"], group="Weekly Settings")
Linewidth3 = input.int(defval=3, title="Line Width", minval=1, maxval=6, group="Weekly Settings")

// Input criteria for Weekly line colors
WHighColor = input.color(defval=color.green, title="| Week's High color", group="Weekly Settings", inline="9")
WLowColor = input.color(defval=color.red, title="| Week's Low color", group="Weekly Settings", inline="10")
WOpenColor = input.color(defval=color.orange, title="| Week's Open color", group="Weekly Settings", inline="11")
WCloseColor = input.color(defval=color.blue, title="| Week's Close color", group="Weekly Settings", inline="12")

// Month's Inputs
MHigh = input.bool(defval=false, title="Month's High", inline="13", group="Monthly Settings")
MLow = input.bool(defval=false, title="Month's Low", inline="14", group="Monthly Settings")
MOpen = input.bool(defval=false, title="Month's Open", inline="15", group="Monthly Settings")
MClose = input.bool(defval=false, title="Month's Close", inline="16", group="Monthly Settings")

// Input criteria for Monthly line type and width
LineType4 = input.string(defval="line.style_solid", title="Line Type", options=["line.style_solid","line.style_dotted","line.style_dashed"], group="Monthly Settings")
Linewidth4 = input.int(defval=4, title="Line Width", minval=1, maxval=6, group="Monthly Settings")

// Input criteria for Monthly line colors
MHighColor = input.color(defval=color.green, title="| Month's High color", group="Monthly Settings", inline="13")
MLowColor = input.color(defval=color.red, title="| Month's Low color", group="Monthly Settings", inline="14")
MOpenColor = input.color(defval=color.orange, title="| Month's Open color", group="Monthly Settings", inline="15")
MCloseColor = input.color(defval=color.blue, title="| Month's Close color", group="Monthly Settings", inline="16")

// Changing line styles
L1 = switch LineType1
    "line.style_solid" => style=line.style_solid
    "line.style_dotted" => style=line.style_dotted
    "line.style_dashed" => style=line.style_dashed
    
L2 = switch LineType2
    "line.style_solid" => style=line.style_solid
    "line.style_dotted" => style=line.style_dotted
    "line.style_dashed" => style=line.style_dashed

L3 = switch LineType3
    "line.style_solid" => style=line.style_solid
    "line.style_dotted" => style=line.style_dotted
    "line.style_dashed" => style=line.style_dashed

L4 = switch LineType4
    "line.style_solid" => style=line.style_solid
    "line.style_dotted" => style=line.style_dotted
    "line.style_dashed" => style=line.style_dashed

// Requesting data from the higher timeframes.
[Todays_High, Todays_Low, Todays_Open, Todays_Close] = request.security(syminfo.ticker, "D", [high[0], low[0], open[0],close[0]], lookahead=barmerge.lookahead_on)
[Yesterdays_High, Yesterdays_Low, Yesterdays_Open, Yesterdays_Close] = request.security(syminfo.ticker, "D", [high[1], low[1], open[1],close[1]], lookahead=barmerge.lookahead_on)
[Weekly_High, Weekly_Low, Weekly_Open, Weekly_Close] = request.security(syminfo.ticker,"W", [high[0], low[0], open[0],close[0]], lookahead=barmerge.lookahead_on)
[Monthly_High, Monthly_Low, Monthly_Open, Monthly_Close] = request.security(syminfo.ticker,"M", [high[0], low[0], open[0],close[0]], lookahead=barmerge.lookahead_on)

// Actual plotting of the high, low, open & close lines.
if THigh
    THLine = line.new(x1=bar_index -1, y1=Todays_High, x2=bar_index, y2=Todays_High, color=THighColor, style=L1, width=Linewidth1, extend=extend.both)
    line.delete(THLine[1])

if  TLow
    TLLine = line.new(x1=bar_index -1, y1=Todays_Low, x2=bar_index, y2=Todays_Low, color=TLowColor, style=L1, width=Linewidth1, extend=extend.both)
    line.delete(TLLine[1])

if TOpen
    TOLine = line.new(x1=bar_index -1, y1=Todays_Open, x2=bar_index, y2=Todays_Open, color=TOpenColor, style=L1, width=Linewidth1, extend=extend.both)
    line.delete(TOLine[1])

if TClose
    TCLine = line.new(x1=bar_index -1, y1=Todays_Close, x2=bar_index, y2=Todays_Close, color=TCloseColor , style=L1, width=Linewidth1, extend=extend.both)
    line.delete(TCLine[1])

if YHigh
    YHLine = line.new(x1=bar_index -1, y1=Yesterdays_High, x2=bar_index, y2=Yesterdays_High, color=YHighColor, style=L2, width=Linewidth2, extend=extend.both)
    line.delete(YHLine[1])
 
if YLow
    YLLine = line.new(x1=bar_index -1, y1=Yesterdays_Low, x2=bar_index, y2=Yesterdays_Low, color=YLowColor, style=L2, width=Linewidth2, extend=extend.both)
    line.delete(YLLine[1]) 
    
if YOpen
    YOLine = line.new(x1=bar_index -1, y1=Yesterdays_Open, x2=bar_index, y2=Yesterdays_Open, color=YOpenColor, style=L2, width=Linewidth2, extend=extend.both)
    line.delete(YOLine[1])

if YClose
    YCLine = line.new(x1=bar_index -1, y1=Yesterdays_Close, x2=bar_index, y2=Yesterdays_Close, color=YCloseColor, style=L2, width=Linewidth2, extend=extend.both)
    line.delete(YCLine[1]) 

if WHigh
    WHLine = line.new(x1=bar_index -1, y1=Weekly_High, x2=bar_index, y2=Weekly_High, color=WHighColor, style=L3, width=Linewidth3, extend=extend.both)
    line.delete(WHLine[1])
    
if WLow
    WLLine = line.new(x1=bar_index -1, y1=Weekly_Low, x2=bar_index, y2=Weekly_Low, color=WLowColor, style=L3, width=Linewidth3, extend=extend.both)
    line.delete(WLLine[1])    
    
if WOpen
    WOLine = line.new(x1=bar_index -1, y1=Weekly_Open, x2=bar_index, y2=Weekly_Open, color=WOpenColor, style=L3, width=Linewidth3, extend=extend.both)
    line.delete(WOLine[1])  

if WClose
    WCLine = line.new(x1=bar_index -1, y1=Weekly_Close, x2=bar_index, y2=Weekly_Close, color=WCloseColor, style=L3, width=Linewidth3, extend=extend.both)
    line.delete(WCLine[1])

if MHigh
    MHLine = line.new(x1=bar_index -1, y1=Monthly_High, x2=bar_index, y2=Monthly_High, color=MHighColor, style=L4, width=Linewidth4, extend=extend.both)
    line.delete(MHLine[1])
    
if MLow
    MLLine = line.new(x1=bar_index -1, y1=Monthly_Low, x2=bar_index, y2=Monthly_Low, color=MLowColor, style=L4, width=Linewidth4, extend=extend.both)
    line.delete(MLLine[1])
    
if MOpen
    MOLine = line.new(x1=bar_index -1, y1=Monthly_Open, x2=bar_index, y2=Monthly_Open, color=MOpenColor, style=L4, width=Linewidth4, extend=extend.both)
    line.delete(MOLine[1]) 
    
if MClose
    MCLine = line.new(x1=bar_index -1, y1=Monthly_Close, x2=bar_index, y2=Monthly_Close, color=MCloseColor, style=L4, width=Linewidth4, extend=extend.both)
    line.delete(MCLine[1])
    
// Plotting the labels that appear at respective opens, closes, highs and lows 
// Today's plotshapes
plotshape(Todays_High and THigh ? Todays_High : na, title="Today's High", style=shape.labelup, location=location.absolute, color=THighColor, text="Today's High", textcolor=color.white, size=size.small, show_last=1)    
plotshape(Todays_Low and TLow ? Todays_Low : na, title="Today's Low", style=shape.labelup, location=location.absolute, color=TLowColor, text="Today's Low", textcolor=color.white, size=size.small, show_last=1)    
plotshape(Todays_Open and TOpen ? Todays_Open : na, title="Today's Open", style=shape.labelup, location=location.absolute, color=TOpenColor, text="Today's Open", textcolor=color.white, size=size.small, show_last=1)    
plotshape(Todays_Close and TClose ? Todays_Close : na, title="Today's Close", style=shape.labelup, location=location.absolute, color=TCloseColor, text="Today's Close", textcolor=color.white, size=size.small, show_last=1)      
    
// Yesterday's plotshapes    
plotshape(Yesterdays_High and YHigh ? Yesterdays_High : na, title="Yesterday's High", style=shape.labelup, location=location.absolute, color=YHighColor, text="Yesterday's High", textcolor=color.white, size=size.small, show_last=1)     
plotshape(Yesterdays_Low and YLow ? Yesterdays_Low : na, title="Yesterday's Low", style=shape.labelup, location=location.absolute, color=YLowColor, text="Yesterday's Low", textcolor=color.white, size=size.small, show_last=1)     
plotshape(Yesterdays_Open and YOpen ? Yesterdays_Open : na, title="Yesterday's Open", style=shape.labelup, location=location.absolute, color=YOpenColor, text="Yesterday's Open", textcolor=color.white, size=size.small, show_last=1)     
plotshape(Yesterdays_Close and YClose ? Yesterdays_Close : na, title="Yesterday's Close", style=shape.labelup, location=location.absolute, color=YCloseColor, text="Yesterday's Close", textcolor=color.white, size=size.small, show_last=1)     
    
// weekly plotshapes
plotshape(Weekly_High and WHigh ? Weekly_High : na, title="Week's High", style=shape.labelup, location=location.absolute, color=WHighColor, text="Week's high", textcolor=color.white, size=size.small, show_last=1)
plotshape(Weekly_Low and WLow ? Weekly_Low : na, title="Week's Low", style=shape.labelup, location=location.absolute, color=WLowColor, text="Week's Low", textcolor=color.white, size=size.small, show_last=1)    
plotshape(Weekly_Open and WOpen ? Weekly_Open : na, title="Week's Open", style=shape.labelup, location=location.absolute, color=WOpenColor, text="Week's Open", textcolor=color.white, size=size.small, show_last=1)    
plotshape(Weekly_Close and WClose ? Weekly_Close : na, title="Week's Close", style=shape.labelup, location=location.absolute, color=WCloseColor, text="Week's Close", textcolor=color.white, size=size.small, show_last=1) 

// Monthly plotshapes
plotshape(Monthly_High and MHigh ? Monthly_High : na, title="Month's High", style=shape.labelup, location=location.absolute, color=MHighColor, text="Months's High", textcolor=color.white, size=size.small, show_last=1)
plotshape(Monthly_Low and MLow ? Monthly_Low : na, title="Month's Low", style=shape.labelup, location=location.absolute, color=MLowColor, text="Month's Low", textcolor=color.white, size=size.small, show_last=1)    
plotshape(Monthly_Open and MOpen ? Monthly_Open : na, title="Month's Open", style=shape.labelup, location=location.absolute, color=MOpenColor, text="Months's Open", textcolor=color.white, size=size.small, show_last=1)    
plotshape(Monthly_Close and MClose ? Monthly_Close : na, title="Month's Close", style=shape.labelup, location=location.absolute, color=MCloseColor, text="Month's Close", textcolor=color.white, size=size.small, show_last=1)    
    
    
    
    
    
    
    
    
    
    
    
    