TradingView Pine Script Tutorial 28 – Using Fill Function to Highlight a Chart. Part 1: Basics

TradingView Pine Script Tutorial 28 – Using Fill Function to Highlight a Chart. Part 1: Basics

YouTube Video

YouTube Video Transcript

[Music] hey this is David for big bits and in this video we’re gonna take a look at the fill feature on training view with the pine script and essentially what we’re gonna be doing in the first video here is we’re going to be looking to fill the difference between two moving averages that way you can kind of get an idea of which way the trend is going just by the fill color between the two but we’re gonna get a little bit more advanced than that there’s gonna be a second video where we also discuss how to do conditional filling which is where you would only show a fill within a certain condition and by default that’s not even available so you kind of have to know how to use the code to get to be able to do that so I’ll go ahead take a look at this in the reference manual this is a built-in function that we can use you can fill between two different horizontal lines or you can fill between two different plots now you can’t mix and match and you have to save these values as a plot you can see here they’re referencing they’re creating a variable here and they’re setting it equal to the plot and you have to reference those in the fill so what we’re gonna be doing is we’re gonna be doing this just to show you how it’s actually done and I’ll give you two examples of it with the horizontal line and the plot just kind of show you how that actually works in the first video here in the next video we’re gonna take a look at the conditional fill where we can kind of trick the chart to only showing a fill when we want it to and then there might even be a third video where we’ll go into even more more than that with the fill so stay tuned and keep up with all this and as always please subscribe and like the video if you do like it so let’s go ahead and get started I’ve already plotted a moving average here this is the exponential moving average to see 12 period EMA on the closing price and this is Bitcoin on coinbase and we have calculated our EMA here and we have saved our plot for the MA one here it’s color is set to lime and that’s pretty important because this is going to be our fast trend and what we’re gonna do is we’re gonna fill the difference between this and another EMA green when the fast moving average is above this slow moving average and we’ll fill it red when the fast moving average here is below the slow moving average so let’s go ahead and make our second moving average which we’ll call MA to call our MA function or EMA function here and set this to 26 I use 12 and 26 because that’s what’s used in the MACD calculation by default so now we have those two values let’s go ahead and make our second plot and we’ll make this one red and we hit save you’ll see another line show up here and you can see the Green Line is our 12 period EMA and our red line is our 26th day this should all be very simple for you if you follow the tutorial series up to now if you haven’t please go back and check out the videos where we talk about moving averages that will help you a lot that’s one of the very first ones now when it comes to using the actual fill what we’re gonna do is we’re going to set a fill color conditionally because if you look at the reference manual it calls for a static color you can see it says set the color to this well our colors can be variables we can use them as inputs when our settings so for example if you were to click the settings we could make an input here on the settings for it and it would be constant to that and you could change it but what we want is we want it to change based on the condition of the indicators that we’re working with and this one’s very simple so if it’s just above the slow then it’s green if it’s below the slow it’s red so let’s go ahead and set a variable called fill color and we’re going to set that equal to a conditional statement and we’re gonna say ma one is greater than ma two so in this case our fast is above the slow we will return color dot lime and otherwise it will be below so we’ll return color dot red so again this is a conditional statement we’ve covered this in previous videos as always go back to the other videos to check this out if you don’t understand what’s going on now now that we have our fill color we really have all the information we need we have our first moving average our second moving average and now we can fill the gap in between those on the chart with an actual color so let’s go ahead and do that we’ll call the fill function the first thing we’re going to put in is our moving average one plot not the moving average value but the plot that we saved it as then we also need the second moving average plot and then finally we’re gonna pass in our fill color and it should change colors based on which direction or which one is above the other yeah so it did exactly what we wanted and let’s actually minimize this for just a moment now you can see we move the chart over just a bit you can see that when the green line is above the red line it is filled between the two with green and when the green line is below the red line it is filled with red so generally if you are looking for trends using moving averages and comparing two different ones you can see just about looking at a chart and looking at the fill it’s very easy to tell that you know you’re in an upward trend when it’s green and a downward trend when it’s red so that’s one way to use the fill method and then we’re actually going to go back and we’re gonna do something a little bit different since we’ve used the plot and I mentioned there’s two ways to use this with plots and with horizontal lines we’re actually gonna go back and we’re going to use the horizontal lines that way you get an idea of what that’s actually about so I’m actually gonna go back I’m going to erase all of this or set our overlay to false and you might be familiar with this if you’ve seen some of my other videos where I talked about my smooth RSI indicator and in fact I’ll go ahead and show you what that looks like in just a moment I needed to get a little bit more done here before we can continue let’s see we will set our RSI equal to the RSI close 14 that is the default value for RSI here and I have to plot something my apologies we’ll just plot that really quick so we can save it and move on to something different now we need to remove it from the chart since we change the overlay add it back to the chart and now it won’t be overlaid anymore but let’s go ahead and add the indicator I was talking about smooth RSI you can find this in the public library under my name big bits I owe my profile there and you just click to add that and this one as well is not overlaid you’ll show up down here excellent now you can see what we’re actually going to be doing here is we’re actually going to be plotting these overbought and these oversold lines as well as the maximum and minimum value and we’re going to fill in between just like we have on the smooth RSI chart here just to show you how the horizontal line works let’s go ahead and pull back our source code here now we’ve plotted our RSI and we actually need to save the RSI plot like we did with the moving averages earlier and let’s make it a little bit more friendlier and give it a title and then also set the color equal to white because it’ll stand out really well alright so now we’ve plotted our RSI it’s white we need to know the value of our top line well that’s always going to be 100 because it’s a maximum value for the RSI indicator so we are going to set top line equal to horizontal line with a value of 100 and we’re just going to call this Max and we’re gonna give this a color equal to color dot red let’s go ahead and save this so that you can see that it will go ahead and print that on the screen we have a horizontal line now at our maximum value of 100 and it doesn’t show up over here with our other values so this is a good way to show something on the chart without actually showing a value there now we also need to capture an overbought value and by default we’re gonna have that set to 70 and we’re gonna go ahead and create another horizontal line for our overbought line and we’re gonna have this one set to H line over Botts so that’ll set it at 70 since we set that variable above that we’ll call this one overbought and then we will set its color also equal to color dot red so now we can go ahead and see we have those two lines from the overbought to the maximum value and now all we really have to do for those is actually fill in between those so we’re gonna go ahead and do that let’s see we need to call a fill function we’ll have to reference our first line which is our top line our second line over by and then finally we will also have to pass in a color let’s have it match what we’ve been working with which is red let’s go ahead and save that okay that’s pretty good we have our two lines you can see when something goes over sold on the RSI it’ll come up here and it’ll show into that red section where it’s been filled and to do the exact opposite we can just pretty much copy and paste what we have already and replace the values with whatever we need so we’ll change our top line to a bottom line set the name of it to minimum change its color to lime which is gonna show up as a nice green on the chart will set our oversold value to 30 and go ahead and change that there rename this one change this to reference our new oversold variable and then rename this as well change the color oops and then finally we can replace these values as well let’s go ahead and type all of that so now we should have our oversold and our overbought areas filled and highlighted nicely on the charts that you can see very easily just by looking at the chart when you go into oversold and overbought territory on the RSI and what I like to do and what I did on my smooth RSI indicator was I set an input to where we could change this oversold and or the overbought and the oversold values to where this would be variable and the horizontal line would change based on your setting and that’s another option you can do you can go back and look at the videos for the inputs on how to do that but I think that’s gonna be it for this video and in the next video we’re gonna talk about that conditional fill to where it’ll only show the fill between the lines when you really want it to which is gonna be something really neat because that isn’t something that’s built into that fill function that you can actually do like that but other than that I think that’s about it please like the video if you liked what we’ve covered here and if you want to watch the next video please subscribe it’ll give you a notification when the next video comes out where we talk about the conditional fill and as always check out the reference manual if you have any questions on how to actually do this stuff check out my trading view profile where you can get access to all of my ideas scripts streams and all that on trading view and of course if you have been following the series I would really appreciate it if you were considering a paid plan on training view to use my referral link the link is in the description of the video this will give you $30 and me $30 to go towards a renewal on the planet be really great if you could do that but other than that we are actually done now and that’s it so thank you and have a nice day [Music]

