Python: Average True Range (ATR) 1 Mathematics and Stock Indicators
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: Python for Data
View skill →Related Reads
📰
📰
📰
📰
I Tested an AI Slop Detector — It Flagged My Own Writing
Dev.to AI
The Ultimate Guide to Crafting a Winning Resume with AI
Dev.to · vicente san silvestre chacon
Google Veo3 Public Release 2026: The Creator's Secret Weapon
Dev.to AI
Stop Paying for SaaS - Build Free AI Stack
Dev.to · Swastik Mishra
🎓
Tutor Explanation
DeepCamp AI