TradingView Pine Script Tutorial 30 – Using Fill Function on a Chart. Part 3: Repeating Gradients

TradingView Pine Script Tutorial 30 – Using Fill Function on a Chart. Part 3: Repeating Gradients

YouTube Video

YouTube Video Transcript

[Music] hey this is David Trebek bits in this video we’re gonna take a look at using gradients when we’re doing our fills between our different lines on our plots and in the last couple of videos we talked about doing fills between two different lines or two different plots and they have been rather basic and some are based on different conditions on what color they should be and I’ve kind of carried the idea of the conditional fill over maybe not so much with when the fill shows up like we did with the RSI but the condition of what color it’s gonna be but there’s also another condition that we’re adding on here is what color the fill should be within that particular candle now this isn’t something that it’s terribly easy to do if you’re trying to figure this out on your own I played around with it myself but there’s a group of people called pine coders they have their own website mm-hmm and they have a lot of great resources on pine and I’m gonna show you something that they did that I learned a lot about for the gradients that we’re using here when I decided to look at the gradients now you’ll see they have a public script now there’s a link to it in the description of the video so if you’re curious about that you can go down and see that now while you’re down there like the video please but what they’re doing is they are returning a hex color value and this is an alpha RGB so it returns a red green blue and an alpha value which is transparency value essentially for a color and you use hexadecimal values or whatever the whatever the mode is here I believe it’s hexadecimal but anyway you return this color code instead of actually telling it a color like color dot red like we did in the past we’re gonna use this code we’re gonna use these functions that they created to return a color code now the functions that they have return a different color code based on the number you put into the function now if you’re having a hard time reading this code it’s likely because they use their coding standards that they’ve come up with and if you go to their website they actually have a page dedicated to this and I’ll link that in the description of the video we’ll cover this a little bit later about what they’re actually doing here but if you’ve been following me and you’re not an advanced or an intermediate programmer by any means it might be a little bit harder for you to read then looking at how I’ve done the code in the past to where it’s a lot more simple and straightforward to where we’re using you know full words instead of you know lowercase underscore and then different essentially code words to help developers know what they’re actually looking at so what we’re taking from this we’re not taking anything else what we’re gonna be taking from this one is the function for the lime color and the red color and when we pass in a number we’re gonna pass in anything essentially any number but what we’re really wanting to focus on is the numbers one through ten now anything above nine returns this particular color otherwise we start looking for the other ones and what we’re going to do is we’re actually gonna repeat so we’re gonna go through the lists and then we’re gonna circle back through the list while it’s supposed to be green we’re gonna do the same thing with red so the first thing I’ve done is I’ve created our script over here you can see we have this repeating gradient there’s nothing special about it that’s related to the actual script we’re working with there is no real value in the color here other than it’s green or red it just is kind of aesthetically slightly more pleasing I suppose than if it were just red or green so let’s go ahead take a look at the script here and slide this up so you’ll notice I have pulled those functions over we aren’t going to be using any any of these so you just kind of ignore those I just want to show you we replaced well we’ve copied that code over from this one and this is in the script I’m not gonna publish this script because like I mentioned I’m putting a link for their actual script in the video description so you’ll be able to get to the content that way so what I have done to get it to repeat and use these different values is I have actually focused on using the values that it is focused on zero through one through ten I should say and what I’m going to do to repeat it is we have to start with one count up to ten and then once we get to ten we need to start counting down back to one and we need to loop that over and over every single candle to make this nice repeating pattern now the first thing we do is we create a float called the color value now I use C Val for the color value cuz this is going to return either our numbers one through ten okay it’s gonna return either of those numbers one through ten and we also come up with another one called float Direction up now there is a reason I use up and this is a float instead of a boolean and that has to do with how the script works so the first thing we’re going to do is we’re actually going to carry over those values from the previous candles so if it didn’t exist before then we’re gonna start it at 1 and otherwise we’re gonna return the previous value so now that we know the direction we were going and the value of the previous candle whether it was a 1 through 10 we can start with our actual logic of looping through this every candle so let’s go through here as if it’s the first time running script we have a 0 and a 0 here so the first one okay nothing actually exists so the first value is actually going to be 1 and that means that our color value is gonna be one so when we call the color value function it’s going to return this value because it is not greater than one now the direction up is also going to be one on the first candle because it didn’t have anything before it so it’s gonna start counting up with the value 1 and let’s see how that actually works so first we’re going to check if the direction is up if it is up plus 1 is that greater than 10 because if we’re counting up past 10 it really does us no good we need to turn around at that point so if it is we set our value back to 10 we leave it at 10 but we change our direction to zero then it’s just going to break out of this and because it uses an else statement and then it’s gonna go down it’s gonna plot our moving averages so the top and bottom lines here not the field then it’s going to of course like I said it’s going to plot those and it uses this color code for it to be fully transparent so you don’t actually see it you don’t actually see the color of the actual lines going around it now we call our fill function but where we would call our color we’re actually going to be doing a conditional statement so if RMA 1 is greater than ma – it’s gonna be green we know that so we’ll call our green function but we’ll then pass in our color value into the green function and it’s going to return the proper color based on where we are at in the loop so that’s how we get the colors to change from nearly transparent to very opaque back to transparent again and of course the opposite would be true if we were counting down and we subtracted one and that would have been less than one then we stopped it at 1 and we changed the direction and otherwise if there isn’t a need for a direction change you just continue adding on to the color value and you keep the direction the same or subtract and keep the direction the same so that’s pretty much gonna cover it for what I wanted to talk about in this video wanted to keep it kind of short because in the next video we’re gonna care continue on with the gradients but we’re actually going to focus on a slightly different approach than what the pine coder function has to actually tell you how how strong the current fill is compared to previous fills so what we’re going to do is we’re going to look at the maximum percentage change since the cross over and then comparative to the maximum fill distance we’re going to then calculate the percentage transparency it needs and with that transparency then we can you know keep it this more opaque color for longer here and then once it starts to get a bit more narrow be a little bit more transparent and then if it were to get wider again it would get more opaque as it would approach the maximum width of the fill so it’s very similar to what they have here but I believe it’s a bit different because they focus on using a center line and honestly there’s a lot going on here where it’s really not entirely necessary in my opinion and it’s kind of intimidating for those of you watching so I definitely want to give them credit for posting this and all the great resources they have available and definitely check out those links for them in the description otherwise you can also check out my trading me profile where you know I have a lot of scripts posted you can see there’s several down there we’ve got quite a few followers now so check out the chatting we profile you can see all the scripts we’ve done in the tutorial series so if you like this video and you like the pine script tutorial stuff definitely check out those videos but please subscribe because you’re gonna get notifications when there are new tutorial videos and I also cover some other things such as other crypto related projects because I’m a fan and that’s what I like to do on this channel but thank you for staying around and if you are and you have been following the channel and you’re still thinking about getting a paid subscription to trading view to unlock some of their features please consider using the promo code in the description of the videos so that you can get $30 and I can get $30 as well towards an upgraded plan when it comes time for me to renew and then of course that also helps you as well but other than that I think that’s it for this video you can look forward to another one very soon and I thank you and have a nice day [Music]

YouTube Video Description

< br/> ???? IMPORTANT LINKS BELOW ????
? Sign up for a paid plan at TradingView and receive a $30 credit: https://www.tradingview.com/gopro/?share_your_love=BigBitsIO

??????????
Relative URLs:
??????????
? https://www.tradingview.com/script/rFJ5I3Hl-Color-Gradient-Framework-PineCoders-FAQ/
? https://www.pinecoders.com/coding_conventions/

??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️??‍♂️
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.
❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️❗️

#bitcoin #crypto #cryptocurrencies #tradingview #binance #binanceUS #coinbase

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!