Standard Deviation Lines

Jayhawk5

New member
I'm new to thinkScript and was hoping someone could help. I wanted to create an indicator that shows the first and second deviation level of the range of a stock (not SMA or EMA). By "range," I simply mean the [High] minus [Low] daily movement over X number of candles. I'll sacrifice not taking into account gap ups/downs in after hours so it's a little bit different than finding the standard deviation of ATR. Could anyone help?

For example, if...
Day1: High = 10, Low = 5, then range = 10-5=5
Day2: High = 8, Low = 4, then range = 8-4=4
Day3: High = 12, Low = 2, then range = 12-2=10
Day4: High = 9, Low = 7, then range = 9-7=2
Day5: High = 7, Low = 1, then range = 7-1=6

The Standard Deviation of 5, 4, 10, 2, and 6 is 2.653. So, if on Day6, the stock opened at 6, there would be a line at 8.653 and 3.347 for the first deviation, as well as a line at 11.306 and 0.694 for the second deviation. My strategy is to buy options for a reversal after the price has reached the second deviation. In the previous example, I'd buy a call at 0.694 or a put at 11.306. Please help!
 
Solution
Try this to start off with, will probably have to tweak it a bit

Ruby:
input length = 10;

plot StDevDay = StDev(high(period = AggregationPeriod.DAY)[1]-low(period = AggregationPeriod.DAY)[1], length);

Plot SD1 = open(period = AggregationPeriod.DAY) + StDevDay;
Plot SD2 = open(period = AggregationPeriod.DAY) - StDevDay;

Plot SD3 = open(period = AggregationPeriod.DAY) + (2*StDevDay);
Plot SD4 = open(period = AggregationPeriod.DAY) - (2*StDevDay);
Try this to start off with, will probably have to tweak it a bit

Ruby:
input length = 10;

plot StDevDay = StDev(high(period = AggregationPeriod.DAY)[1]-low(period = AggregationPeriod.DAY)[1], length);

Plot SD1 = open(period = AggregationPeriod.DAY) + StDevDay;
Plot SD2 = open(period = AggregationPeriod.DAY) - StDevDay;

Plot SD3 = open(period = AggregationPeriod.DAY) + (2*StDevDay);
Plot SD4 = open(period = AggregationPeriod.DAY) - (2*StDevDay);
 
Solution

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