TradingView Pine Script Tutorial 11 (B) – Commissions/Fees

TradingView Pine Script Tutorial 11 (B) – Commissions/Fees

YouTube Video

YouTube Video Transcript

[Music] hey this is David for big bits in this video we’re gonna take a look at accounting for the commission or the fees in our strategy now in the past we have just went along with our strategy without trying to account for any fees on trading and that’s just usually not the case now there are some exceptions with different exchanges there’s different fee models but I usually tend to focus on coinbase on the channel so we’re gonna take a look at using the coin base fees on our trading strategy now the first thing I’m gonna do here is I’m actually gonna clean this indicator up a little bit we have a lot of extra features on here that we’re not really looking at so I’m gonna go into the settings and turn some of these off we don’t really care about the second ma we are not going to care really about the ribbons right now and we are not gonna worry about the MA one one two and the two three crosses we can leave our tape profit stop-loss the same that doesn’t really impact things too much now for those of you haven’t seen the videos yet the Green Line is the 50 period daily moving average the red line is the 200-day moving average and of course if we change our resolution it’ll change to that particular resolution so if we change the one-minute chart it’ll be the 50 minute moving average now let’s zoom out take a look at the chart a little bit better you can see we have one trade here if you look at the strategy tester you can see in total on the coinbase chart there’s only been two trades that have qualified and they both wound up in profit but as you can tell with our settings when we bring those back up we have a take profit percentage set of 30 but we’re only seeing 20 8.85% profit that is because we have accounted for the Commission and the strategy now before if you would watch the videos if there was a take profit it would have been strictly at 30% now that’s pretty good so let’s see how this actually works now all of this video is mostly well is entirely around this particular line of code we’ve continued on our strategy and we are adding more parameters on it to increase the usefulness of our strategy now the unfortunate thing about this is that these are all kind of set at once so we can’t really use inputs on our strategy and change these values on the fly like we could before as far as I know you’re gonna have to go in here you’re gonna to change these values maybe we can try that another time to see if the inputs work maybe it’s a different version of pine in the future that can do that but for now you’re just gonna have to type these in and have to go with it as part of your strategy these are all the defaults that are gonna be a part of this tutorial this is going to be the Commission tutorial scripted tutorial be so that everything shows up in order on tradingview now the first item we’re looking at is calc on every tick now what this means and let’s look at our reference manual here calc on every tick which is right here this basically allows you to trade within the daily candle or whatever candle that is currently being used or being drawn on the chart now this can allow you to essentially trade in the areas appear in wicks where otherwise you wouldn’t have say you wanted to trade on an RSI value let’s bring up the RSI indicator and you can see the RSI got very high here and here but the RSI would have been much higher if you were able to trade it during the middle of the day up here so if you wanted to catch that RSI at even higher numbers in this wick that would be how you would do it to have every tick every new set of data that comes in for this chart to process the strategy and potentially put in a position or not now there are some important things to know when you’re talking about using the intra candle calculate ich option and that the data in the history of the chart and I can close the RSI now the data in the history of the chart there’s no way to run the back-testing through the middle of all of these candles so you see these wicks that I was talking about there’s no way to simulate what the strategy was in there because the chart that we’re looking at only knows the data that it’s showing not all of the prices and the changes that happened within that candle to be able to do that there’s a bit beyond what we’re looking at now you would have to create the indicator to look at you know smaller timeframes betrayed the larger timeframe moves and it’s entirely possible what we’re going on to talk about Commission so one of the key things to note about the calc on every tick feature is that now our strategy is showing the moving average completed all the way out to the current candle now before and I’ll show you this live here and say the change you’ll take just a moment now if we weren’t calculating on every tick it’s now gonna move the VMAs back to here because it has it processed this candle yet this takes just a moment to say if there is quite a bit of code in the strategy it was just a moment and there you go and of course I’m gonna have to change back all the settings that we changed earlier but you get the picture it moved all the mas backed because it has a process this candle yet because we didn’t have calculate on every tick set to true now I’m going to change that back I’m going to leave the ribbons on here just because we’re gonna be changing a couple of other values here as well later on so what they’ll just come back anyway so let’s wait for this to save and I’ll move our ma back onto the current candle now let’s actually talk about Commission and if you don’t know that is the fee that the exchange takes on every order that you make now whether you’re placing a limit order which basically means you want to buy at a specific price or sell at a specific price they could have a different fee than if you told it to buy right now which would be the closest price in the order book say somebody wanted to sell at whatever the current price is you could do that immediately right now a lot of times that has a higher fee than if you place an order down here and we’re willing to wait or in order up here and we’re willing to wait just keep in mind whatever exchange you’re using because you will need to know the fee model for that exchange now coinbase which is what I’m going to use for the example it uses a half of a percentage point to calculate the fees for each trade and now for your basic account that doesn’t have a lot of volume that applies to both the market orders and the limit orders that we were just talking about so the first thing you’re gonna have to do is we have two new parameters a commission type we want to use a percentage because coinbase uses a percentage based fee and then we also need to set the Commission value to 0.5 now if you’re thinking about 0.5% you might be tempted to put to put point zero zero five and I completely understand why you would do that because when you’re talking about based on a 100 value that would be the case but 0.5 is this measure based on percentages not whole numbers so it’s point five for half a percentage if you wanted it to be one and a half percent that’s all you would have to do just put the integer before the decimal there now this is how we take care of a permission or a percent base Commission excuse me if you wanted to do a fixed fee like say you’re trading stocks or futures on you know each rate or something and there’s a flat fee of $2 per contract or something then you could put in a flat fee here as well by change the Commission type let’s go here let’s take a look at our commission types here we go they have a percentage which is what we’re using a cash per contract so that’s the example that I gave you so two dollars per contract that would be this example and then cash per order so if it only costs $5 to execute your order on the exchange no matter how big or small it is you would use this one and then you would just set your Commission value to whatever that value is so if you were doing the cash per order and you were trading five contracts you wouldn’t need to worry about there being five contracts your Commission value would just be whatever the price is per contract so if it was $0.50 per contract this would be what you would have in there exactly what we have now if your per order commission type was being used your Commission value would be for example five dollars per order and that would take care of the entire order as opposed to worrying about how many contracts you’re actually using in the order now that being said let’s take a look at a strategy tester and this is on the daily charts yes I don’t think there was this many on here but there is okay ah that’s because I need to change my settings we’ll leave it like this we’re trading all kinds of different crossovers now so you can kind of get an idea like I mentioned earlier in the video I apologize I was completely in the way let me scroll this up here I was in the way earlier in the video I apologize about that but there is a take profit on the strategy of 30% but we’re only trading 28.8 5% when we take our profit that’s because we’re using a market order which has 0.5% fees now if you’re a more experienced trader you know that there is more involved with trying to get an accurate back test and simulate a strategy than just the Commission’s and the fees and you know that there is such a thing as slippage and that is when you don’t get the price that you want now this is sometimes in my opinion a bit more severe when you’re using limit orders when the market tends to move away from wherever you’re trying to enter and you want to enter it again you keep placing the orders in but there’s also slippage when you make market orders when you’ve moved the price and your average price is either above or below where you got in or you or where the signal to go in and I should say so there is a bit more to it your average price of all your contracts may not be the price where it triggered at now for example here I don’t have any slippage on here so the contracts execute at this particular price where in the real world if you were to trade 389 Bitcoin on a single trade you would likely move the price up or down in whatever direction you trade and that’s just a fact on most exchanges unless there’s a much larger order out there this is a fairly large order for Bitcoin at this time so it would move the market significantly if you were moving 389 contracts and significantly is relative it might just be a few tenths of a percent maybe not even that much but it does impact your profit so it is something to keep in mind now when it comes to accounting for the slippage in the strategy itself you can see I have it set to zero that’s because I don’t really care for how it’s being taken care of I would love to be able to set the slippage to a percentage amount but the slippage is actually a number of ticks which is the size increment on your y-axis on your chart for the price so here it’s one penny so the slippage if I set it to one would adjust the price up or down depending in the direction of the trade by one penny so that it could get account for those price changes due to the slippage of us moving the prices when we order now that’s why I’ve included it in here I’ve added several notes so that you know exactly why I did things the way they are in the strategy and so far I mean it’s pretty good like I said you can change all the settings around to however you like when we started the video we only were working with the MA one and three we didn’t even worry about the ribbons and we left our take profit stop loss the same and you can see that impacted the strategy tester with the list of trades the performance review where in fact you can actually see the amount of Commission you’ve paid so I do want to dive in just a little bit more and talk about Commission when you’re looking at strategies because and this you might think this is financial advice but it’s just kind of a fact of the way things work the more often you trade the more fees there are so you need to take that account into account when you’re trading if you’re trading these longer time frames such as daily charts the fees are not going to accrue as fast because you’re not trading as quickly whereas if you’re trading let’s move this down to 5-minute candles say you’re trying to trade five minute candles they are going to accrue much quicker you can see thirty five thousand dollars now thirty six almost instead of two thousand that’s because we got in and out of a lot more trades but when you’re working with these smaller candles a lot of times the percentage movements when you enter an exit are also a lot smaller so that’s why it’s very important to keep in mind your and let me make sure that actually showed up for you here and make sure my head wasn’t in the way yeah I think you can see the Commission’s where are they right here yeah you can see that and let’s go back to the list of trades and I’ll bring that back up here so you can see we had our take profit in our stop loss at 30 and 15 percent respectively but when you’re working with these smaller timeframes like this you’re getting in and out of trades quicker so if the market doesn’t move enough to account for the fees that you’re having to pay then you’ll see a lot of this a lot of red you might have closed when the price was above your entry but due to your fees you ended up losing significantly and it might not be super significant like I believe this one is a good example point six six percent you’re paying point five percent fees on the Buy and the sell so you would have been in profit if there were no fees that’s another reason why this a very good example I should say of why it’s important to consider Commission in your back testing especially when you’re trying to come up with a back test for quicker time frames or resolutions such as the five minutes like what we’re looking at now now I’m gonna call that pretty much for the video we’ve covered just about everything I’ve went over I’m gonna be publishing this script in just a moment it’s gonna be available on my trading view profile and you can actually see that here it’s big bits IO got over 50 followers now it’s kind of early in the channel still since the reboot and we’ve got plenty of scripts posted I’ve posted several ideas we’ve got a lot of likes going on so check out the profile and if you like the video please like here on YouTube and check out the other videos in the series before this one because there’s a lot of the tutorials out here and you can get a good idea on how to create these indicators and strategies on your own there’s a lot of good examples on things that you can do and some notes and comments and make sure you use the reference manual as well but check out the profile like the video and if you like these videos not only check out the scripts here but also check out the series on YouTube and subscribe because I’m going to be coming out with more videos later on these development tutorials and also some other things related to trading development so make sure and subscribe and just yeah have a great day [Music]