Supertrend Part 1 - Average True Range

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone welcome back to another video today i'm going to be having a little wine here and building a new trading bot so um i have this lyric pinot noir it's from santa barbara from 2018 good year right um yeah so not not a sponsored video or anything i don't have the wine sponsors yet but you know it just happens to be what i'm drinking so today i'm going to be talking about super trend what is it i don't know yet some people in the last video uh i asked uh what people want to see and they said super trend so yeah i want to see what it is what's it about can we build a trading bot uh using this i'm just going to learn it as i go with you and share it with you maybe some other people are already familiar with all of this pine script down below but i am not um i'm gonna try to write this in python and i'm going to use a this library called ccxt to place buy and sell orders i'll either use my binance account or my coinbase account to buy and sell some stuff i demoed this in the last video we showed how to buy and sell we showed how to fetch some historical data uh the last 15 5-minute candles for instance we showed how to get some quotes um and a variety of things that you can do using this library that supports connecting to multiple exchanges i'm going to connect this to a schedule um so that we can retrieve data you know periodically to check for new price data and then we're going to try to write the python code to apply this uh super trend a strategy here or indicator to that um and see if we can generate some buy and sell signals and trade based upon this thing um like i said um i am unfamiliar with this and you know i'm just gonna study it and show what i do as i go you can see there's a picture of uh pivot point here there's a couple of versions of it i looked it up uh so it says super trend this one has super trend with ema this has pivot point super trend and it looks like there's a variety of like flavors of this of combining it with multiple indicators and tweaking the settings uh certain ways to produce a certain outcome so maybe some people found flaws with it uh when it's used on its own uh but combined with other things maybe it's more powerful uh yeah let's let's figure it out um so you see i have a picture here um obviously when you look at the picture right all these pictures look real pretty you know obviously it tells you exactly when to buy right here and then a nice up trend starts and you sell it right at the top you make lots of money and then you sell and then you know you buy again and and you just keep making money every time it always wins right um yeah let's see is that really the case i don't know we're gonna try it so yeah i'm gonna try to break this down um at least one version of it this one looks a little bit simpler so i might just do this one but one common component of super trend if i look at it is uh the average two range it also looks like there's an atr factor here so some multiple of this atr value um so yeah let's talk about that first so um i don't want it to be a super long hour long video so let's just talk about uh this piece of it first so let's look at the atr since it it's a component of any variety of this super trend indicator so if you go to investopedia great wealth of knowledge about everything describes what it is right it's by mr wells wilder who obviously created a lot of indicators like i think adx and rsi and a variety of these indicators that people use he made average true range as well and it's described by this formula here which is either very simple looking to you or if you didn't do a lot of math maybe it looks really complicated but i want to break this down and talk about what this is and we'll actually get some real-time data here so we'll look at this data coming in for a coin like ethereum and let's calculate the atr on paper you know i do the the ipad thing so yeah let's just write it out real quick like we're in school make sure we understand it really well before we use some type of library to calculate this because i want to make sure i really understand the script right so let's talk about the atr portion first what it is how to calculate it we'll do it on paper we'll apply it to some actual data make sure it's correct and then we'll use a library to do it so i'm going to try out this technical analysis library in python which is different from ta lib i've tried a variety of ta indicator libraries on here including talib backtraders uh technical analysis library and tulip indicators and let's throw one more into the mix and figure out which one we like this one looks kind of kind of nice actually it looks a little bit more pythonic and modern than something like ta lib uh and the yeah so that's one reason i'm gonna try this out talib you know some people have trouble installing it on windows this one might just install really cleanly and easily um just as a plain uh python package whereas tl ta lib isn't as pythonic because you can tell it's like i believe it's built as a wrapper around like a c library so um this seems like it's written from scratch and pure python maybe we won't have all these issues where we have to like compile it and install it in weird ways we can just use a regular pip install so yeah some people might like this version and it also has a nice you know set of classes here like while it's it's divided into uh multiple uh classes here so there's volatility momentum volume and trend indicators so under volatility indicators right you see it has average true range built in already and so uh we're going to understand it first from scratch and then we'll just show how to use this technical analysis library in python to to do it and then once you're comfortable with this then you can tweak and use other parts of this library if you want so perhaps you want to combine volatility with with something else right with a trend volatility with trend or something like that or volume so yeah let's talk about how to use this library and then once we know how to use this library we can uh use a schedule to pull in data from one of these exchanges and and then from that data we should be able to apply a strategy using this library and our understanding of this algorithm and then based on that we'll be able to detect buy and sell signals and trigger those and at that point we'll uh fire the python code from ccxt the cryptocurrency exchange trading library that we discussed uh in the last video and we'll use that to create uh buy and sell orders on binance or coinbase or whatever crypto exchange you use so uh let's go ahead and get started with talking about average true range so atr or average true range it is a measure of market volatility so um whatever we're trading whether it's a stock or a cryptocurrency or the lean hogs or whatever it is you trade how much how volatile is that instrument how much is the price uh moving around is it rapidly going up and down can it fall twenty percent of the day thirty percent of the day you know bitcoins pretty volatile or you know does it not move around very much like a t stock it's still about the same price it was 20 years ago so it's not going to gap up you know 60 or something in a day it's not very volatile so a lot of momentum and growth stocks are very volatile as you've seen over the past month or so right in february you saw those growth stocks move very fast move down just as fast as they moved up so how do we measure this volatility one tool we can use is the average true range a lot of people use this atr if you watch the full stack trading app tutorial there was a point where we set a trailing stop it's very common to use this indicator atr to help you set a trailing stop so if you're trading this super volatile stock or cryptocurrency that moves around a lot right if you try to set some super tight stop on a volatile stock like that then you're gonna get stopped out like super easily right uh if you set like one percent behind but it's a stock that goes up or down a few percent uh on any given day so some people use this average true range to measure how volatile stock is and use some multiple like 1.5 atr twice the atr to determine uh you know to move at the stop a little bit further out to allow for its uh the instrument's normal volatility okay so how do you calculate this so uh first use the true range indicator and then you take the average of that right and so the true range here is taken as the greatest of the falling the current high minus the current low the absolute value of the current high minus the previous close or the absolute value of the current low minus the previous close okay um so that's described in this formula here which you know might look complicated but it's not very complicated at all and so uh yeah let's let's look at that so uh the first is you want the true range which is the maximum of any one of these values and so if i look at this chart for ethereum for instance and i zoom in on a certain candle here so this is the five minute time frame from ethereum usdt here and so i'm on trading view and so let's look at um let's see where it gets more volatile and it's less well so you see where you know it's relatively flat here and you see these candles are very small you know it's not moving around a lot so you see here i have the atr added to the chart and so you can see that the volatility is trending down the longer it stays in this very narrow range but at a certain point right you see these candles get larger and it moves down really quickly and you see the volatility uh is picking up so the atr is trending upward here so when it's moving up and it's trending you see this atr value is moving up right and then you'll see gradually these candles get smaller and smaller and you see it gradually flattens out here and so you see the volatility gets lower and lower as it as it trades in this range again and then eventually you know it falls down really quickly and the volatility goes back up so if as we discuss in the ttm squeeze video um you'll see things go from a period of relatively low volatility like like this here to a period of higher volatility where it's moving up and down a lot and you see these very long candles here so there's a large difference between the low and the high so let's focus on this peak over here so let's say uh 21 15 at april 5th at 2115 so you can see this at the at the bottom here so um you can see the open high low close of this particular candle here and so if you look in the top left there you see the high was 2148.50 and the low was 2131.88 so you can see it's you know it's this range here is around 17 uh 17 and then you can see this range here is uh the high is 2147 and the low is 21.35 so it's about 12 right and so let's see if we can go ahead and calculate what uh the average true range is um from scratch and um instead of atr 14 i'm going to use a smaller amount so i don't want to calculate that many values so let's do five and you see there's another setting here so there's different types of moving averages that can be used to make the most recent candle have more weight so that would be if you're using the exponential moving average but i'm just going to use the simple moving average so the 5 period atr here and yeah so let's go ahead and calculate that and let's see if we can derive one of these values to make sure that we understand it so um 21 15 here at 2115 you see the atr 5 is 1347. so um let's see where that comes from what that roughly means is that for the five previous candles here um the true range the average true range is 1347 right so let's so let's go ahead and calculate this out so i'm going to write it down here just to make sure i'm going to really draw this out to make sure to understand it if you already know this stuff feel free to skip ahead so what we have is april 5th at 21 15. so i'll just make a little uh table here with some columns and then we'll write this out so there's going to be at a certain time and these are five-minute intervals so i'm going to say let's calculate what the five-period atr is so uh 2115 2110 21 05 21 000. and then 20 55 and 20 50. we need one more a previous close so uh we're looking back so this would be like our current uh candle and so if our current candle was uh this one here you'll see in the top left i have a high value and we're gonna have a low and we're gonna have a previous close value okay right and then we'll have you know whatever the max is okay so the high here i have 21 48 50. the low here i have is 21 31 88 and then if i go back one candle to the previous close it looks like it's uh 2142 42 95 right so now that we have these values here we need to calculate the true range of this particular um timestamp this particular five-minute candle and so according to our formula here we want whatever is either the maximum of the high minus the low so the high minus the low here or the high minus the previous close or the low minus the previous close so one of these differences is going to be the maximum right and so which one's the furthest apart it looks like it's the high minus the low because the high the high and the previous close here the high and the previous close here or you know that's like 550 or so but the high minus the low here is what is this 16 1662 so the maximum difference is actually 1662 because the high minus the low is a 1662 okay and so we just need to fill this out for each candle so we can go back one more right so if i go back one more on my chart here so i'm going to go back to my ethereum i'm going to go to 2110 you see our high here is 2151. so i'll write 21.51 right 2151.00 and then the lowest 21.42 21.42. and the close the previous close if i go back one more candle is 21 46 55. so 21 46 55 okay and which one's the greatest difference here it looks like again it's the high minus the low here and the high minus the low here is what is that 8 54. so 854 is the max right and i'll do one more just for completion and then i'll fast forward and edit this out so uh 2105 if i go across at 2105 here looks like i got a high of 21 47 70. so 21 47 70. i got a low of 21 35 40. so 21 35 40. and then my previous close here is 21 35 21 so 21 35 a 21 okay and then the max at this case you'll see that the previous close is a little bit further from the high than the low so in this case this is the max and then if you subtract those out you get 1249. okay so 1249 right and then i'm going to fill in the rest of these real fast and forward it and so now that i have these five true range values these five maximum differences according to this formula i just need the average to those so these that's just true range number one two three four five and all this is is adding you know everyone knows how to take an average this is a summation right the summation just means add all these true ranges and then divide by the number of there are so you're just adding these five numbers and dividing by five right and so if i add all those together that total comes to 67 36 and we're dividing by five so if i divide 67 67 36 divided by 5. we get 13 13 47 is my atr 5. okay so that's my number and if i verify that i can should be able to verify that on my chart if i go to 21 15 and i look there at the bottom panel there and uh on the left side it says atr 5 sma is 1347. so that's your average true range and that's where it comes comes from and that should make intuitive sense right because you know it's just the average amount of movement so um you see the app for the last five bars we're moving around about a 13 dollars in range there and then if you go over here later on you'll see the atr goes down to six right so we're moving about an average of 13 but then we go over here it's only an average of six and then that volatility goes way down and then you see the volatility will eventually go back up and then if you go to over here for instance the atr is 16.37 so that's more volatile period and so that's how you calculate the atr by hand and i think i'm going to stop it there and get to the actual library to calculate this i just wanted to do a long drawn out manual calculation to begin to get our juices flowing and understand this and in the next video i'll download some newer data and use this python library to show you how to use a variety of indicators including the atr and we'll continue our discussion of supertrend so thanks a lot for watching and stay tuned for the next one and we'll keep going
Info
Channel: Part Time Larry
Views: 14,771
Rating: undefined out of 5
Keywords: supertrend, atr, average true range, technical analysis, trading bots, indicators, ccxt trading bot, crypto bot, volatility, python
Id: r0Zfj0oa9OA
Channel Id: undefined
Length: 19min 44sec (1184 seconds)
Published: Wed Apr 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.