Python: Average True Range (ATR) 1 Mathematics and Stock Indicators

sentdex · Beginner ·🛠️ AI Tools & Apps ·12y ago

Key Takeaways

Introduces the Average True Range (ATR) indicator and its calculation in Python

Full Transcript

hello everybody and welcome back to a python mathematics and stock indicator tutorial video this video we're going to be discussing the average true range uh alphabetically actually we would be discussing the directional movement system but the directional movement system uses average true range within it so that's why we're kind of skipping over that one to average true range in the next next uh little miniseries will be the directional movement system so ATR what is it it's another one developed by Wells Wilder uh the idea of it is to measure volatility in a stock so it's not going to denote trending at all sometimes it might appear like it is but it is not so um the average in average true range just Den notes it's just true range with an average right so it's an exponential moving average of true range so what's true range true range is just the difference between the absolute lowest price and the absolute highest price uh within you know a one day time period so it's usually going to be today's high minus today's low but or that specific day's High minus that specific day's low but it can go all the way back to yesterday's closing price so if yesterday's closing price was really really high and then today's low is really really low uh and those are the Max and Min then that would be considered mostly since that's like a true full you know 24hour day uh of price and in some theories uh you would say that the price is still changing even while market is closed because people's opinions sentiment and all that is changing so true range is a measure of volatility but it's only a measure of the absolute highest price to the absolute lowest price so keep that in mind because um I would be one to argue that that's not a full definition of volatility really a def you know the true volatility would be you know as far as percent change how much uh like how much did that stock go or the whatever stock Forex uh ratio or whatever how much do that go up and down and up and down and up and down throughout the day right not necessarily you know just because it Rose a lot but what if you know in my opinion volatility is a lot of up and down uh but anyway that just you just have to kind of accept the fact that that's part of it now average true range I'm not the biggest fan of this but the directional movement system that uses true range is actually a pretty interesting indicator so I'll be interested to see what you guys think about that one so moving on just again the average true range is just simply an exponential moving average typically 14 of that true range uh but again one of the benefits to both knowing how to chart your own stocks and how to calculate this stuff is you can put whatever value in there you want if if you want to use a shorter you know like I was saying be in the beginning the idea of moving averages is to fit your needs exactly so you can smooth out a line to be either a very long-term kind of trend line or very short-term Trend and 14 is kind of a longer term trend for uh something like this one and I'll show you some examples of comparing 14 to maybe like a five right and and you'll see the the Stark difference um and also the the choosing of whether or not you even want to do an exponential moving average because again you might not want to do an exponential moving average you might want to do just a typical moving average and then even Wells Wilder himself had his own special you know Wells Wilder moving efforts so so you can kind of uh you can choose a lot of your own things once you learn how to do this stuff so it's definitely useful also if you're the one programming it that gives you a pretty good understanding of what's going on in the formula uh and then you can really truly make an educated decision on whether or not you want to buy into uh that indicator so now I'm just going to show you guys some examples of this uh average true range I'll just show you a couple different stocks uh the first one I want to do we'll do a 14 period um ATR of Exon and I'm just going to run that script here and this is what we'll end up coding at the end if you follow all the way through um so we'll plot xon it comes up a second grab it and here's our Exon chart and as you can see again this is a uh ATR oh let me fix that it's an ATR 14 period and here's a good example of where obviously you can you know volume is a pretty good measure of volatility as well I would almost say that of the of this stuff uh volume is the better measure and volume's like instant right you don't need you know U any moving average but anyway um and you can see how volume kind of correlates uh or really uh ATR correlates to volume uh anyway so like here would be like the one of the most volatile points on the chart as we can see it does show up here but it's quite late it doesn't show up until you know way over here right so it starts showing up really on uh December 21st and it Peaks at uh January 11th of 2009 when really the true action the true volatility was actually October 6ish to 10th so as you can see that's insanely late um and you know but you can see also that you know the as this line was slowly Rising as volatility was rising and then you see it reached its peak and then it kind of came down and sure enough you know price change in this area was a little bit um slower than price change up here so not to say that it doesn't work but again volume I think is a pretty good determin I mean you could put a moving average on volume or just leave it like this and you can visualize it just as good in my opinion um so now let me show you another example only this time like this one's using an atr1 14 we'll do an ATR 5 on the same stock let me close out of this and edit the value there so this one will be a five and we'll run it on X [Music] on so here's our Exxon chart and as you can see this one worked out a lot better uh with the I mean it's still a little bit late so again it is using a five period exponential moving average so let's just zoom in on this spot uh so you can see it kind just barely is missing it here but it's much better but then also if we zoom out we can see again it's almost perfectly matching volume so I know I keep saying it but I just think volume's probably one of your best bets or maybe a meshing of volume and price but um anyway so that's the basics of uh ATR and again it's just it's only to denote volatility as you can see I mean it's a it's doing its job at least uh and then we can we can begin to use this um to be a measure of volatility and it's actually you know considering that it doesn't use volume at all to measure volatility I would say it's actually a pretty interesting indicator of volatility because then you can mesh it with volume and you're using two totally separate data sets uh so it gives you a pretty good uh idea of what volatility is and and then when you mesh this with ATR for example just another case of of what makes it so useful to know how to not only chart but also program this stuff is you can change you know because this is just true range that and the point of true range is to measure volatility so since that's your goal you really could mesh this ATR with just simply um you know percent change or something of volume and you can really get a good measure of volatility so then when you go to add it to maybe the directional movement uh system uh you can make that system a better system so in the next video this is what we're going to be uh programming at least this line right here that's all we're really after uh we'll be programming that and then in some subsequent videos I'll show you how to add it into the chart like this um so you can see the same thing so anyways uh that's going to conclude this introductory video to average true range as always thanks for watching

Original Description

This video introduces the Average True Range indicator, which is used to measure volatility of a stock. The purpose of this series is to teach mathematics within python. To do this, we will be working with a bunch of the more popular stock indicators used with technical analysis. With most of the indicators, we will first discuss them, their purpose, then teach how to program them into python, then actually display them on a chart. The basic charting application comes from a previous tutorial series, here: http://www.youtube.com/playlist?list=PLQVvvaa0QuDcR-u9O8LyLR7URiKuW-XZq Required files: Sample Code for the actual charting parts: http://sentdex.com/sentiment-analysisbig-data-and-python-tutorials-algorithmic-trading/python-matplotlib-sample-code-charting-stocks-python/ Python: http://python.org Numpy: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy Matplotlib: http://matplotlib.org/downloads.html Sentdex.com Facebook.com/sentdex Twitter.com/sentdex
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

Related Reads

📰
I Tested an AI Slop Detector — It Flagged My Own Writing
Learn how an AI slop detector flagged a writer's own content, highlighting the importance of unique writing styles and the potential of AI tools in content evaluation
Dev.to AI
📰
The Ultimate Guide to Crafting a Winning Resume with AI
Learn how to leverage AI to create a winning resume with effective tips, strategies, and tools
Dev.to · vicente san silvestre chacon
📰
Google Veo3 Public Release 2026: The Creator's Secret Weapon
Learn about Google Veo3, a powerful tool for creators, and how to leverage its capabilities for enhanced productivity and innovation
Dev.to AI
📰
Stop Paying for SaaS - Build Free AI Stack
Learn how to build a free AI stack and save $200/month by replacing SaaS tools with open-source alternatives, and apply this knowledge to automate tasks and increase productivity.
Dev.to · Swastik Mishra
Up next
How to Use Jotform AI App Builder (Step-by-Step Tutorial)
Kevin Stratvert
Watch →