TradingView Pine Script Tutorial 7 – Resolutions / Timeframes / Periods

TradingView Pine Script Tutorial 7 – Resolutions / Timeframes / Periods

YouTube Video

YouTube Video Transcript

[Music] hey this is David for big bits and in this video we’re gonna go over our seventh script and our pine script tutorial for tradingview development and in this video we are actually going to discuss different resolutions and this isn’t you know like a new year’s resolution and tradingview we are talking about a resolution as far as what we are looking at kind of like the display resolution on a monitor so in trading view terms this is usually what time frame you’re looking at this is what they refer to as a resolution in their documentation so you can see the different resolutions available some of these are only available to pro accounts or premium accounts so be mindful of that but what we’re going to do in this video is we’re actually going to set our moving averages that we’ve been working on to be able to be calculated based off of a different resolution and by that I mean well let me just show you so in the chart here we have three lines we have a green a yellow and a red now in the past by default these have been the 50 period the 100 and the 200 now decided to do it a little bit different since we’ve added resolutions we’re looking at a 4-hour chart the green line here is a 50 period let me pull up these settings to make a little bit more clear this is a 50 period using the current resolution which is the 4 out now the yellow line it is actually the 200-day moving average you can see we set the period to 200 and the resolution to 1 day now I’m going to explain how this works in just a moment but you can also see the 100 week moving average is the red line here as well because we changed the resolution to 1 week now why is this important well just look at this chart you can see where it can be helpful to look at different resolution on a single chart so if you’re looking at trading on a four-hour chart it’s probably a good idea to be mindful of daily and weekly trends I guess just a general bit of a helpful hint I suppose is that when you’re trading smaller timeframes like 5 minutes 15 minutes it’s I think in my opinion a very good idea to look towards larger timeframes for the overall trend that you were working in otherwise if the daily were to dump and you were thinking that the 15-minute candle looks really good and it’s gonna go up so you bought it well the daily trend is fighting against you and it’s a much larger trend than anything you can find on 15 minutes so that’s definitely not real financial advice it’s just something I’ve seen from experience ok so just keep that in mind and you can see on this chart we’re looking at a 50-day moving average going down which if you look recently this looks like it’s been acting as resistance okay now I have made some livestream videos here and I’ve talked about the Bitcoin price and I mentioned the 200-day moving average and I said once we first broke out of this consolidation I was looking for a target of the 200-day moving average because typically in the past it has held as support in various occasions and it did it held as support even though the price did wick below it held a support for some time then once it was broken it acted as resistance and that happens fairly often in trading is when you have a support get broken becomes resistance now that’s what we’re trying to use these moving averages to determine I can’t tell you how to do that that’s entirely up to you but just looking at this chart it looks like there’s a pretty good pattern there that could show you where support resistance may be and then of course finally there’s also this 100 week moving average which it touched once with the wicks and then again later on and bounced off of it so it appears based on this chart that the price is pretty much stuck between support and resistance and it’s likely in a range so that’s how I would use this indicator but you’re more than welcome to use it however you want it’s always important in my mind to keep these larger timeframes like the daily in mind like I’ve mentioned because they are much more important in the grand scheme of things than you know the 15-minute like I mentioned so let’s continue into the code now you’ve seen what you’re getting out of this now you well there’s one more thing I forgot to mention the forecast and you notice there’s no forecasting on the different resolutions this is due to the way the forecasting works and the way it’s plotted on the chart and I’ll probably explain that a little bit better but when you change the resolution from anything other than the current resolution it’s it’s not gonna show up and I’ll explain that later but there’s a very good reason for it now let’s get into the code really everything is the same going down and tool finally when we want to actually calculate our moving averages things are a little bit different and one of the things I had to do for this was I had to create a function to help us determine what resolution were working with now you’ll notice on the inputs that we had that the resolution dropped down had these numbers and then the resolution that you’re actually wanting to work with the reason I did this was because if we just listed these all like this they would be completely out of order from what you would expect okay and we couldn’t have had the current on there if we just used the built-in resolution type now a lot of charts there are a lot of indicators I should say that I’ve seen that had the ability for you to select the custom resolution seem to have been based on the idea that you would use the resolution enumerator that’s built into Pyne script as the input option or the input type well I’m actually using a string that way we don’t have to have a checkbox if you want to use the current and then also have a drop-down for all the other options I think it’s a little bit cleaner and a little bit friendlier for the user only have the one drop-down and just have a default of current form so how do we actually accomplish getting the correct resolution out of this like I said we have a function and we pass in our resolution I’ll get into the rest of this in just a moment but the resolution codes first let’s go over that to determine what resolution is all you do is you call the resolution function and you pass in whatever the moving average resolution was that was selected from that drop-down since it’s a stream we’re gonna have to compare it to what we would expect so well let’s go back up here one more thing that’s slightly different we had to add the options and the input for the resolution I said everything was the same my bad it wasn’t we actually added an input for the resolution on these and we had to have these specific options declared otherwise you could have set the type to input resolution I believe and this is why I said we went this way so we wouldn’t have to have a checkbox and make it use the current okay back to where we were we have the default value set here and we’ve passed whatever they’ve selected in as their input into the resolution function here and it’s gonna go through and check each condition that we’ve identified and if it has current it’s gonna use this contextual information and contextual or metadata however you want to call it this is just information about the chart that we’re looking at and this is the period of the time frame for the chart and it’s kind of confusing they use the word resolution they use the word period other people just say time frame so there’s there’s several different words and you’re really just talking about the candle length so just keep that in mind and then we got a return appropriate values anything under one day is measuring in minutes you can see one minute is just one but once you get up to one hour the value that it’s expecting back is 60 because it’s in minutes and then four hours of sooner than 40 once you get the days you have to have the one and the capital D and it’ll know that that is the one day resolution and so forth with weeks and months okay so let’s get back into the actual moving average calculations and in order for us to do based on a potentially different resolution we have to use what’s called the security function here and this is going to use information we pass in to calculate the moving average on that particular security and the reason we would do that is because if it is on a different resolution it might not be the one that we’re looking at on the chart so some more contextual or metadata information about this particular chart is the tikar ID now it’s usually this information up here for us we’re not looking at any other type of security we’re only focused on the data in the chart so say for example you actually wanted to change what chart you wanted the moving average from say not only did you want to set the resolution to one week but maybe you wanted the one week or the 50 week I should say moving average on gold if you knew the ticker ID for gold you could pass it in as security and give it the appropriate resolution and MA information and it would calculate the 50 week for gold and put it on your Bitcoin chart I mean they already have ways to do that using the compare feature but this is another way that you could do that although the compare I think uses the same resolution so this way would allow you to look at different resolutions on different securities now I haven’t tried that so I can’t say for sure that works maybe we’ll try that in the future here but that’s what I would expect this to work and we can look at the information on security you can see how that is expected to work here and close that all right so yeah you can see how this is expected to work get all the information about it and I’ll just tell you there’s a lot here and it’s not really that hard what we’re dealing with with our script is the moving average mostly this is probably the most confusing part but when we call the security function I’ve already told you about the taker ID I’ve already tell about the resolution now we also have to tell it to calculate our moving average based on that moving average information we’ve already done this in the previous video so we don’t have to rewrite this you just have to know that in order to return the value for the moving average of that security you have to put that expression here in order to calculate that now that might be a little bit confusing at first but the code works so you can see for yourself all right let’s see what else we had here I know there was a couple of other things oh I did want to discuss the forecasting that was the other thing that was really important we talked about the forecasting in the last video but it’s as I told you earlier in this video this is not available when you change the resolution and the reason I did this was because and if you’ve watched the last video you’ll understand this a lot better so if if you don’t know what I’m talking about with forecasting and how that works please go back to the last video and watch that because it’ll explain this way better than I’m gonna do right now but essentially when we’re forecasting these values out ahead we’re always calculating the next value out on the current chart so it’s very easy for us to calculate the forecasted value of the next daily moving average but the issue is we’re on the 4-hour chart so we would have to determine exactly how many spots on the x-axis we would need to offset that value now by default we just do the 1 because we’re only looking at the current chart but the flexibility of this particular indicator makes it a little difficult we would have to do some sort of calculation to determine how many offsets it would take and even then if you’re looking at smaller resolutions say for example you wanted the 5 minute the 5 minute moving average on the 4-hour chart how are we supposed to do that there’s many many sets of 5 minutes within 4 hours you can’t display that on the x-axis here appropriately so that’s why they’re not on there it’s pretty straightforward actually but it’ll make a lot more sense if you’re having a hard time following me now if you’ve watched the previous video like I said it makes perfect sense to me because I’m the one who wrote it but if you don’t understand watch the last video it’ll probably make a lot more sense once you understand how the forecasting works in general but you know I think that’s it for this video we’ve got pretty much everything covered with the forecasting now if you want to see this indicator go in a different direction and you want to see more features added please leave a comment let me know you can always check out my trading view profile and see all the different scripts that I’ve published I recently published a smooth dar si script and if you’re looking at this the pictures may be different because the code can change we can add and remove features over time to make these indicators even better or to remove features that weren’t necessary whatever it takes leave your feedback you can leave it on YouTube in the comments or you can leave it on tradingview when you reply back to these particular scripts and also post ideas here as well I’ve been busy working on the scripts I haven’t had a lot of ideas posted on training you but we’ll get there we’re we’re building up building more content and we’re working on this series so that is it for now thank you very much for watching if you liked the video please leave a like on the video of course subscribe if you have liked this video as well because I’m gonna be doing a lot of videos related to this same sort of information usually some sort of trading related development and most of the trading is related to crypto of course so please subscribe if you haven’t already thank you and have a good day and hopefully I’ll see you in the next one [Music]