Traders Paradise
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Bull Club Bias

//@version=5
indicator(title="Traders Paradise", shorttitle="BCB_TP", format=format.price, precision=2, timeframe="", timeframe_gaps=true, overlay = true)


//define colours
color1 = #808080
color2 = #ff0000
color3 = #90ee90
color4 = #90ee90
color5 = #008000
color6 = #e0b0ff
color7 = #ffa500
color8 = #00ff00


//define choppiness
length = input.int(14, minval=1)
ci = 100 * math.log10(math.sum(ta.atr(1), length) / (ta.highest(length) - ta.lowest(length))) / math.log10(length)
offset = input.int(0, "Offset",  minval = -500, maxval = 500)
//plot(ci, "CHOP", color=#2962FF, offset = offset)
//band1 = hline(100, "Upper Band", color=#ffffff, linestyle=hline.style_dashed)
//band0 = hline(0, "Lower Band", color=#ffffff, linestyle=hline.style_dashed)
//fill(band1, band0, color = color.rgb(33, 150, 243,100), title = "Background")

ma1 = ta.sma(ci,25)
//plot(ma1, "CHOP MA", color=#000000, offset = offset)


//Define ATR
lengthATR = input.int(title="Length ATR", defval=14, minval=1)
smoothing = input.string(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])
ma_function(source, lengthATR) =>
	switch smoothing
		"RMA" => ta.rma(source, lengthATR)
		"SMA" => ta.sma(source, lengthATR)
		"EMA" => ta.ema(source, lengthATR)
		=> ta.wma(source, lengthATR)
//plot(ma_function(ta.tr(true), lengthATR), title = "ATR", color=color.new(#B71C1C, 0))

ma2 = ta.sma(ma_function(ta.tr(true), lengthATR),25)
//plot(ma2, "CHOP MA", color=#000000, offset = offset)

atrPLOT = ma_function(ta.tr(true), lengthATR)

x = 0

//Define COlour selection   
if ((ci >= ma1) and (atrPLOT <= ma2))// and (ci > ci[1]))
    x := 1
if ((ci >= ma1) and (atrPLOT <= ma2))// and (ci < ci[1]))
    x := 1
if ((ci >= ma1) and (atrPLOT > ma2))// and (ci > ci[1]))
    x := 2
if ((ci >= ma1) and (atrPLOT > ma2))// and (ci < ci[1]))
    x := 2
if ((ci < ma1) and (atrPLOT <= ma2))// and (ci > ci[1]))
    x := 3
if ((ci < ma1) and (atrPLOT <= ma2))// and (ci < ci[1]))
    x := 3
if ((ci < ma1) and (atrPLOT > ma2))// and (ci > ci[1]))
    x := 4
if ((ci < ma1) and (atrPLOT > ma2))// and (ci < ci[1]))
    x := 4

//plot (10*x,"X")


//Colour the background
sessioncolor = (x<2)?color1:(x<3 and x>1)?color2:(x<4and x>2)?color3:(x<5and x>3)?color4:color1//(x<6 and x>4)?color5:(x<7and x>5)?color6:(x<8and x>6)?color7:(x<9and x>7)?color8:color1

bgcolor(sessioncolor,transp = 90,title = "Trading")