YouTube Video Transcript
hey this is David for big bits and in this video we’re gonna take a look at the value win function on pine script for trading view and this is going to be a video where we cover that function and kind of how it works but since it’s really just one little function we’re actually going to go into an example of how you can actually use it in a strategy and of course this is just an example so probably not gonna be too useful of an actual strategy so much as the example to show you how you can actually apply it to your own so before we begin if you haven’t already please check out the trading view profile and you can also if you’re considering a paid plan on trading you use a referral that is in the description of the video you can also find a link to my profile down there where we’ve done a bunch of other scripts and done a bunch of other things on trading view with this particular YouTube account and that’s all in the description of the video so if you’re down there just go ahead and leave a like and if you would subscribe because we do these kind of videos all the time now back to our valuing function I’ve created a little script just for this particular video and if you’re not familiar and you probably aren’t because you’re watching this video the value in function will give you a value when a condition happened and what’s really neat about this is you can tell it when the last condition was so how many times ago this condition occurred you can get that value back so so for example we want to see the closing price on a candle when the Golden Cross happened but we don’t want the price of the most recent gold across we want one three times back well you can do that there’s plenty of other examples where you can find to do this to find those conditions in previous candles going back so that you can actually apply them to your strategy and I think the way I’m going to show you today is pretty useful for some strategies but let’s go ahead and get talking about actual value in now the first thing you’ll notice is we have two moving averages a green and a red and typically on my channel the green is a 50 period a single moving average in the red is a 200 period single moving average and I do this because you’re usually working with a golden or death cross when you’re using a 500 to earth 50 and 200 excuse me so what we’re going to be capturing first of all is the value win and we’re gonna save this as the last cross we’re gonna get the value in there was a cross over from the ma one to the ma to and they may one is the Green Line and the ma to is at redline so we’re gonna get the closing price on the candle where the crossover occurred so it should be around here and what we’re going to do to define what you were going to return is here this is our second part of this function and that is the source so when this condition is true it’s going to return this value and on this occurrence so the reason I’ve chosen zero is because this is actually the first occurrence and you’re probably gonna be tempted to put one in here and if you were at least with the way the scripts working for me you’re going to get the second instance back so let’s go ahead and plot these things I’ve already got it may want any may to plotted so I’m going to just uncomment this code and show you where the last cross is you’re going to see some yellow circles now show up on the screen so great you can actually see there is a bit of a difference here there is one line here and another here at least the circles I should say so we had our crossover occur here you can see the value you can see the value here so you can see we’re at 73 87 and just to prove this is different lines if 73 26 back here so what it’s doing is it’s getting you the value of the clothes when that crossover happened on the very first instance now say we want to go back and get an instance farther back say we want to get this value on our last cross and this should make this line actually start here so we should have 73 26 instead of 7387 here if we move this and change it back to one sure enough we do so that just kind of shows you that this is a zero based index like a lot of things on trading view and you have to actually start with zero when you want the first value in something and that’s very important to remember and of course you can go back much further than that let’s just go back five just for the fun of it so that’s where our golden cross occurred six times ago because it’s n plus 1 on the occurrences backwards on the into concurrence so that’s something to keep in mind that was over at eleven thousand five hundred sixteen so wow that’s that’s pretty hot up there back there but let’s go ahead and change this back to zero because in the example I’m gonna be showing you were actually just going to be doing a very simple strategy to where we are looking to enter into a position long when the RSI is low but instead of just using a low RSI we want to also make sure that we are entering our position above our last cross price that way we can kind of confirm that the price has been moving up and it hasn’t just kind of flatlined like it has here and we want our RSI to be low so that means the prices come up and it’s went down sharply and we have a low RSI so this might be a good opportunity to buy now like I said this probably isn’t gonna work out that great because there’s a lot of other things that I would like to add to this strategy but we’re gonna go ahead and work with what we’ve got here and just show you how values win can be useful in the strategy here so let me go ahead and copy some code over here I’ve done a lot of this before the video actually started so we’re not gonna have to wait around for some live coding let me copy over my inputs okay so we have an oversold and overbought RSI and the reason I brought in the overbought was so that this is another way to exit the trade as well as opposed to just to take profit in a stop loss we’ve already got our last cross and we’ve plotted that so now we need to calculate our RSI and then we also need to calculate our profit and loss targets we can do that with our other calculations here so we have our ma one in May 2 RSI profit target and lost target now we can determine whether our necessary conditions are true for buying or selling so let’s go all the way down here alright these are conditions we want our MA 1 to be greater than ma 2 so we currently want the Green Line above the red line we want our closing price right now to be above the closing price of our last Cross so we would want the price currently to be above this yellow line and at any other point in the history of this particular strategy now we also want the RSI to be less than the oversold RSI and that’s an input that’s at 30 by default that we can change with the settings later and then finally we also want the current price to be greater than the red line as well and that’s just to make sure that we aren’t buying when things are dumping straight through and there’s likely another crossover at least that’s just my theory here so the other conditions are for selling so this determines when we’re going to interposition this is going to determine when we want to exit so we’re going to exit on a death cross or if our RSI is greater than our overbought RSI so they cross under kind of acts like a stop loss because in order for the price to cross under with these averages the price is gonna have to go down and we can also kind of take profit if the RSI ever gets back above the overbought RSI value and we’re also throwing in our take profit and our stop loss these are just kind of safety nets to get us in and out quicker now that we have that all we have to do is copy in our functions for our strategy to actually get in and out of trades you can see if we are a buy we’re going to enter into a long called low RSI in an uptrend and that’s because with the Golden Cross and the price above the last Cross value we would expect it to be in an uptrend or at least I would now the other thing we’re going to be doing is we’re also going to be planning an exit here called a profit or stop-loss when our toss in our profit and our loss values there now if you’re curious about how that actually works because there is a little bit of code involved with calculus your profit and loss targets I have another video about that in this series earlier on so please go check that up if you haven’t already now the other one of course is we’re going to sell this is how we’re going to close our long and really this is very simple we just call closed on strategy but it’s based on whether or not our conditions are telling us we should sell so let’s go ahead and save this and hopefully it’ll work on the first try after I’ve copied this code back over from notepad yeah there we go so you can see based on the strategy tester on the performance summary this is gonna net you two point four eight percent profit with 0.1% fees on each trade so let’s actually go and look at the list of trades you can see five percent five percent four point nine to those most likely hit the take profit and then there looks like there’s several here who hit the stop loss at five percent many more at five percent so this one’s pretty interesting there’s a lot of trades going on most of them were profitable and it seems like we could probably tweak a few things to make it a little bit better and I’m sure you’re probably thinking plenty more things that you could add in on your own if you’re a little bit more experienced with trading so you can always take this as an example of how to use that to help you now this video has all been all about the value win function and how we can actually use that incorporate that into a strategy hope this has actually helped with that and you actually understand the value win function and when you might want to actually use that for yourself so I hope you’ve liked this video if you have please leave a like and if you like these types of videos I do plenty of them I have a tutorial series here on trading view over 30 videos at this time and you can always subscribe and get updates on that whenever they happen but we also do other videos here on the channel and of course always check out the trading view profile and sign up with the referral link to get $30 toward your pay plan on trading food but I think that is it for now yeah I’m pretty sure all right 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
Valuewhen function in Pine Script for TradingView can be used to get a value during a certain condition on the nth occurance back. We use this function to determine the last close price “valuewhen” the Golden Cross occurred. Please view the TradingView Pine Script reference manual for more informaiton on valuewhen and other functions in Pine.
Social and other public profiles
💻 Website: https://www.bigbits.io
🎮 Discord: https://discord.gg/rapMn4z
🐦 Twitter: https://twitter.com/BigBitsIO
📔 Facebook: https://www.facebook.com/BigBitsIO/
📈 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!