PriceCatch-Intraday Volume
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PriceCatch
// You must credit PriceCatch if you modify this code or use it in your scripts.

//@version=5
indicator(title="PriceCatch-Intraday Volume", shorttitle="PC-IDVol", overlay=true)
if not timeframe.isintraday
    runtime.error("Please change to intraday time-frame chart")

var float   _bullVol = na
var int     _bullCandles = na
var float   _bullTrades = na

var float   _bearVol = na
var int     _bearCandles = na
var float   _bearTrades = na

var float   _dojiVol = na
var int     _dojiCandles = na
var float   _dojiTrades = na

_newDay     = ta.change(time('D'))

if _newDay

    _bearVol := 0
    _bearCandles := 0
    _bearTrades := 0

    _bullVol := 0
    _bullCandles := 0
    _bullTrades := 0

    _dojiVol := 0
    _dojiCandles := 0
    _dojiTrades := 0

if barstate.isconfirmed and  open > close
    _bearVol += volume
    _bearCandles += 1
    _bearTrades += volume / syminfo.pointvalue

if barstate.isconfirmed and  close > open
    _bullVol += volume
    _bullCandles += 1
    _bullTrades += volume / syminfo.pointvalue

if barstate.isconfirmed and  open == close
    _dojiVol += volume
    _dojiCandles += 1
    _dojiTrades += volume / syminfo.pointvalue


// print results
// Volume Info Panel Section
tblPos              = input.string(title='Position on Chart', defval='Bottom Center', options=['Top Left', 'Top Right', 'Bottom Left', 'Bottom Center', 'Bottom Right', 'Middle Left', 'Middle Right'], group="Information Panel")
tblposition         = tblPos == 'Top Left' ? position.top_left : tblPos == 'Top Right' ? position.top_right : tblPos == 'Bottom Left' ? position.bottom_left : tblPos == 'Bottom Center' ? position.bottom_center : tblPos == 'Bottom Right' ? position.bottom_right : tblPos == 'Middle Left' ? position.middle_left : position.middle_right

tblBorderColor      = input(title='Border Color', defval=#636363, group="Information Panel")

title1_bgColor      = input(title='Title Background', defval=#004074, group="Information Panel")
title1_textColor    = input(title='Title Text', defval=#7AC3ff, group="Information Panel")

_downBgColor        = input(title='Down Background Color', defval=#000000, group="Information Panel")
_downTextColor      = input(title='Down Text Color', defval=color.red, group="Information Panel")

_upBgColor          = input(title='Up Background Color', defval=#000000, group="Information Panel")
_upTextColor        = input(title='Up Text Color', defval=color.blue, group="Information Panel")

_dojiBgColor        = input(title='Doji Background Color', defval=#000000, group="Information Panel")
_dojiTextColor      = input(title='Doji Text Color', defval=color.rgb(185, 185, 185), group="Information Panel")

var table resultsTable = na

resultsTable := table.new(position=tblposition, columns=4, rows=4, bgcolor=#ffffff, border_width=0, frame_color=tblBorderColor, frame_width=2)


table.cell(         resultsTable, column=0, row=0, text= "", text_color=title1_textColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=title1_bgColor, text_size=size.normal)
table.cell(         resultsTable, column=1, row=0, text= "Volume", text_color=title1_textColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=title1_bgColor, text_size=size.normal)
table.cell(         resultsTable, column=2, row=0, text= "Candles", text_color=title1_textColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=title1_bgColor, text_size=size.normal)
table.cell(         resultsTable, column=3, row=0, text= "Trades", text_color=title1_textColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=title1_bgColor, text_size=size.normal)


table.cell(         resultsTable, column=0, row=1, text= "Down", text_color=_downTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_downBgColor, text_size=size.normal)
table.cell(         resultsTable, column=1, row=1, text= str.tostring(_bearVol), text_color=_downTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_downBgColor, text_size=size.normal)
table.cell(         resultsTable, column=2, row=1, text= str.tostring(_bearCandles), text_color=_downTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_downBgColor, text_size=size.normal)
table.cell(         resultsTable, column=3, row=1, text= str.tostring(_bearTrades), text_color=_downTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_downBgColor, text_size=size.normal)

table.cell(         resultsTable, column=0, row=2, text= "Up", text_color=_upTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_upBgColor, text_size=size.normal)
table.cell(         resultsTable, column=1, row=2, text= str.tostring(_bullVol), text_color=_upTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_upBgColor, text_size=size.normal)
table.cell(         resultsTable, column=2, row=2, text= str.tostring(_bullCandles), text_color=_upTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_upBgColor, text_size=size.normal)

table.cell(         resultsTable, column=3, row=2, text= str.tostring(_bullTrades), text_color=_upTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_upBgColor, text_size=size.normal)

table.cell(         resultsTable, column=0, row=3, text= "Doji", text_color=_dojiTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_dojiBgColor, text_size=size.normal)
table.cell(         resultsTable, column=1, row=3, text= str.tostring(_dojiVol), text_color=_dojiTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_dojiBgColor, text_size=size.normal)
table.cell(         resultsTable, column=2, row=3, text= str.tostring(_dojiCandles), text_color=_dojiTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_dojiBgColor, text_size=size.normal)

table.cell(         resultsTable, column=3, row=3, text= str.tostring(_dojiTrades), text_color=_dojiTextColor, text_halign=text.align_center, text_valign=text.align_center, bgcolor=_dojiBgColor, text_size=size.normal)

