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

//@version=5

library("L_Trade_Boundaries", overlay = true)
export litmus_color(float value1, float value2)=>
	// Litmus
	color_return = if value1 >= value2
		color.green
	else
		color.red

export lister(int length) =>
	// This goes back in history in a form of an array
	array_values_via_length = array.new_float(length, 0)
	for i = 1 to length+1
		array.insert(array_values_via_length,i,low[i])
		array_values_via_length
//
export moving_averages()=>
	// Moving Averages
	ma_14 = ta.sma(close,14)
	ma_28 = ta.sma(close,28)
	ma_200 = ta.sma(close,200)

	// color_cord
	close_ma_14_color = litmus_color(close, ma_14)
	close_ma_28_color = litmus_color(close, ma_28)
	close_ma_200_color = litmus_color(close, ma_200)
	// Table 
	table_ma = table.new(position.bottom_right, 2,4, color.gray)
	table.cell(table_ma,0,1,"MA-20")
	table.cell(table_ma,0,2,"MA-28")
	table.cell(table_ma,0,3,"MA-200")

	table.cell(table_ma,1,1,str.tostring(math.round(ma_14,2)), text_color = close_ma_14_color)
	table.cell(table_ma,1,2,str.tostring(math.round(ma_28,2)), text_color = close_ma_28_color)
	table.cell(table_ma,1,3,str.tostring(math.round(ma_200,2)), text_color = close_ma_200_color)
	[ma_14,ma_28,ma_200]
//
export timeframe_upper()=>
	timeframe_output = if timeframe.period == "D"
		timeframe.change("W")
	else if timeframe.period == "W"
		timeframe.change("M")
	else if timeframe.period == "M"
		timeframe.change("12M")
	else
		timeframe.change("D")
//			
export timeframe_highlight(simple string timeframe)=>
	return_value = if timeframe == "Disable"		// Show highlight or no?
		na											// Don't Show
	else
		if timeframe == "Auto"						// Auto
			timeframe_upper()						// Daily -> Weekly -> Monthly -> Yearly
		else
			if timeframe.period != timeframe		// Manual
				timeframe.change(timeframe)			// Changing the value with the timeframe (manual Input)
			else
				na

	
	
//

length_input_trend = input.int(4,"Input Trend",1)

array_length_based_trend = lister(length_input_trend)
plot(array.max(array_length_based_trend), color=color.new(color.yellow,60))


time_frame_select = input.timeframe("D","Custom TimeFrame",["Auto","Disable","D","W","M","3M","12M"])
[ma_14,ma_28,ma_200]=moving_averages()

variable_timeframe = timeframe_highlight(time_frame_select)
bgcolor( variable_timeframe ? color.new(color.red,70): na)
//bgcolor(close < open ? color.new(color.red,70) : color.new(color.green, 70))