Need indicator Highest open or close to Lowest open or close

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.
 
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);

SleepyZ

Well-known member
VIP
Lifetime
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.

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);
 

stevemend0za

New member
VIP
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.

 

SleepyZ

Well-known member
VIP
Lifetime
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

stevemend0za

New member
VIP
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);
 

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.
Top