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?

8MqHyN3.png


Code:
#Freedom of Movement

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);
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:
@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] - 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
 
Last edited:
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
 
@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] - 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
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!
 
@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] - 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[1];
def signalPrice = if bar == HighestAll(signalBar) then low else signalPrice[1];
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);
Alert(trigger, "CSA FoM RV StDev", Alert.BAR, Sound.RING);
# End CSA FoM and RV Std Dev Horizontal Line
 
@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] - 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[1];
def signalPrice = if bar == HighestAll(signalBar) then low else signalPrice[1];
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);
Alert(trigger, "CSA FoM RV StDev", Alert.BAR, Sound.RING);
# End CSA FoM and RV Std Dev Horizontal Line
@tomsk Thank you so much! I really appreciate all you do for this community.
 
@tomsk Would it be too much to ask if you can write a code that plots all prior triggers and displays them across the chart for the time frame that I am viewing? I understand that the chart will be cluttered but I think this is a very important indicator because it acts as a support and/or resistance line for future price action. Also, it would be nice to have the option to keep the lines on or turn them off. Thank you so much!
 
Suppose you wanted the last 3 Defended Price Lines across the FOM price...
Where you check to see that it is the latest time
Code:
def signalBar = if trigger then bar else signalBar[1];
def signalPrice = if bar == HighestAll(signalBar) then low else signalPrice[1];
plot hLine = if barNumber() >= HighestAll(signalBar) then signalPrice else Double.NaN;

You do not have a chance to check if this is the 2nd latest time a FoM has happened or a 3rd latest time a FoM has happened... unfortunately Thinkscript only allows us a 'Highest' all function. So how would you count the 2nd most recent and the 3rd most recent FoM you would want it to keep plotting???
Keep in mind counting the number of bars will really wear out computer resources...
@tomsk @HighBredCloud
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
242 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top