NumberOfVisibleBars
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mentalRock19315

//@version=5

// @description TODO: add library description here
library("NumberOfVisibleBars",true)

// @function Calculates the number of visible bars on the user screen
// @param No paramters needed
// @returns The numbers of visible bars on the user screen (int)
export NumberOfVisibleBars() =>
	start_time = chart.left_visible_bar_time // get unix time in milli seconds
	end_time = chart.right_visible_bar_time
	resolution = timeframe.period
	Visibles_bars = 0

	second_divider = 0
	if str.contains(resolution, "S")
		if str.length(resolution) == 1
			second_divider := 1
		else
			second_divider := int(str.tonumber(str.substring(resolution, 0,str.length(resolution)-1)))
	else if str.contains(resolution, "D")
		if str.length(resolution) == 1
			second_divider := 60*60*24
		else
			second_divider := int(str.tonumber(str.substring(resolution, 0,str.length(resolution)-1)))*60*60*24
	else if str.contains(resolution, "W")
		if str.length(resolution) == 1
			second_divider := 60*60*24*7
		else
			second_divider := int(str.tonumber(str.substring(resolution, 0,str.length(resolution)-1)))*60*60*24*7
	else if str.contains(resolution, "M")
		if str.length(resolution) == 1
			second_divider := 60*60*24*365/12
		else
			second_divider := int(str.tonumber(str.substring(resolution, 0,str.length(resolution)-1)))*60*60*24*365/12
	else
		if str.length(resolution) == 1
			second_divider := 60
		else
			second_divider := int(str.tonumber(resolution)*60)
	if second_divider > 0
		Visibles_bars := int((end_time-start_time)/1000/second_divider + 1)

	Visibles_bars