Fusion: Big Arty Candles
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Koalems
// @version=5

indicator(
  shorttitle = "Fusion: BAC",
  title      = "Fusion: Big Arty Candles",
  overlay    = true
  )

maxLabels = 500

Group6300 = '6300 Big Arty Candles - Show'
stgyBACShowOnCandle                   = input.bool(true,                            group=Group6300,                                                                  title='Show on candle')
stgyBACShowLabel                      = input.bool(true,                            group=Group6300,                                                                  title='Show label')

Group6320 = '6320 Big Arty Candles - Source'
stgyBACUseHL                          = input.bool(true,                            group=Group6320,                                                                  title='High/Low')
stgyBACUseOC                          = input.bool(false,                           group=Group6320,                                                                  title='Open/Close')

Group6330 = '6330 Big Arty Candles - High/Low'
stgyBACToAverageHL                    = input.int(10,                               group=Group6330, minval=2,                                                        title='Number of bars to average')
stgyBACRelativeSizeHL                 = input.float(3.8,                            group=Group6330, minval=0, step=0.05,                                             title='Relative size of BAC')
stgyBACColorHL                        = input.color(color.new(#f57c00, 50),         group=Group6330,                                                                  title='Color')

Group6340 = '6340 Big Arty Candles - Open/Close'
stgyBACToAverageOC                    = input.int(10,                               group=Group6340, minval=2,                                                        title='Number of bars to average')
stgyBACRelativeSizeOC                 = input.float(3.8,                            group=Group6340, minval=0, step=0.05,                                             title='Relative size of BAC')
stgyBACColorOC                        = input.color(color.new(#7e57c2, 50),         group=Group6340,                                                                  title='Color')

stgyBACAvgHigh = ta.sma(high, stgyBACToAverageHL)
stgyBACAvgLow  = ta.sma(low,  stgyBACToAverageHL)

bool  stgyBAC    = na
bool  stgyBACHL  = na
bool  stgyBACOC  = na

if stgyBACUseHL
    stgyBACHL := high - low >= (stgyBACAvgHigh - stgyBACAvgLow) * stgyBACRelativeSizeHL

if stgyBACUseOC
    avg = ta.sma(open > close ? open - close : close - open, stgyBACToAverageOC)
    stgyBACOC := stgyBAC or math.abs(open - close) >= avg * stgyBACRelativeSizeOC

//stgyBAC = stgyBACHL or stgyBACOC

barcolor(
  stgyBACShowOnCandle and stgyBACHL ? stgyBACColorHL : na, 
  title='Big arty candle: High/Low')

barcolor(
  stgyBACShowOnCandle and stgyBACOC ? stgyBACColorOC : na, 
  title='Big arty candle: Open/Close')

plotshape(
  stgyBACShowLabel and stgyBACHL,
  style     = shape.labeldown,
  location  = location.top,
  color     = stgyBACColorHL,
  text      = 'BAC',
  textcolor = color.new(color.white, 0),
  size      = size.small,
  title     = 'Big arty candle: High/Low')

plotshape(
  stgyBACShowLabel and stgyBACOC,
  style     = shape.labeldown,
  location  = location.top,
  color     = stgyBACColorOC,
  text      = 'BAC',
  textcolor = color.new(color.white, 0),
  size      = size.small,
  title     = 'Big arty candle: High/Low')
