[FR]Custom Candles/FVG/nSideBar
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FFriZz

//@version=5
indicator("Custom Candles",overlay = true,max_lines_count = 500,max_labels_count = 500,max_boxes_count = 500,explicit_plot_zorder = true)

//Inputs//
//Bar Switch//
MESSAGE = input.text_area("🔥      🔥      🔥     🔥      🔥   Custom Candles   🔥     🔥     🔥      🔥      🔥\nDon't hide your Candles!! Turn the transparency in chart settings down or\nyou can check the boxes and turn them off very inconvenient if you have\nyour candles turned off when changing charts.. I've now learned.. =D\nand this removes the Price Label on the Y-axis/bar countdown/and ticker\nwould still move to top of object tree..\n\n⇩    ⇩    ⇩    ⇩    ⇩    ⇩    ⇩    ⇩ ----- UPDATES ----- ⇩    ⇩    ⇩    ⇩    ⇩    ⇩    ⇩\n\n-I added a Price Line option so now you can have a \nSolid-Dashed-Dotted and Arrow Style for the Price Line with a Price Label\nthat you can move along the X-axis and the Price Line is adjustable from\nleft to right\n-I added a price line that you can make how ever you want\n-I added added an option to change color of price line by tick\n-Theres a couple of labels that will change direction with price aswell\nand now there is a tooltip that has OHLC values just hover over the label\n\nI posted pictures on the chart of the indicator download if you didn't \nunderstand what settings exactly I'm referring too\n\nMessage me if you have any questions, or if there is a bug\nits hard to catch everything\nI understand this is over kill but after people liked it I figured id make it as customizable as possible\n\nHope you enjoy!\n💲💰 FFriZz 💰💲\n",'README')
SLIM = input.bool(false,'SLIM Candles'      ,group = 'Candle MODE',inline = '')         
NORMAL = input.bool(true,'NORMAL Candles'   ,group = 'Candle MODE',inline = '')          

if SLIM == true
    NORMAL := false
if NORMAL == true
    SLIM := false

//Price Line//
pllineonoff =   input.bool(true ,'Price Line | On/Off?'                                                                                 ,group = 'Price Line')         
lstyle =        input.string('Solid','Price Line Style',options = ['Solid','Dashed','Dotted','Arrow Right','Arrow Left','Arrow Both']   ,group = 'Price Line', inline = 'a')
plinew =        input.int(1 ,'Width -->'                                                                                                ,group = 'Price Line', inline = 'a')
extend =        input.string('Extend Both','Extend Price Line',options = ['Extend Both','Extend None','Extend Right','Extend Left']     ,group = 'Price Line', inline = 'a')
offset1 =       input.int(0,'Price Line offset Left -->'                                                                                ,group = 'Price Line', inline = 'b', maxval = 0) 
offset2 =       input.int(5,'Price Line offset Right -->'                                                                               ,group = 'Price Line', inline = 'b', minval = 0) 
linetick =      input.bool(true ,'Change Line Color on Up/Down Ticks | On/Off?'                                                         ,group = 'Price Line') 

//Price Label//
pllabelonoff =  input.bool(true ,'Price Label | On/Off?'                                                                                ,group = 'Price Label', inline = 'd')         
labeloffset =   input.int(5,'Label offset -->'                                                                                          ,group = 'Price Label', inline = 'e') 
lblsize =       input.string('Normal','Label Size',options = ['Auto','Tiny','Small','Normal','Large','Huge']                            ,group = 'Price Label', inline = 'e')
lblstyle =      input.string('arrow','Price Label Style -->' ,options = ['NONE','arrow','circle','cross','diamond','label_center','label_down','label_left','label_lower_left','label_lower_right','label_right','label_up','label_upper_left','label_upper_right','square','flag','triangle']                                                            ,group = 'Price Label'  ,inline = 'h') 
lbltick =       input.bool(true ,'Change Label Color on Up/Down Ticks | On/Off?'        ,group = 'Price Label') 
 
