plot Data = close;# CSA FoM and RV Std Dev
# tomsk
# 1.7.2020
# Freedom of Movement and Relative Volume Std Dev
# Original code: provided by blakecmathis
declare lower;
declare zerobase;
input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;
def mov = AbsValue(close / close[1] - 1);
def minMov = Lowest(mov, length);
def maxMov = Highest(mov, length);
def nMov = 1 + (mov - minMov) / (maxMov - minMov) * 9;
def vol = (volume - Average(volume, length)) / StDev(volume, length);
def minVol = Lowest(vol, length);
def maxVol = Highest(vol, length);
def nVol = 1 + (vol - minVol) / (maxVol - minVol) * 9;
def vByM = nVol / nMov;
def rawFoM = (vByM - Average(vByM, length)) / StDev(vByM, length);
#Relative Volume Std Dev
def rawRelVol = (volume - Average(volume, length)) / StDev(volume, length);
def RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
plot signal = rawFoM > numDev and RelVol > numDev;
AddLabel(signal, "CSA FoM RV StDev Triggered", Color.Yellow);
Alert(signal, "CSA FoM RV StDev", Alert.BAR, Sound.RING);
# End CSA FoM and RV Std Dev