YouTube Video Description

< br/> #bitcoin #crypto #cryptocurrencies #tradingview
?⛓?⛓?⛓ ? IMPORTANT LINKS BELOW ?⛓?⛓?⛓?

??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️
Social and other public profiles
??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️
? 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

???????????
Referral links
???????????
? Buy, Sell and Trade Crypto on Binance.US with LOW fees: https://www.binance.us/?ref=35105151
?‍♂️ Want to buy crypto? Get $10 of bitcoin w/ your first purchase over $100: https://www.coinbase.com/join/johnso_dxz
? Sign up for a paid plan at TradingView and receive a $30 credit: https://www.tradingview.com/gopro/?share_your_love=BigBitsIO
? Browse privately and get rewarded with Brave Browser: https://brave.com/big406
? Receive bonus perks when purchasing Lightnite Game: https://lightnite.io/ref=BigBits
VIEW ALL HERE: https://bigbits.io/bigbits-referrals/

❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️
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.
❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️

This channel focuses on Bitcoin, Ethereum, LiteCoin, Ripple, Link, Basic Attention Token and almost all cryptocurrencies that demand attention. Please like the video if you liked the video, and subscribe if you like these types of videos. David from BigBits is an experienced Software Engineer, but no one is perfect, If you find any issues with any of the open-source, free code, or code shown in videos please comment to let us know what to fix, we listen to our viewers!