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

// ██████████████████████████████████████████████████████████████████████
// █▄─▄─▀██▀▄─██▄─▄▄▀█▄─▄▄─█▄─▄▄─█─▄▄─█─▄▄─█─▄─▄─███▄─▄█─▄▄─█▄─▄▄─█▄─█─▄█
// ██─▄─▀██─▀─███─▄─▄██─▄█▀██─▄███─██─█─██─███─███─▄█─██─██─██─▄█▀██▄─▄██
// █▄▄▄▄██▄▄█▄▄█▄▄█▄▄█▄▄▄▄▄█▄▄▄███▄▄▄▄█▄▄▄▄██▄▄▄██▄▄▄███▄▄▄▄█▄▄▄▄▄██▄▄▄██

//@version=5
indicator(title="Gamification Indicator", overlay=true)

// -------------------------------- Groups ---------------------------------- //
grp = "Player"
grt = "Trend"
gro = "Obstacle"
grc = "Celestial"


// --------------------------------- Colors --------------------------------- //
red = color.red
green = color.green
nocol = color.gray
brightred = #ff1100
brightgreen = #00ff0a

// -------------------------------- Theme ----------------------------------- //
// Additional Emoji COnsiderations
// Celestial/Top🌙🌜⛳
// Obstacles🌳🪁🚧

surfer =" 🏄‍♂️"
merman = "🧜‍♂"
skier = "🏂"
alien = "🛸"
plane = "🛫"
parachute = "🪂"
rocket = "🚀"
butterfly = "🦋"
pacishman = "👾"
shark = "🦈"
earth = "🌎"
tree = "🌲"
mountain ="🗻"
cactus = "🌵"
fire = "🔥"
waves = "🌊"
volcano = "🌋"
lightning = "⚡"
sun = "🌞"
moon = "🌛"
galaxy = "🌌"
saturn = "🪐"
error = "⛔"

// -------------------------------- Constants ------------------------------- //
constantvar=1>0

// Decimals
pricedecimals= input.int(defval=2, title='Number of Price Decimals', minval=0, maxval=10)
truncateprice(number, pricedecimals) =>
    factor = math.pow(10, pricedecimals)
    int(number * factor) / factor

// --------------------------------- Inputs --------------------------------- //
size = input.string(size.huge, "Emoji Size", [size.tiny, size.small, size.normal, size.large, size.huge])
transp = input.int(20, "Emoji Transparency", minval=0, maxval=100)
vehicle = input.string(plane, "Player Emoji", options=[plane,alien,parachute,rocket,butterfly,merman,surfer,"Custom","None"], group=grp)
customv = input.string("👾", "Custom Player Emoji", group=grp)
trend = input.string("Clouds", "Trend Type", options=["Clouds", "Waves", "Channel", "None"],group=grt)

// ------------------------- Ichimoku Clouds -------------------------------- // 
// Inputs
conversionPeriods = 9
basePeriods = 26
laggingSpan2Periods = 52
displacement = 26
//
// Calculations
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)

// Plots & Fills
p3 = plot(conversionLine, color=nocol, title="Conversion Line (Tenkan-Sen)", display=display.none, editable=false)
p4 = plot(baseLine, color=conversionLine>baseLine?green:red, title="Base Line (Kijun-sen)", display=display.none, editable=false)
fill(p3, p4, color = trend == "Clouds" ? color.new(nocol,80):na)
p1 = plot(leadLine1, offset = displacement - 1, color=nocol, title="Leading Span A (Senkou Span A)", display=display.none, editable=false) // green
p2 = plot(leadLine2, offset = displacement - 1, color=leadLine1>leadLine2?green:red, title="Leading Span B (Senkou Span B)", display=display.none, editable=false) // green
fill(p1, p2, color = trend == "Clouds" ? color.new(nocol,80):na)

// ----------------------------------- MA Clouds ---------------------------- //
fastma1 =ta.ema(close,8)
fastma2 =ta.ema(close,34)
slowma1 =ta.ema(close,89)
slowma2 =ta.ema(close,233)
slowestma = ta.ema(close,618)

fastma1f = plot(fastma1, color=color.gray, display=display.none, editable=false)
fastma2f = plot(fastma2, color=color.gray, display=display.none, editable=false)
slowma1f = plot(slowma1, color=color.gray, display=display.none, editable=false)
slowma2f = plot(slowma2, color=color.gray, display=display.none, editable=false)
slowest = plot(slowestma, color=color.gray, display=display.none, editable=false)

fill(fastma1f, fastma2f, color=trend == "Waves" ? color.new(color.blue,80):na)
fill(fastma2f, slowma1f, color=trend == "Waves" ? color.new(color.blue,90):na)
fill(slowma1f, slowma2f, color=trend == "Waves" ? color.new(color.blue,95):na)
fill(fastma1f, slowest, color=trend == "Waves" ? color.new(color.blue,80):na)

