Standard Deviation Candles (With Emoji)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator('Standard Deviation Candles With Emoji', 
     overlay=true, 
     shorttitle='StDev Candles w/ Emoji',
     timeframe="", 
     timeframe_gaps=true)

up = close > open
down = open > close

//input
len = input.int(defval=20, title='SD Period', minval=2, inline='00', 
     group='Candle Coloring Based On Normal Distribution, Unique Colors When Current Bar Differs From Previous Candles By > 1.5, 2, 2.5, and 3 Std Dev. Note: Works good with Heikin Ashi!')
showchars = input.bool(true, 'Show Emoji?', 
     group='Candle Coloring Based On Normal Distribution, Unique Colors When Current Bar Differs From Previous Candles By > 1.5, 2, 2.5, and 3 Std Dev. Note: Works good with Heikin Ashi!', inline='00')
showcolors = input.bool(true, 'Bar colors?', 
     group='Candle Coloring Based On Normal Distribution, Unique Colors When Current Bar Differs From Previous Candles By > 1.5, 2, 2.5, and 3 Std Dev. Note: Works good with Heikin Ashi!', inline='00')

fomoinp1 = input(open, 'Up              Baseline', group='How Significant Moves Are Measured', inline='0')
fomoinp2 = input(high, 'High Point', group='How Significant Moves Are Measured', inline='0')

dumpinp1 = input(open, 'Down          Baseline', group='How Significant Moves Are Measured', inline='1')
dumpinp2 = input(low, ' Low Point', group='How Significant Moves Are Measured', inline='1')

