volatility for x bars back

stevemend0za

New member
VIP
I'm looking for indicator to give me volatility for x bars back. Highest open/close (which ever is higher) to Lowest open/close (which ever is lower). I would also like to have two percentages displayed like the photo. One including the first bar and the second skipping it. Please any help is greatly appreciated.
15958[/ATTACH]']
6tb1zha.png
 

Attachments

  • 6tb1zha.png
    6tb1zha.png
    58.2 KB · Views: 62
Last edited by a moderator:
Solution
Can you please make change. Thanks

Sure, this seems to work

Ruby:
input lookback = 4;
def hoc = Max(Highest(open, lookback), Highest(close, lookback));
def loc = Min(open, close);

def "vol_w/o" = AbsValue(hoc[1] - loc[1]) / loc[1];
AddLabel(1, "Volatility w/o 1st bar " + AsPercent("vol_w/o") , if "vol_w/o" * 100 > 5 then Color.GREEN else Color.RED);

def "vol_w" = AbsValue(hoc - loc) / loc;
AddLabel(1, "Volatility with 1st bar " + AsPercent("vol_w") , if "vol_w" * 100 > 5 then Color.GREEN else Color.RED);

input test = no;
AddLabel(test, " Highest w " + hoc + " Lowest w " + loc + " || Highest skipping " + hoc[1] + " Lowest skipping 1st " + loc[1]  , Color.WHITE);
I'm looking for indicator to give me volatility for x bars back. Highest open/close (which ever is higher) to Lowest open/close (which ever is lower). I would also like to have two percentages displayed like the photo. One including the first bar and the second skipping it. Please any help is greatly appreciated.
15961[/ATTACH]']
6tb1zha.png

See if this helps. Set lookback to how many bars you want Set test to yes to see the highest/lowest values used to gauge volatility.

Capture.jpg
Ruby:
input lookback = 4;
def hoc = Max(Highest(open, lookback), Highest(close, lookback));
def loc = Min(open, close);

def "vol_w/o" = AbsValue(hoc - loc[1]) / loc[1];
AddLabel(1, "Volatility w/o 1st bar " + AsPercent("vol_w/o") , if "vol_w/o" * 100 > 5 then Color.GREEN else Color.RED);

def "vol_w" = AbsValue(hoc - loc) / loc;
AddLabel(1, "Volatility with 1st bar " + AsPercent("vol_w") , if "vol_w" * 100 > 5 then Color.GREEN else Color.RED);

input test = no;
AddLabel(test, " Highest " + hoc + "Lowest " + loc + " Lowest skipping 1st " + loc[1]  , Color.WHITE);
 

Attachments

  • 6tb1zha.png
    6tb1zha.png
    58.2 KB · Views: 65
See if this helps. Set lookback to how many bars you want Set test to yes to see the highest/lowest values used to gauge volatility.
OMG you almost have it. YOU ARE A GENIUS SR. My fault for not explaining correctly. In the photo you will see that while skipping the first bar we are still looking back 4 bars. (Just scooting over but still counting 4) Would it be too much to ask to modify it, I thank you in advanced.

https%3A//i.imgur.com/2NezJMz.png[/img]']
2NezJMz.png
 
Can you please make change. Thanks

Sure, this seems to work

Ruby:
input lookback = 4;
def hoc = Max(Highest(open, lookback), Highest(close, lookback));
def loc = Min(open, close);

def "vol_w/o" = AbsValue(hoc[1] - loc[1]) / loc[1];
AddLabel(1, "Volatility w/o 1st bar " + AsPercent("vol_w/o") , if "vol_w/o" * 100 > 5 then Color.GREEN else Color.RED);

def "vol_w" = AbsValue(hoc - loc) / loc;
AddLabel(1, "Volatility with 1st bar " + AsPercent("vol_w") , if "vol_w" * 100 > 5 then Color.GREEN else Color.RED);

input test = no;
AddLabel(test, " Highest w " + hoc + " Lowest w " + loc + " || Highest skipping " + hoc[1] + " Lowest skipping 1st " + loc[1]  , Color.WHITE);
 
Solution
Sure, this seems to work
Sir, Thank you so much! I cannot thank you enough. THANK YOU !!!
By the way I made just a small adjustment to your script and worked just as I needed. Thank you and is forum. I will be joining VIP as it is the only way I can think of to show my appreciation. Thank you all.

input lookback = 4;
def hoc = Max(Highest(open, lookback), Highest(close, lookback));
def loc = Min(Lowest (open, lookback), Lowest (close, lookback));

def "vol_w/o" = AbsValue(hoc[1] - loc[1]) / loc[1];
AddLabel(1, "Volatility Mon-10am Wed " + AsPercent("vol_w/o") , if "vol_w/o" * 100 > 5 then Color.GREEN else Color.RED);

def "vol_w" = AbsValue(hoc - loc) / loc;
AddLabel(1, "Volatility Wed 10am-Friday " + AsPercent("vol_w") , if "vol_w" * 100 > 5 then Color.GREEN else Color.RED);

input test = no;
AddLabel(test, " Highest w " + hoc + " Lowest w " + loc + " || Highest skipping " + hoc[1] + " Lowest skipping 1st " + loc[1] , Color.WHITE);
 
The following is a script that gives me the volatility based on highest and lowest close regardless of candle color. works perfect. I would like to have it work on my watchlist but instead of displaying the percentages I need it to be green if above 5 percent.

input lookback = 4;
def hoc = Max(Highest(open, lookback), Highest(close, lookback));
def loc = Min(Lowest (open, lookback), Lowest (close, lookback));

def "vol_w/o" = AbsValue(hoc[1] - loc[1]) / loc[1];
AddLabel(1, "Volatility 6:30-10am " + AsPercent("vol_w/o") , if "vol_w/o" * 100 > 5 then Color.GREEN else Color.RED);

def "vol_w" = AbsValue(hoc - loc) / loc;
AddLabel(1, "Volatility 10am-1pm " + AsPercent("vol_w") , if "vol_w" * 100 > 5 then Color.GREEN else Color.RED);

input test = no;
AddLabel(test, " Highest w " + hoc + " Lowest w " + loc + " || Highest skipping " + hoc[1] + " Lowest skipping 1st " + loc[1] , Color.WHITE);
 
The following is a script that gives me the volatility based on highest and lowest close regardless of candle color. works perfect. I would like to have it work on my watchlist but instead of displaying the percentages I need it to be green if above 5 percent.

input lookback = 4;
def hoc = Max(Highest(open, lookback), Highest(close, lookback));
def loc = Min(Lowest (open, lookback), Lowest (close, lookback));

def "vol_w/o" = AbsValue(hoc[1] - loc[1]) / loc[1];
AddLabel(1, "Volatility 6:30-10am " + AsPercent("vol_w/o") , if "vol_w/o" * 100 > 5 then Color.GREEN else Color.RED);

def "vol_w" = AbsValue(hoc - loc) / loc;
AddLabel(1, "Volatility 10am-1pm " + AsPercent("vol_w") , if "vol_w" * 100 > 5 then Color.GREEN else Color.RED);

input test = no;
AddLabel(test, " Highest w " + hoc + " Lowest w " + loc + " || Highest skipping " + hoc[1] + " Lowest skipping 1st " + loc[1] , Color.WHITE);

Create 2 custom scripts using. Rename the columns to your liking
Screenshot 2023-08-09 161000.png

Screenshot 2023-08-09 160831.png

Screenshot 2023-08-09 161142.png
 

Attachments

  • Screenshot 2023-08-09 153835.png
    Screenshot 2023-08-09 153835.png
    53.9 KB · Views: 62

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
522 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