// ------------------------------------ Channel ----------------------------- //
length = 233 //input(233, 'Channel Length', group = grt)
highestBar = ta.highest(high, length)
lowestBar = ta.lowest(low, length)
midBar = (highestBar + lowestBar) / 2
channelColor = color.new(#964b00,65)

midChannel = plot(trend == "Channel" ? midBar : na, color=channelColor, style=plot.style_line, linewidth=1)
upperChannel = plot(trend == "Channel" ? highestBar : na, color=channelColor, style=plot.style_line, linewidth=1)
lowerChannel = plot(trend == "Channel" ? lowestBar : na, color=channelColor, style=plot.style_line, linewidth=1)
upperMidChannel = plot(trend == "Channel" ? midBar + (highestBar - midBar) * 0.5 : na, style=plot.style_line, linewidth=1, color=channelColor, display=display.none)
lowerMidChannel = plot(trend == "Channel" ? midBar - (midBar - lowestBar) * 0.5 : na, style=plot.style_line, linewidth=1, color=channelColor, display=display.none)

fill(midChannel, upperChannel, color=trend == "Channel" ? color.new(#964b00, 95) : na)
fill(lowerChannel, midChannel, color=trend == "Channel" ? color.new(#964b00, 95) : na)
fill(upperMidChannel, upperChannel, color=trend == "Channel" ? color.new(#964b00, 80) : na)
fill(lowerChannel, lowerMidChannel, color=trend == "Channel" ? color.new(#964b00, 80) : na)

// ------------------------------ Player ------------------------------------ //
// ConTrail (OHLC4)
src = input.source(ohlc4, "Source", group=grp)
ctlen = input.int(89, "Trail Color Fade Length", minval=1, group=grp)
ctcol = input.color(color.white, "Trail Color", group=grp)
plot(src, "OHLC4 Long Trail", color=color.new(ctcol,80), linewidth=3)
plot(src, "OHLC4 Mid Trail", color=color.new(ctcol,65), linewidth=2, show_last=ctlen*3)
plot(src, "OHLC4 Short Trail", color=color.new(ctcol,50), linewidth=1, show_last=ctlen)

// Current Altitude (Price Line)
linelevel=src
altcol = src>src[1] ? green: red
var line l8 = na
line.delete(l8)
l8 := line.new(bar_index, linelevel, bar_index + 25, linelevel, color=color.new(altcol, 0), style=line.style_dotted)
// Altitude Label (Price Label)
altoffset = input.int(7, "Price Close Label Horizontal Offset", group=grp)
var label bl = na
label.delete(bl)
bl := label.new(bar_index + altoffset, linelevel, str.tostring(truncateprice(close, pricedecimals)), textcolor=altcol, color=color.new(#000000, 100), style=label.style_label_down, size=size.small) 

// Vehicle Label
emoji2 = src>src[1]?"🛫":"🛬"
whichvehicle=vehicle == plane ? emoji2 : vehicle == alien ? alien : vehicle == parachute ? parachute : vehicle == "Custom" ? customv : vehicle == "None" ? na : vehicle == merman ? merman : vehicle == rocket ? rocket : vehicle == butterfly ? butterfly : vehicle == surfer ? surfer : error
col = color.orange 
planelocation = yloc.price 
planePrice = ta.valuewhen(bar_index, src, 0)
var label planel = na
planel := label.new(bar_index, y=planePrice, yloc=planelocation, size=size, text=whichvehicle, style=label.style_none, textcolor=color.new(col,transp))
label.delete(planel[1])

// ------------------------------ Celestial --------------------------------- //
// Define Daytime, get corresponding Sun/Moon emoji, and give tooltips
zero = timestamp(2009, 03, 11, 00, 00)
ts = time('D')
lunarmonth = 2551442890
altcols = 4
rot = (ts - zero) / (lunarmonth/8) % 8
daytime = time(timeframe.period, '0700-1900')
whichmoon = rot<1 ? "🌕" : rot<2 ? "🌔" : rot<3 ? "🌓" : rot<4 ? "🌒" : rot<5 ? "🌑" : rot<6 ? "🌒" : rot<7 ? "🌗" : rot<8 ? "🌖" : na 
ttip = rot<1 ? "Full Moon (4/8)" : rot<2 ? "Waning Gibbous (5/8)" : rot<3 ? "Last Quarter (6/8)" : rot<4 ? "Waning Crescent (7/8)" : rot<5 ? "New/No Moon (8/8)" : rot<6 ? "Waxing Crescent (1/8)" : rot<7 ? "First Quarter (2/8)" : rot<8 ? "Waxing Gibbous (3/8)" : na
watermark2 = daytime ? '🌞' : whichmoon 
actualtt = "🌙 Phase: " + ttip 
// Plot the celestial body
watermark4 = input.string("Live/Actual", "Celestial Emoji", options=[lightning, sun, moon, galaxy, saturn, "Live/Actual","Custom", "None"],group=grc) 
customc = input.string("🌙", "Custom Celestial Emoji", group=grc)
whichcelestial = watermark4 == moon ? moon : watermark4 == lightning ? lightning : watermark4 == sun ? sun : watermark4 == galaxy ? galaxy : watermark4 == saturn ? saturn : watermark4 == "Live/Actual" ? watermark2 : watermark4 == "None" ? na : watermark4 == "Custom" ? customc : error
whichcelestialtt = watermark4 == "Live/Actual" ? actualtt : na
position4 = position.top_right
var table celestial = table.new(position4, 1, 1)
table.cell(celestial, 0, 0, whichcelestial, text_size = size, text_color = color.new(col, transp), tooltip=whichcelestialtt)
  
// --------------------------------- Obstacle ------------------------------- //
watermark3 = input.string(mountain, "Obstacle Emoji", options=[mountain, shark, tree, earth, fire, volcano, waves, "Custom", "None"],group=gro)
customo = input.string(cactus, "Custom Obstacle Emoji", group=gro)
whichobstacle = watermark3 == mountain ? mountain : watermark3 == shark ? shark : watermark3 == tree ? tree : watermark3 == earth ? earth : watermark3 ==fire ? fire : watermark3 == volcano ? volcano : watermark3 == "Custom" ? customo : watermark3 == "None" ? na : watermark3== waves ? waves : error
position3 = position.bottom_right
var table obstacle = table.new(position3, 1, 1)
table.cell(obstacle, 0, 0, whichobstacle, text_size = size, text_color = color.new(col, transp))

// EoS made w/ ❤ by @BarefootJoey ✌💗📈