Normal Distribution Outliers for volume (NDO indicator)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © spiritualhealer117

//@version=5
indicator("NDO")
length = input(14, "Length")

use_sv = input.bool(false,"Use Short Volume")

bool overwriteSymbolInput = input.bool(false, "Other symbol", inline = "OS", group = "Short Volume")
string tickerInput = input.symbol("", "", inline = "OS", group = "Short Volume")

string symbolOnly = str.substring(tickerInput, str.pos(tickerInput, ":") + 1)
string userSymbol = overwriteSymbolInput ? symbolOnly : syminfo.ticker
string shortVolumeTicker = str.format("FINRA:{0}_SHORT_VOLUME", userSymbol)

[shortVolume, shortVolumeMa] = request.security(shortVolumeTicker, "D", [close, ta.sma(close, length)], ignore_invalid_symbol = true)

var string[] validPrefixes = array.from("BATS", "NASDAQ", "NYSE", "AMEX")

src = shortVolume 
moving_average = ta.ema(src,length)
standard_deviation = ta.stdev(src,length)

src2 = volume
moving_average2 = ta.ema(src2,length)
standard_deviation2 = ta.stdev(src2, length)

standardized_volume = (src-moving_average)/standard_deviation
standardized_volume2 = (src2-moving_average2)/standard_deviation2
clor = standardized_volume > 3 ? color.green : standardized_volume > 2 ? color.yellow : standardized_volume >1 ? color.orange : color.red
color2=standardized_volume2 > 3 ? color.green : standardized_volume2 > 2 ? color.yellow : standardized_volume2 >1 ? color.orange : color.red

//Volume - short volume, if gap is massive then its a whale selling off or buying in, while short volume disagrees 
plot(use_sv?standardized_volume:standardized_volume2,color=use_sv?clor:color2, title="NDO",style=plot.style_columns)
hline(-1)
hline(0)
hline(1)
hline(2)
hline(3)


