TradingView Pine Script Tutorial 14 – Plot Settings – Show Last & Offset

TradingView Pine Script Tutorial 14 – Plot Settings – Show Last & Offset

YouTube Video

YouTube Video Transcript

[Music] hey this is David for big bits in this video we’re gonna take a look at the plot function on trading view and specifically take a look at the show last property as well as the offset which is kind of out of view here let me take myself off the video and we’ll go ahead and get started here okay there we are now you can see we’ve added an offset here and I’ll explain exactly what this does but when you’re looking at the chart here you can tell we’re using a moving average this is a new indicator I’ve created it’s already published out on trading view you can go check that out in the library you should be able to go to the public library and search for fancy moving average there you go it’s one of the few ones out there it might not be registering in the public library just yet because I did just post it a few moments ago but that’s how this video is out it should be available to everyone there as you can see it is a published script here and you will have access to that as soon as it’s available in the library I probably just had need to index it at trading view but you can see this is a moving average and if you follow it along with video series before you’ll notice some other features such as the forecasting here at the end of it but you’ll notice something kind of new there’s one line but it’s got two different colors but instead of just changing colors when the price changes direction on the moving average say when it goes down you would have a red line and when it goes up you would have a green line which a lot of people do I wanted to do something a little bit different here and I wanted to highlight just the candles that are being shown of course they’re just being shown but I wanted to highlight just the candles that are being used in the calculation for the moving average so for example we have a 50 period simple moving average right now and if I change this to 75 you’ll notice it should go back to somewhere around and here I believe maybe further yeah so now the the green portion of the line goes back further because those are 75 candles back and that just shows the latest candles that are included in that calculation so that moving average calculation starts with the candle back here all the way to the current candle which could be pretty helpful and it helps you understand the forecasting as well so you can see when this candle leaves that’s why the forecast is going up it was a red candle that the price stays the same it gets replaced with a higher price here so it’ll go up that’s why the forecasting is in there just kind of give you an idea on this end but you can also get a better idea on the back end so you can even think out further ahead and the five that are given to you in the actual indicator now if you’ve been following along you probably want to know how that’s done if you don’t really care about how it’s done just go ahead and check out the trading view profile big bits out or you said it’s already out there now we’ve copied over all of our other functions for the resolution the moving average and also for the forecast and the bias now one thing you’ll notice we do different is we calculate one moving average but we have plotted up to two different moving averages now the way this works is we calculate our standard moving average which in this case is 75 period I want to move that back to 50 okay it’s a little bit easier to see when that line isn’t being covered up with candles but we have a 50 period moving average and the show last feature and let’s take a look at the documentation here the show last feature allows you to only plot or show the last however many bars or sections on the x-axis that you would like to go back under y set bars but yes it is points on the x-axis backwards that it would show when you choose show last and you see here the definition if set defines the number of bars so I guess bars was the right choice of words there from the last bar back to the pass to plot on the chart okay so you get the idea here hopefully that I can move out of the way all right so we’re plotting 50 back you can see if we have chosen chosen at our settings to highlight the inclusion and I’m just kind of calling this the inclusion period because these candles are included in the calculation we have the highlight inclusion selected if it is selected then it’s only going to show the last 50 candles which is our ma period now if we uncheck this it’s going to show set show last equal to zero and what that does is basically means it’s not a valid number and that you should show the entire history now also when it comes to that we also have the other line the shaded line I’m calling that the ghost trail and this should only show up when we are showing or highlighting this inclusion period and that’s because if we had it show up as well here then it would shade the green and it would still look like there was a trail on there you don’t need a trail when you’re not even showing the inclusion so what we’re gonna have to do here so we’re gonna have to add a couple settings so we have to add a button to show the inclusion goes trail and for that a toggle I should say or a checkbox and when you uncheck that you can only see what’s included in the candle calculation why you would want to do that not entirely sure but we gave that to you as a setting and you can see if you wanted to you can see the ghost trail which is the entire price history and a moving average that’s available so how do we do this one particular line so you can tell that we are only showing this green line for the last 50 candles so how do we show a line on the chart that goes back and actually stops right here because you can tell it doesn’t overlap with this green line because if it did it would be shaded in different color it wouldn’t be the lime green color that we set it to so we have to make sure that we only plot this line when we are showing or highlighting this inclusion so only when we are showing the candles included with the green line and when we have the show goes trail selected which is basically just show this line and to do that we are going to plot on the chart the moving average we’ve calculated but we’re gonna go back and we’re gonna look back 50 in this particular case the period is 50 so we want the moving average 50 periods ago minus one so it’d be 49 and that’s because it’s a zero based index it starts at zero if we want to actually go 50 back we need to go 49 back in the array that might not might not make sense if you’re not a somewhat experienced programmer but it’s a pretty basic topic in programming basically you start counting at zero so we need to go 49 back to get to the actual 50th moving average and if none of those are set it’s just not gonna show the line we’ve already discussed that and I’ve shown you that just a moment ago to get it to look like this I just set it to black and set the transparency to 10 now we’re also working with a new property here I’m sure we’ve used this in our videos yet for the offset let’s go back to the plot documentation offset it’s pretty easy to figure out it shifts the plot to the left or to the right on the given number of bars the default value is zero so the our green line here has a zero offset because it’s not been set and you can see it’s plotted on the most current line it’s not offset to the left or to the right and see this one is offset to the left now if we didn’t have the offset in this particular line the gray line would also end at the current candle because we would just be plotting the moving average of 50 candles back if we also don’t offset it backwards then it won’t show up correctly in the correct location so to do that we go back our 49 and we multiply that by negative one so that it offsets to the left if you have a positive value there it’s gonna offset to the right so we have to offset it back 49 to get it to do the correct line and I would have done 50 here because it’s not necessarily in an array and it’s not zero index based but what happened if you didn’t do that is that these lines would not connect because it would plot up to here and there would be a gap and it would be here so I left it at 49 on this one even though it’s not zero indexed just because I wanted them to line up and touch each other and that’s all there really is to that so that’s pretty much all there is to this particular video I wanted to highlight this feature that I’ve come up with to only show the candles that are included or basically highlight those in better included in the calculation for the moving average and then also show you the past history of it and then kind of explain how we did that with the show last and the offset feature so if you like this indicator you want to add it I’ve already mentioned you check out my profile there’s other indicators and things on there as well so make sure to check those out if you like the video please like and if you like these types of videos please subscribe it helps me a lot but you’ll also get to see all the other videos were doing especially if you like this video go back and check out the other videos in the series so far where you can kind of follow along and all this other stuff that I didn’t talk about would be on there as well and it looks like we just got a brave advertisement while we’re doing this that’s okay I support brave see ya that’s pretty much covers everything so just like and subscribe and that’s about it thanks have a nice day [Music]