//FVG// 
FVG =           input.bool(true ,'FVG | On/Off?'                                        ,group = 'FVG')         
FVGplot =       input.bool(true ,'FVG Type | (Big FVG = On) | (SLIM FVG = off)'         ,group = 'FVG')         
FVGw =          input.int(2 ,'Small FVG Width -->'                                      ,group = 'FVG'           ,inline = '1')


//Inside Bar//
ISB =           input.bool(true ,'INSIDE BAR | On/Off?'                                 ,group = 'INSIDE-Bar'    ,inline = '')         
ISBplot =       input.bool(false ,'ISB Type | (Big ISB = On) | (SLIM ISB = off)'        ,group = 'INSIDE-Bar'    ,inline = '')         
ISBw =          input.int (2 ,'Big ISB Width -->'                                       ,group = 'INSIDE-Bar'    ,inline = '')

upc = open < close

//Colors//
labelbgup =              input.color(color.lime     ,'Label --> Up'                     ,group = 'Price Label'   ,inline = 'f')           
labelbgdown =            input.color(color.red      ,'Down'                             ,group = 'Price Label'   ,inline = 'f') 
labeltextup =            input.color(#000000        ,'Label Text --> Up'                ,group = 'Price Label'   ,inline = 'g')           
labeltextdown =          input.color(#000000        ,'Down'                             ,group = 'Price Label'   ,inline = 'g') 
PriceCup =               input.color(color.lime     ,'Price Line --> Up'                ,group = 'Price Line'    ,inline = 'c')           
PriceCdown =             input.color(color.red      ,'Down'                             ,group = 'Price Line'    ,inline = 'c')
BULLfvgc =               input.color(color.white    ,'BullFVG -->'                      ,group = 'FVG'           ,inline = '1')
BEARfvgc =               input.color(color.white    ,'BearFVG --> '                     ,group = 'FVG'           ,inline = '1')

//?: Colors//
ISBc =           upc ?   input.color(color.white    ,'ISB --> Bull'                     ,group = 'INSIDE-Bar'    ,inline = '3')           :
                         input.color(color.white    ,'Bear'                             ,group = 'INSIDE-Bar'    ,inline = '3')                      
NORMALtwickc =   upc ?   input.color(color.red      ,'NORMAL | Top Wick --> Up'         ,group = 'NORMAL Candle' ,inline = 'tw')          :     
                         input.color(color.red      ,'Down'                             ,group = 'NORMAL Candle' ,inline = 'tw')
NORMALbwickc =   upc ?   input.color(color.lime     ,'NORMAL | Bottom Wick --> Up'      ,group = 'NORMAL Candle' ,inline = 'bw')          :     
                         input.color(color.lime     ,'Down'                             ,group = 'NORMAL Candle' ,inline = 'bw')
NORMALbodyc =    upc ?   input.color(#000000        ,'NORMAL | Body --> Up'             ,group = 'NORMAL Candle' ,inline = 'body')        :
                         input.color(#000000        ,'Down'                             ,group = 'NORMAL Candle' ,inline = 'body')        
NORMALborderc =  upc ?   input.color(#000000        ,'NORMAL | Border --> Up'           ,group = 'NORMAL Candle' ,inline = 'border')      :
                         input.color(#000000        ,'Down'                             ,group = 'NORMAL Candle' ,inline = 'border')    
SLIMtwickc =     upc ?   input.color(color.red      ,'SLIM | Top Wick --> Up'           ,group = 'SLIM Candle'   ,inline = 'tw')          :
                         input.color(color.red      ,'Down'                             ,group = 'SLIM Candle'   ,inline = 'tw')
SLIMbwickc =     upc ?   input.color(color.lime     ,'SLIM | Bottom Wick --> Up'        ,group = 'SLIM Candle'   ,inline = 'bw')          :
                         input.color(color.lime     ,'Down'                             ,group = 'SLIM Candle'   ,inline = 'bw')
SLIMbodyc =      upc ?   input.color(#000000        ,'SLIM | Body --> Up'               ,group = 'SLIM Candle'   ,inline = 'bs')          :
                         input.color(#000000        ,'Down'                             ,group = 'SLIM Candle'   ,inline = 'bs')          
SLIMborderctop = upc ?   input.color(#000000        ,'SLIM | Top (o,c) --> Up'          ,group = 'SLIM Candle'   ,inline = 'bordert')     :
                         input.color(#000000        ,'Down'                             ,group = 'SLIM Candle'   ,inline = 'bordert')     
SLIMbordercbot = upc ?   input.color(#000000        ,'SLIM | Bottom (o,c) --> Up'       ,group = 'SLIM Candle'   ,inline = 'borderb')     :
                         input.color(#000000        ,'Down'                             ,group = 'SLIM Candle'   ,inline = 'borderb')     
SLIMoc =                 input.bool (true ,'SLIM Bar | (Open and Close Line) | On/Off?' ,group = 'SLIM Candle'   ,inline = 'bs') 

//Tick & Bar Color Change//
varip bool lblip = na
varip bool lineip = na
varip ipclose = close
int ip = 0

if ta.change(close)
    if ipclose > close
        ip := -1
    if ipclose < close
        ip := 1
    ipclose := close

if lbltick
    lblip  := ip > 0
if linetick
    lineip := ip > 0

PriceC = linetick ? lineip ? PriceCup : PriceCdown : upc ? PriceCup : PriceCdown
labelbg = lbltick ? lblip ? labelbgup : labelbgdown : upc ? labelbgup : labelbgdown
labeltext = lbltick ? lblip ? labeltextup : labeltextdown : upc ? labeltextup : labeltextdown

//Vars - Conditions//
sbt = upc ? close :  open
sbb = upc ?  open : close
ISBar = ISB and high < high[1] and low > low[1]
BearFVG = high < low[2] and FVG   
BullFVG = low  > high[2] and FVG
FVGc = BullFVG ? BULLfvgc : BEARfvgc

//Switches//
Linestyle = switch lstyle
    'Solid' => line.style_solid
    'Dashed' => line.style_dashed
    'Dotted' => line.style_dotted
    'Arrow Right' => line.style_arrow_right
    'Arrow Left' => line.style_arrow_left
    'Arrow Both' => line.style_arrow_both
    => na
    
Extend = switch extend
    'Extend Both' => extend.both
    'Extend None' => extend.none
    'Extend Right' => extend.right
    'Extend Left' => extend.left
    => na  

Labelstyle = switch lblstyle    
    'arrow' => lbltick ? lblip ? label.style_arrowup : label.style_arrowdown : upc ? label.style_arrowup : label.style_arrowdown
    'circle' => label.style_circle
    'cross' => label.style_cross
    'diamond' => label.style_diamond
    'label_center' => label.style_label_center
    'label_down' => label.style_label_down
    'label_left' => label.style_label_left
    'label_lower_left' => label.style_label_lower_left
    'label_lower_right' => label.style_label_lower_right
    'label_right' => label.style_label_right
    'label_up' => label.style_label_up
    'label_upper_left' => label.style_label_upper_left
    'label_upper_right' => label.style_label_upper_right
    'square' => label.style_square
    'flag' => label.style_flag
    'triangle' => lbltick ? lblip ? label.style_triangleup : label.style_triangledown : upc ? label.style_triangleup : label.style_triangledown
    => label.style_none  
    
Labelsize = switch lblsize
    'Tiny' => size.tiny
    'Small' => size.small
    'Normal' => size.normal
    'Large' => size.large
    'Huge' => size.huge
    'Auto' => size.auto
    => na
    
// FVGs w/ Lines//
if (BullFVG or BearFVG) and not FVGplot
    line1 = line.new(
     bar_index - 1, 
     BearFVG ? low[2] : high[2],
     bar_index - 1,
     BearFVG ? high : low,
     width = FVGw,
     color = FVGc
     ) 

// ISBs w/ Lines for an adjustable ISB Width//
if ISBar  and ISBplot
    line2 = line.new(
     bar_index,
     open,
     bar_index,
     close,
     width = ISBw,
     color = ISBc
     ) 
     
//SLIM top and bot wicks//
plotcandle(SLIM ? sbt : na, high ,high, sbt, color = na ,bordercolor = na ,wickcolor = SLIMtwickc ,editable = false)
plotcandle(SLIM ? sbb : na, low  ,low , sbb, color = na ,bordercolor = na ,wickcolor = SLIMbwickc ,editable = false)

//SLIM borders//
plotcandle(SLIM ? sbt : na ,sbt ,sbt ,sbt ,color = na ,bordercolor = SLIMoc ? SLIMborderctop : na ,wickcolor = na ,editable = false) 
plotcandle(SLIM ? sbb : na ,sbb ,sbb ,sbb ,color = na ,bordercolor = SLIMoc ? SLIMbordercbot : na ,wickcolor = na ,editable = false)

//SLIM body//
plotcandle(SLIM ? close : na ,open ,open ,close ,color = na ,bordercolor = na ,wickcolor = ISBar  ? ISBc : SLIMbodyc ,editable = false)

//NORMAL border,body,wicks//
plotcandle(NORMAL ? open : na ,high , low ,close ,color = ISBar  and not ISBplot ? ISBc : NORMALbodyc ,bordercolor = NORMALborderc ,wickcolor = na ,editable = false)
plotcandle(NORMAL ?  sbt : na ,high ,high ,  sbt ,color =                                             na ,bordercolor =            na ,wickcolor = NORMALtwickc ,editable = false)
plotcandle(NORMAL ?  sbb : na ,low  , low ,  sbb ,color =                                             na ,bordercolor =            na ,wickcolor = NORMALbwickc ,editable = false)

//Sticking with the Theme custom Price/Line and Label//
var label Label = na
var line  Line = na
if pllabelonoff    
    label.delete(Label)
    Label := label.new(bar_index + labeloffset, close, text = str.tostring(close) + (Labelstyle == 'NONE' ? '\n\n' : ''), color = labelbg, style = Labelstyle, textcolor = labeltext, size = Labelsize, tooltip = 
     '---- OHLC ----\n' +  'Open: ' + str.tostring(open) + '\nHigh: ' + str.tostring(high) + '\nLow: ' + str.tostring(low) + '\nClose: ' + str.tostring(close))
if pllineonoff
    line.delete(Line)
    Line := line.new(bar_index + offset1, close, last_bar_index + offset2, close, extend = Extend, color = PriceC, style = Linestyle, width = plinew)

// Another Option For Price Line ⇊ //
// plot(close, color = color.lime, show_last = 1, offset = -99999999, trackprice = true)

//To make sure the FVG plotting pairs are skipping a bar incase of back to back FVG's
bool BearFVGp = false
bool BullFVGp = false

if BearFVG
    BearFVGp := true
if BearFVGp == true and BearFVGp[1] == true
    BearFVGp := false
if BullFVG
    BullFVGp := true
if BullFVGp == true and BullFVGp[1] == true
    BullFVGp := false
    
BullGO1 = BullFVG and BullFVGp
BearGO1 = BearFVG and BearFVGp

BullGO2 = BullFVG and BullGO1 == false
BearGO2 = BearFVG and BearGO1 == false

//Bear-Bull FVG plots//
//Plots Need Sequences to prevent the fills from forming to plot lines and covering 2 bars if another FVG is on next Bar
//Can have Bear and Bull in each plot pair because you cant have a Bull and Bear FVG on the Same bar
//-- Pair 1 -- //
p1 = plot(FVGplot ? 
 BearGO1 ? low[2] : BullGO1 ? low : na : na,
 style = plot.style_stepline,
 offset=-1, display = display.none,
 editable = false)
p2 = plot(FVGplot ? 
 BearGO1 ? high : BullGO1 ? high[2] : na : na,
 style = plot.style_stepline,
 offset=-1, display = display.none,
 editable = false)
fill(p1,p2,color = FVGc[1], editable = false)

//-- Pair 2 -- //
p3 = plot(FVGplot ? 
 BearGO2 ? low[2] : BullGO2 ? low : na : na,
 style = plot.style_stepline,
 offset=-1, display = display.none,
 editable = false)
p4 = plot(FVGplot ? 
 BearGO2 ? high : BullGO2 ? high[2] : na : na,
 style = plot.style_stepline,
 offset=-1, display = display.none,
 editable = false)
fill(p3,p4,color = FVGc[1], editable = false)
