# Coding Help - FOM & RelVolStdDev #### blakecmathis

##### Well-known member
The lower is comprised of two studies: RelativeVolumeStDev and Freedom of Movement. However, only values above 2 standard deviations are plotted for both studies (bars for volume and wedges for freedom of movement). Ideally, I would like for the these to be absent from the chart and only shown when they overlap such as in the picture below and plotted as a boolean value. So if both signals are generated on the same candle, a simple wedge up would be plotted. And when they do not occur on the same candle, nothing is plotted. Is this possible? Code:
``````#Freedom of Movement

declare lower;
declare zerobase;

input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def mov = AbsValue(close / close - 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);
plot FoM = if rawFoM > numDev then rawFoM else Double.NaN;
plot StDevLevel = numDev;

FoM.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
FoM.SetLineWeight(3);
FoM.DefineColor("Above", GetColor(0));
FoM.DefineColor("Below", GetColor(2));
FoM.AssignValueColor(if FoM >= numDev then FoM.Color("Above") else FoM.Color("Below"));
StDevLevel.SetDefaultColor(GetColor(7));
StDevLevel.SetStyle(Curve.SHORT_DASH);

# End Code``````

Code:
``````#Relative Volume Std Dev

declare lower;
declare zerobase;

input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def rawRelVol = (volume - Average(volume, length)) / StDev(volume, length);
def RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);

plot StDevLevel = numDev;
plot RV = if RelVol > numDev then RelVol else Double.NaN;

RV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
RV.SetLineWeight(3);
RV.DefineColor("Above", GetColor(0));
RV.DefineColor("Below", GetColor(2));
RV.AssignValueColor(if RelVol >= numDev then RV.Color("Above") else RV.Color("Below"));
StDevLevel.SetDefaultColor(GetColor(7));
StDevLevel.SetStyle(Curve.SHORT_DASH);
# End Code``````

Last edited:
T

#### tomsk

##### Well-known member
VIP
@blakecmathis See if this resembles what you're looking for. I have combined both studies into one, and only if there is a confluence in both studies above 2 standard deviation would you get a signal. When that signal is triggered you'll see the label appear of that condition, as well as hear an audible alarm bell go off.

If this is really what you're looking for then you may even dispense on the lower boolean plot and just depend on the AddLabel and audible alarm. Just several ideas to play with.

Code:
``````# 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);
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);
# End CSA FoM and RV Std Dev``````

Last edited:
• J007RMC and BenTen #### blakecmathis

##### Well-known member
@tomsk Damn thats beautiful. Appreciate it brotha!!

T

#### tomsk

##### Well-known member
VIP
@tomsk Damn thats beautiful. Appreciate it brotha!!

K

#### kosnarf

##### New member
VIP
Both studies are available on the platform by default: RelativeVolumeStDev and FreedomOfMovement
I'm trying to find a way to combine this with the pivot array or fractals to plot high and lows

T

##### Member
2019 Donor
@blakecmathis See if this resembles what you're looking for. I have combined both studies into one, and only if there is a confluence in both studies above 2 standard deviation would you get a signal. When that signal is triggered you'll see the label appear of that condition, as well as hear an audible alarm bell go off.

If this is really what you're looking for then you may even dispense on the lower boolean plot and just depend on the AddLabel and audible alarm. Just several ideas to play with.

Code:
``````# 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);
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);
# End CSA FoM and RV Std Dev``````
I've been testing this and I really like it. But I'm wondering if you can make it automatically add a horizontal price line on the chart every time it triggers? Thanks!

T

#### tomsk

##### Well-known member
VIP
@TradeUp Here is version 1.1 of the code, it has been converted to an upper study to display a horizontal price line from the last trigger condition to the end of the chart. All prior trigger conditions will not be plotted to make the display cleaner, otherwise it would be too cluttered. Note that the previous study was a lower study that displays signals as requested by @blakecmathis (see post #2)

Code:
``````# CSA FoM and RV Std Dev Horizontal Line
# tomsk
# 1.20.2020

# V1.0 - 01.07.2020 - tomsk - Initial release CSA FoM and RV Std Dev (lower study)
# V1.1 - 01.20.2020 - tomsk - Converted to upper study to display a horizontal line at the last signal

# Freedom of Movement and Relative Volume Std Dev
# Original code: provided by blakecmathis

input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def bar = barNumber();
def mov = AbsValue(close / close - 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);

def trigger = rawFoM > numDev and RelVol > numDev;
def signalBar = if trigger then bar else signalBar;
def signalPrice = if bar == HighestAll(signalBar) then low else signalPrice;
plot hLine = if barNumber() >= HighestAll(signalBar) then signalPrice else Double.NaN;
hLine.SetPaintingStrategy(PaintingStrategy.LINE);
hLine.SetDefaultColor(Color.ORANGE);
hLine.SetLineWeight(5);

AddLabel(trigger, "CSA FoM RV StDev Triggered", Color.Yellow);
# End CSA FoM and RV Std Dev Horizontal Line``````

• blakecmathis and BenTen
T

##### Member
2019 Donor
@TradeUp Here is version 1.1 of the code, it has been converted to an upper study to display a horizontal price line from the last trigger condition to the end of the chart. All prior trigger conditions will not be plotted to make the display cleaner, otherwise it would be too cluttered. Note that the previous study was a lower study that displays signals as requested by @blakecmathis (see post #2)

Code:
``````# CSA FoM and RV Std Dev Horizontal Line
# tomsk
# 1.20.2020

# V1.0 - 01.07.2020 - tomsk - Initial release CSA FoM and RV Std Dev (lower study)
# V1.1 - 01.20.2020 - tomsk - Converted to upper study to display a horizontal line at the last signal

# Freedom of Movement and Relative Volume Std Dev
# Original code: provided by blakecmathis

input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;

def bar = barNumber();
def mov = AbsValue(close / close - 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);

def trigger = rawFoM > numDev and RelVol > numDev;
def signalBar = if trigger then bar else signalBar;
def signalPrice = if bar == HighestAll(signalBar) then low else signalPrice;
plot hLine = if barNumber() >= HighestAll(signalBar) then signalPrice else Double.NaN;
hLine.SetPaintingStrategy(PaintingStrategy.LINE);
hLine.SetDefaultColor(Color.ORANGE);
hLine.SetLineWeight(5);

AddLabel(trigger, "CSA FoM RV StDev Triggered", Color.Yellow);
# End CSA FoM and RV Std Dev Horizontal Line``````
@tomsk Thank you so much! I really appreciate all you do for this community.

H

#### HighBredCloud

##### Well-known member
VIP
Can this be made into a scan to indicate candles approaching both from above and below the yellow line within certain deviation from the yellow line?

T Help complete this FE and Hurst Exp. coding request? Questions 18