Bias Pivot Point
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Botnet101

//@version=5
indicator(title='Bias Pivot Point', overlay=true)

// INPUTS
//{
_timeframe     = input.string(defval='3M' , title='Pivots Timeframe', options=['15', '30', '60', '240', 'D', 'W', 'M', '3M', '12M'])

colourBars     = input.bool  (defval=false, title='Colour Bars?'      , group="Plot Settings")
showPivot      = input.bool  (defval=true , title='Show Pivot Points?', group="Plot Settings")
fillPlot       = input.bool  (defval=true , title='Fill plot?'        , group="Plot Settings")

colour_bullish = input.color(defval=color.new(color.green, 70), title="Bullish", group="Colours")
colour_bearish = input.color(defval=color.new(color.red  , 70), title="Bearish", group="Colours")
//}


// FUNCTIONS
//{
GetData(timeframe, data) => request.security(syminfo.tickerid, timeframe, data[1], lookahead=barmerge.lookahead_on)

GetColour (canShow, _colour) => canShow ? _colour : na

// Calculate Pivot Points
CalculatPivotPoint () =>
    float dailyHigh  = GetData(_timeframe, high )
    float dailyLow   = GetData(_timeframe, low  )
    float dailyClose = GetData(_timeframe, close)
    
    (dailyHigh + dailyLow + dailyClose) / 3
//}

    
float pivotPoint  = CalculatPivotPoint ()

color bias_colour       = close > pivotPoint ? colour_bullish : colour_bearish
color cloud_colour      = GetColour(fillPlot  , bias_colour              )
color pivotPoint_colour = GetColour(showPivot , color.new(bias_colour, 0))
color bar_colour        = GetColour(colourBars, color.new(bias_colour, 0))


plot_close = plot(ohlc4     , title='Close', color=na               , style=plot.style_stepline, editable=false             )
plot_pivot = plot(pivotPoint, title='Pivot', color=pivotPoint_colour, style=plot.style_stepline, editable=true , linewidth=2)


fill    (plot_pivot, plot_close, color=cloud_colour, editable=false)
barcolor(bar_colour                                , editable=false)