TradingView Pine Script Tutorial 26 – Comparing Any Securities by Using Time and Change

TradingView Pine Script Tutorial 26 – Comparing Any Securities by Using Time and Change

YouTube Video

YouTube Video Transcript

[Music] hey this is David for big bits and in this video we’re gonna take a look at comparing the time of particular bars on charts so that we can compare different securities now in this particular example I created a specific indicator just for this you might have already seen me publish this if you follow me on trading view otherwise I’ll give you kind of a quick breakdown on how this actually works we’re gonna be looking at one security and comparing it to another as just the title sounds and then we are going to get the percentage change within that candle so from open to close on both of the securities and then we’re gonna compare the change in percentage points and perp so for example if Bitcoin gained 10 percent on the day and we’re using Bitcoin as our base market and etherium as our other markets are compared to if Bitcoin gained 10% and etherium gained 5% we would have a green bar of 5% for Bitcoin because it outperformed etherion by 5% now the exact opposite is true if aetherium had gained 10% and Bitcoin had only gained 5% the difference would be a negative 5 or a red bar of 5 negative 5 so in order to do this and compare any security we had to look at the time of the bars that were working with because of course many markets closed and cryptocurrency markets don’t really close so we needed a way to be able to compare them and make sure it was fair there were some discrepancies I had noticed to where the bar times weren’t really starting the same so I required that the bars start at the same time when you’re using a particular time frame that way you’re always comparing the correct time frame and you might miss out on some data when the markets don’t quite align perfectly but for the most part as long as there is a match on the bar time when they start it should work pretty well so let’s go ahead and dive into this I’m going to show you the settings we have a base market you can choose from some built in options and the other market is exactly the same way you can check this to use a custom base market but you’re going to have to type in the trading view symbol that you see up here in order to do that and that is so that the security function that we’re using in pine script knows which symbol to actually call otherwise if you don’t check that and write one in it’s just gonna use one of these built-in strings now other than that I think that pretty much covers what you’re seeing here I’ve already talked about how it works and we need to focus on time so let’s do that I’ve got the chart pulled up here I believe my head isn’t in the way so let’s go ahead and take a look at what’s going on if you haven’t seen the video that I’ve done where I talk about functions and strings it’s a good idea to go back through this series and look at that because otherwise this code might not make sense essentially we had to create a function for our base and our other to return a string because we have the option to use a custom one and to type in that value so if this is checked it’s going to return the custom string that they use for their input and if they don’t use the custom string it’ll just use the default first option from that drop-down list so the reason we do that there instead of actually within the single line of code here is because you can’t do the evaluation within the security function so we call that first we use our function within get security it’s going to return that string here plus it’s also best practice I should say to create a function because we’re going to be using that in other places so it’s a good idea to use that as a function so that you can reuse that code later instead of having to type all the evaluation out over and over okay back to the point we are going to be calling the security we need to get this close we need to get its open for the current time frame the current resolution so you can do this also with intraday time frames such as five minutes 15 minutes one minute whatever you have the option for on trading view now once we have that data we can calculate the percentage change and that’s a pretty easy calculation and I’m not gonna go over how to actually do that you can see that in the code for the indicator if you need to now what we are also going to do you’ll notice is we are at also going to capture the bar closing time or well I use this as the reference for creating the variable name it’s not actually the closing time of the bar if you do a ctrl click on that time built-in variable there it’s the current bar time and UNIX format now I’ve also covered unix time in great detail in another video so if you want to go back and learn about what unix time is and how to use that then go back and check that video for now we’re just going to be talking about how we’re using that to compare so essentially it’s looking at the bars and it’s getting their time for the bar that way when we compare it to another one we make sure they actually compare in the same time and there’s not some sort of mismatch and the comparisons don’t actually work ok so we’ve got all of our data we’ve gotten our percentage changes we’ve gotten our absolute values if we needed those and we’ve made them negative if it was necessary so if our base change was less than the other since it returns an absolute value based on the way that this needs to work to get the correct value we then had to multiply it by negative 1 so just ignore that math just know that it works if you’re curious about it you can always dig into it for yourself but now when it comes time to actually plot the percentage difference down here we did have to do something I’m actually going to show you the result of this let’s go ahead and look at SPX okay there you can see there are now some gaps and the data that’s because it’s not plotting that data and this is what I’ve been talking about this is the reason why we’ve gotten the time variable is so that when we compare one to the other we will know the percentage difference based on the actual time frame that we’re looking at and not something that it doesn’t have data for or it doesn’t align perfectly with so this makes sure that we’re working with the correct data when we compare it so because those markets do close there are gaps and you will have those issues when you’re working with those but for the most part if you want to see the data it’s going to be there now what we do to compare these is we make sure that we actually have a base change and another change this is those percentage changes then we also make sure that we do have a closing time for those candles or those bars should I say if there isn’t one then we obviously don’t have anything to compare it to so we’re not gonna plot anything but we also need to check that the closing earth at the time for those bars from the base and the other also matched so if they don’t match and that’s what this means if the base time does not equal to the other time we are going to set our percentage difference to an n/a value which basically means null and it’s not going to plot anything on the chart once we do that all we had to do was plot this on the chart and if it’s above zero it’s nice and green and if it’s below zero it’s red it’s pretty simple plot it’s very easy other than that that’s about all there is to doing this and working with time now I wanted to show you actually how the time works so we’re going to be plotting the time of the candles here let’s go ahead and save this it’ll reset to our default values and you’ll notice these numbers are very high that’s because it’s unix time it’s a 1 it’s one integer for every second since like 1970 we’re looking at daily charts and you can see how these kind of compare here from one of the other two blue let’s see where is the data window I always forget to pull this up there we go I always forget about this but this is actually pretty handy the data window you can see the values of all the plots you have so when we’re comparing these and you can’t really see anything on the chart let me do this you all you can really see these blue lines because our percentage changes are scaled down so small that you really can’t even see them so you can see when we hover over the different bars here the plot values for the different times match and that’s because we required them too so let’s go ahead and change this to where we’re comparing it to the SPX again you and it’s kind of hard to tell though so for example and I can’t really move the cursor right here but in the data window on the right where we were just looking before you can see the plot value from the first blue plot to the second blue plot don’t match so in this particular candle there’s not gonna be a bar so let’s actually take a look it’s this green candle here on the daily chart let’s go ahead go back in the code let’s close those plots off comment them out save our data switch back to the SPX and make sure that there’s actually no data showing on that green candle and that the time comparison works there you go there times for the bars didn’t match so it didn’t print anything because it wasn’t really fair to compare at that point okay so that pretty much does it for this video there’s quite a in this pretty long video wasn’t really a whole lot to cover but if you’re interested in actually using this indicator it’s publicly available on trading view all you have to do is search for it I went to the wrong thing there my bad so all you have to do is search for it it’s the any security versus any security change comparison and like I said it compares their change percentages with you in whatever time frame you’re looking at so it’s actually pretty cool it kind of gives you an idea of how things do versus one another and you might be able to spot trends here over longer periods of time perhaps but it’s really just kind of cool to see that on particularly the stock market crashed the last few days if you wanted to you could compare how Bitcoin compared to that if they had the data available so even though the price dropped on Bitcoin this day it didn’t drop nearly as much as the stock market so it actually outperformed by 2.8 percent that’s pretty cool so like I said you can always look at that in the public library or you can check out my trading view profile you can always follow me on there I don’t have a follow button because I’m looking at my own profile that you can always do that you can go to the script section you can see all the scripts that I’ve created you can check out all of those and also if you are considering a paid plan please check out the referral link in the description for the video I’m really not one to chill these sort of things but if you’re going to consider a paid plan please consider using the referral link because it does help me and it’ll also give you a $30 credit to so I would really appreciate that the plants are pretty expensive but other than that I think that covers it for the video we’ve talked about everything yeah so also if you liked the video please like and also you might as well subscribe because I do these videos and videos like this pretty often you’re gonna get a lot of great information and if you want to always go back and check the previous videos for something you might have missed but other than that 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!