col_upreg = input.color(color.new(#26a69a, 0), 'Regular                Up', group='Regular Candles', inline='00')
col_dnreg = input.color(color.new(#ff5252, 0), 'Down', group='Regular Candles', inline='00')
transpreg = input.int(title='Transparency', defval=0, minval=0, maxval=100, group='Regular Candles', inline='00')
//
onepointfive = input.float(title='', defval=1.5, step=0.01, group='Candles Greater Than ... Standard Deviations', inline='03')
col_up15 = input.color(color.new(#32bf8f, 0), 'Up', group='Candles Greater Than ... Standard Deviations', inline='03')
col_dn15 = input.color(color.new(#ff2d70, 0), 'Down', group='Candles Greater Than ... Standard Deviations', inline='03')
transpsd = input.int(title='Transparency', defval=0, minval=0, maxval=100, group='Candles Greater Than ... Standard Deviations', inline='03')
twopointzero = input.float(title='', defval=2.0, step=0.01, group='Candles Greater Than ... Standard Deviations', inline='04')
col_up20 = input.color(color.new(#6bd673, 0), 'Up', group='Candles Greater Than ... Standard Deviations', inline='04')
col_dn20 = input.color(color.new(#ff0097, 0), 'Down', group='Candles Greater Than ... Standard Deviations', inline='04')
twopointfive = input.float(title='', defval=2.5, step=0.01, group='Candles Greater Than ... Standard Deviations', inline='05')
col_up25 = input.color(color.new(#b0e749, 0), 'Up', group='Candles Greater Than ... Standard Deviations', inline='05')
col_dn25 = input.color(color.new(#ff00c8, 0), 'Down', group='Candles Greater Than ... Standard Deviations', inline='05')
threepointzero = input.float(title='', defval=3.0, step=0.01, group='Candles Greater Than ... Standard Deviations', inline='06')
col_up30 = input.color(color.new(#fff000, 0), 'Up', group='Candles Greater Than ... Standard Deviations', inline='06')
col_dn30 = input.color(color.new(#ff00ff, 0), 'Down', group='Candles Greater Than ... Standard Deviations', inline='06')

//normal distribution
sd1_5 = ta.stdev(up ? fomoinp1 : dumpinp1, len) * onepointfive
sd2 = ta.stdev(up ? fomoinp1 : dumpinp1, len) * twopointzero
sd2_5 = ta.stdev(up ? fomoinp1 : dumpinp1, len) * twopointfive
sd3 = ta.stdev(up ? fomoinp1 : dumpinp1, len) * threepointzero

//logic

grad = if up and showcolors == true
    (fomoinp2 - fomoinp1) >= sd3 ? col_up30 : 
     (fomoinp2 - fomoinp1) >= sd2_5 ? col_up25 : 
     (fomoinp2 - fomoinp1) >= sd2 ? col_up20 : 
     (fomoinp2 - fomoinp1) >= sd1_5 ? col_up15 : col_upreg
else if down and showcolors == true
    (dumpinp1 - dumpinp2) >= sd3 ? col_dn30 : 
     (dumpinp1 - dumpinp2) >= sd2_5 ? col_dn25 : 
     (dumpinp1 - dumpinp2) >= sd2 ? col_dn20 : 
     (dumpinp1 - dumpinp2) >= sd1_5 ? col_dn15 : col_dnreg
else
    up ? col_upreg : col_dnreg
    
transp = if grad == col_upreg
    transpreg
else if grad == col_dnreg
    transpreg
else
    transpsd

barcolor(color.new(grad, transp), title="Standard Deviation Candles")

sigma3up = if up
    (fomoinp2 - fomoinp1) >= sd3 ? true : false
else
    false
sigma25up = if up
    (fomoinp2 - fomoinp1) >= sd2_5 ? true : false
else
    false
sigma2up = if up
    (fomoinp2 - fomoinp1) >= sd2 ? true : false
else
    false
sigma15up = if up
    (fomoinp2 - fomoinp1) >= sd1_5 ? true : false
else
    false

sigma3down = if down
    (fomoinp1 - dumpinp2) >= sd3 ? true : false
else
    false
sigma25down = if down
    (fomoinp1 - dumpinp2) >= sd2_5 ? true : false
else
    false
sigma2down = if down
    (fomoinp1 - dumpinp2) >= sd2 ? true : false
else
    false
sigma15down = if down
    (fomoinp1 - dumpinp2) >= sd1_5 ? true : false
else
    false

plotchar(sigma3up and showchars, "Sigma 3 UP", "🚀", location=location.belowbar, color=col_up30, size = size.auto)
plotchar(sigma25up and showchars and not sigma3up, "Sigma 2.5 UP", "✈️️", location=location.belowbar, color=col_up25, size = size.auto)
plotchar(sigma2up and showchars and not sigma3up and not sigma25up, "Sigma 2 UP", "🥂️", location=location.belowbar, color=col_up20, size = size.auto)
plotchar(sigma15up and showchars and not sigma3up and not sigma25up and not sigma2up, "Sigma 1.5 UP", "🟢", location=location.belowbar, color=col_up15, size = size.auto)
plotchar(sigma3down and showchars, "Sigma 3 down", "💀️", location=location.abovebar, color=col_dn30, size = size.auto)
plotchar(sigma25down and showchars and not sigma3down, "Sigma 2.5 down", "🐻️️", location=location.abovebar, color=col_dn25, size = size.auto)
plotchar(sigma2down and showchars and not sigma3down and not sigma25down, "Sigma 2 down", "💩️️", location=location.abovebar, color=col_dn20, size = size.auto)
plotchar(sigma15down and showchars and not sigma3down and not sigma25down and not sigma2down, "Sigma 1.5 down", "🔻", location=location.abovebar, color=col_dn15, size = size.auto)

alertcond = if up
    (fomoinp2 - fomoinp1) >= sd3 ? true : 
     (fomoinp2 - fomoinp1) >= sd2_5 ? true : 
     (fomoinp2 - fomoinp1) >= sd2 ? true : 
     (fomoinp2 - fomoinp1) >= sd1_5 ? true : false
else if down
    (dumpinp1 - dumpinp2) >= sd3 ? true : 
     (dumpinp1 - dumpinp2) >= sd2_5 ? true : 
     (dumpinp1 - dumpinp2) >= sd2 ? true : 
     (dumpinp1 - dumpinp2) >= sd1_5 ? true : false
else
    false

//Alerts
alertcondition(alertcond == true, 'Significant Price Move', 'Significant Price Move')