TradingView Pine Script Tutorial 23 – Detecting Lows and Highs of Any Value with RSI Strategy

TradingView Pine Script Tutorial 23 – Detecting Lows and Highs of Any Value with RSI Strategy

YouTube Video

YouTube Video Transcript

[Music] hey this is David for big bits and in the last video we talked about our RSI strategy that I’m showing you here and in this video we are going to discuss using the lowest and the lowest bars function there is also the opposite version which is the highest and the highest bars function which basically what these do allow you to just with one line of code tell pine script to look back a certain amount of candles for the lowest value within that period so this doesn’t have to do with just price and in our example we’re actually going to use the RSI we’re gonna look back at the RSI we want to find the lowest RSI and we’re gonna want to require our lowest RSI to be below a certain value we’re going to attempt to find a bullish divergence by making sure that our price is currently lower in some aspect then the price of the lowest RSI and our price is still on a downtrend so essentially something similar to what you see here you see the RSI is kind of bottom here and we want to buy below at a certain point because usually that’s how you would find a bullish divergence against the RSI so we’re actually gonna go ahead and do this we’re gonna have a few new parameters or inputs I should say as they’re called on pine script here let me copy these over I did a lot of live coding in the last video and it went pretty long so we’re actually gonna just copy some stuff over from a more completed script this time we’re just gonna call this our buy below target and paste this in here it’s two parameters we’re gonna be looking to buy below the lowest low in the RSI – virgin look back target percentage and it sounds really kind of silly but it’ll make more sense in just a little bit and then there’s also the source we’re going to be looking back and we’re going to want copy this value from the Loess RSI and our look back so if we looked back with 30 candles here the lowest RSI is here we’ll want to grab the closing price or the low something like that from there and that’s what the source is here now going on we are also going to have to specify what that by below target is with a formula and we’re gonna do that down here next to our profit and loss and the reason we’re doing it down here is because this is going to be pretty much the exact same calculation as what we’re doing here and let me go ahead and paste this in here it’s gonna look pretty overwhelming there’s a lot of variables going on here and we’re doing a lot of different things so our by below target what we’re gonna set it to be is we were going to use our by below target source which is the close and we’re going to look back using the lowest bars so I told you the lowest function looked back to give you the lowest value when you do a look back say we’re going to look back 50 or 100 candles whatever it is we are going to return the value that is the number of bars offset from the current candle so if we look back you know say this is 25 candles back the value it returns is going to be negative 25 so when we look at the close and we’re gonna be looking back at the RSI through this period it’s gonna return a negative number and so this is essentially the same thing as saying let’s look at the close at 25 but both of these are now variable and can change based on our inputs so for example if we change our source to a low it would be equivalent of doing something like this and if we were looking back you know a hundred periods maybe we had a lower RSI even back here so the value it returns would be like 88 but it actually returns a negative number so we multiply it by negative one to fix that so that’s what you’re seeing here we’re getting the the closing price of whatever the lowest RSI is in that look-back period so that’s a little bit confusing if you have a middle all the code but hopefully where I’ve done this it help makes a little bit more sense then what we’re doing is we’re going to subtract a percentage difference from that to create our by below target now let’s see what I had that set at by default here by below target percent zero now this is something that can kind of give you a little bit of buffer so if the value it plots is here and you wanted to buy when the price drop below that when the RSI was going down a certain amount in the trend you might want to give it a buffer so if you had it set to where it would plot here initially maybe you want to give it a little bit more room to drop and you would want to buy further down so this is just an example of how we do that and I’m actually going to plot that by below target and we’re actually gonna keep that on there going forward so that you can kind of see how that is and we can actually change how it’s going to look on the chart and let’s say what have I done the RSI diversion looks back okay so I forgot to add a couple more variables so we need the divergence look back and also the by below target I need to initialize that variable as well it looks like let’s see this would be with the RSI so this is the amount of candles we’re going to look back for the lowest RSI and let’s see the buy below target and I do apologize I’m copying this code from the other screen here up the reason that’s not working is because it’s in that same line so there isn’t actually anything wrong with the buy below target okay there we go so now you can see this line that it’s requiring the price to be below before it will buy but we haven’t actually done that as part of our conditions here in our is a buy now if you were following the last video you would know how we’ve set this up so we can track what conditions have to be met so we’re just going to add a new one in here and it’s going to be really simple we just have to have our buy below target source of the current candle which by default is going to be the current price through the clothes you can see that’s set by default to close and we’re gonna require our current price be below this blue line which is our current buy below target so let’s see if that makes any difference on this particular strategy here yeah so it took away a lot of all of the trades from here so we’re gonna be working on changing this to where hopefully we can find those things a little bit more going forward so I’ve shown you how the lowest bars work going backwards and there’s also one where we did the lowest so we also want to require that the RSI be below a certain number so we’re gonna look at a requirement for the RSI and we need the RSI within our look-back its lowest value has to be below a certain number so I mean this is probably a little bit confusing again but say we’re looking back on our candles and let me apologize I’ve probably had my head covering up a little bit of things let me hide that now we’re gonna be looking back in the candles for the lowest RSI value and what we’re gonna do is say the lowest RSI value is this one we actually want to require it to be below a certain number so if we’re looking back in our lowest RSI is you know still way up here like at 50 that might not be optimal especially when you’re looking for a bullish divergence so we want to require that it’s below 25 or 30 something like that the lowest value in our look-back period and then we can add that in there and once it meets that and the price is still below and all these other things then everything will come to work so let’s go and take a look here at how we’re doing this and this is actually quite simple you copy this condition over this is another condition on our is advised thing that we’re just copying some more stuff over we are going to use the lowest function I’ve already told you how this works and this is comparing the smooth SR I for some reason that’s I need to change that in my more completed script here but we are requiring that the RSI be below using its lowest value in that look-back period below what we have set with our input so if we set this to 30 it’s got to be below that in its lowest value going back so that’s pretty straightforward as well let me see if there were any else that I also needed to do we also needed to set another one this is for the smooth SR I it’s pretty much the same thing but once we have this one I think this is pretty much the same script that I had there might be a few things different now this is the same thing we basically just want to ensure that with our bullish divergence that our current smooth RSS RSS I excuse me the orange line here is above a certain value or below a certain value excuse me so we’re requiring that it has a downtrend of three in the default but if that downtrend is coming up around 50 then that might not be a good time to buy so we want to require that its downtrend of three occurs below a certain value so we’re gonna by default required that to be 35 let’s go down here and let me copy this I’m on the other screen right now looking for this here we go and there was also a RSI currently below as well so we’ll do that it’s the same concept as a smooth RSI and you can tell we’re getting a lot of conditions now you can see I’ve added in the smooth RSI and the RSI below a certain value and we have to add in that other RSI currently below parameter or input I should say and then I think we’re going to be done no it’s already on there currently below did I already have that on there yes my apologies I had just not added the one with the smooth s RI RSI excuse me a little off today so let’s save this and let’s see we had one issue where is this oh I had already added that in there we just didn’t have the know well we already did have the condition so yeah I’m Way off right now I thought that we hadn’t done that but we had I think the thing that really threw me off was on the lowest here it used the s RSI when it wasn’t supposed to so that completely threw me off on everything we’ve been doing since then okay you can see we still don’t have any trade so let’s try to change these numbers around to where we can get something about a five-minute chart here let’s see I’m going to use I’m trying to copy some of these from the other one here let me just copy some of these over from my default script I’ll actually just type them in here it’ll be a little bit easier I believe all right our artists at curves 14 currently below was 30 all right our divergence look-back period was 25 our RSI lowest divergent look-back period see which one is this one thing oh yeah that’s that one it was set to 25 as well in the completed script the s RSI curve is C where’s this one 10 the SRS I currently below I have is also 30 and then the minimum SR si downtrend is three as well say there’s there sitting here the SRS I currently below 35 so what if I say 34 here my apologies here that was the RSI currently below so I was looking at the wrong one let’s save this one and see if that makes any difference to the strategy to the strategy tester here okay so you can see it’s actually making some trades again so let’s take a look they were all profitable except for one we had 13 trades now I think before we had 11 or 12 so we’re actually doing pretty good let’s see if we can go back and find one of these trades so we can get an idea of how they’re occurring I think these two are really good examples of what we’re actually trying to accomplish and let me pull this up to where it’s much larger here for you so you can see within our look-back period we were looking for the lowest RSI value and we were setting our minimum buy target to a certain value here and we wanted the price to close below this line with a minimum s RSI downtrend of 3 below a certain value with the current RSI below a certain value and it kind of caught a bull divergence here you can see it bounce pretty well from there and the same thing here I’m actually pretty impressed that it actually caught this one because that’s an extended period of dips one after the other and it caught it pretty much right at the bottom so I’m really happy with how this is turning out right now this one I think caught it a little too soon obviously and it hit it stop-loss we have one here and you can kind of play around with the stop-loss and the take profit to maximize I think the settings I had I forgot to update these I used three and 1.75 let me see if that was actually any better or not go back to the performance summary no it wasn’t any better so yeah you can play around with these the settings that I have on this it might have been slightly better let me change it back again yeah so it was it was better so you can play around adjust these numbers up and down with the toggles here to try and find something that’ll result in more returns on the performance summary but that pretty much does it for this video I hope you’ve appreciated we’ve went over the lowest function and the lowest bars so just keep in mind that the same thing is true for the highest and the highest bars function and if you’re ever confused you can always just kind of hover over it in your pine script editor and hold down the control key and click that and it’ll take you to the updated pine script language reference manual within a modal pop-up on the screen so you don’t have to actually go to another page and it’ll kind of tell you what it’s actually doing but yeah I hope you appreciate this I’m gonna work on getting this and publishing it so everyone will have access to the code and you don’t have to try and copy and follow along with the video itself and you can actually play around with all the values yourself so keep an eye on my Twitter also my discord I’ll probably try and update on both of those places when these things are completed and published for everyone to see I really hope you all appreciate me doing that if you do please like the video please comment subscribe give me comments please on what else you would like to see I’ve had a few people make some suggestions there’s some really good stuff coming in I’ve got a lot of content planned the hard part is getting time to do it I’ve been working on a utility for myself that’s gonna automate a lot of things and I can’t wait to share this with you if you’ve been following my Twitter you’ve probably got a really good idea of what it is because I’ve been making some test posts with the utility I’m working on and it’s gonna be sharing a lot of information automatically and it’s gonna be pretty cool so definitely stay around on the channel to check out that video coming up soon because we’re gonna be sharing a lot of great stuff when that comes out but other than that I’ve already asked you to like and comment you can always also check out my tradingview profile if you like what we’ve been doing here and you can always check out the trading view profiles see some of the ideas I’ve posted I haven’t really posted a lot of ideas lately mostly because I’ve been so busy working on this utility and also the content for these videos so hopefully once we get that utility completed the ideas will be much easier to create and come back you can also check out the strips that we’ve already made and published here and we’re gonna try and get through this quickly there’s also the referral so if you’ve been following along and you wanted a paid subscription please use the referral link it’s in the description of the video that helps me a lot it also helps you as well you get $30 towards an upgraded plan once you pay for your first one and once you do that that really helps me because the premium subscription is pretty expensive so I appreciate you all watching definitely stay tuned there’s a lot of great stuff coming [Music]

YouTube Video Description

< br/> #bitcoin #crypto #cryptocurrencies #tradingview

Website: https://bigbits.io
Discord: https://discord.gg/rapMn4z
Twitter: https://twitter.com/BigBitsIO
Facebook: https://www.facebook.com/BigBitsIO/
GitHub: https://github.com/BigBitsIO
TradingView: https://www.tradingview.com/u/BigBitsIO

Referrals……
Trade on Coinbase: https://www.coinbase.com/join/johnso_dxz
TradingView: https://www.tradingview.com/gopro/?share_your_love=BigBitsIO
Brave Browser: https://brave.com/big406

DISCLAIMER: All my videos are for educational and entertainment purposes only. Nothing in this or any of my videos should be interpreted as financial advice or a recommendation to buy or sell any sort of security or investment including all types of crypto coins and tokens. Consult with a professional financial advisor before making any financial decisions. Investing in general and particularly with crypto trading especially is risky and has the potential for one to lose most or all of the initial investment. In simple terms, you are responsible for your actions when trading.