"Trend Wave Rider" scalping strategy in Python makes 116%

Algo-trading with Saleh · Intermediate ·📊 Data Analytics & Business Intelligence ·1y ago

About this lesson

In this video, I’ll introduce you to the Trend Wave Rider strategy—powered by the Directional Movement Index (DMI) and the Commodity Channel Index (CCI)—and demonstrate how to implement it as a scalping strategy using Python within the Jesse framework. #ScalpingStrategy #TrendWaveRider #Trading #scalping #opensource #Backtesting #Python Performance metrics on other timeframes and symbols: https://jesse.trade/strategies/trendwaverider The premium version of it: https://jesse.trade/strategies/trendwaveriderv2 Join our FREE Discord community: https://jesse.trade/discord Apex signup URL for fee discounts: https://jesse.trade/apex Bybit signup URL for fee discounts: https://jesse.trade/bybit Explore our strategy listings: https://jesse.trade/strategies

Full Transcript

Hey guys, so in this video I'm going to write a strategy using this very simple indicator which not only gives us the direction of the trend, it also gives us a strength of it and the results are pretty good. As always, first I will show you the chart on the Trading View platform and then we will write the Python code for it and actually run some back tests on it. So if that sounds good, let's get right into it. The main indicator of this strategy is called the directional index. So let's look it up on Trading View. And here you can see we have both the directional movement index which is the one we want and we have the average directional index. So let's add this one. And here we have three lines. Now this red line here is actually the ADX which we're going to use but as a separate indicator. So here I'm going to disable it to make this easier to read. Now the rules are really simple. When the blue line goes above the orange line, we are in an uptrend. And when that is no longer the case, like for example in here, we are either in a downtrend or at least in a ranging market. However, remember that I said the ADX is also important. So let's actually bring it back. And for example, in this case, you can see the ADX value is really low. And we're going to need to have some kind of threshold for the ADX. We usually go with a number such as 40 or 30. So let's say the threshold for ADX was 30. That means in a case like this one, we would not have considered this a downtrend. Why? Because the ADX which shows simply the strength of the trend and not its direction is below 30. So we are looking for values such as this one for instance where the direction of the trend is uptrend by this blue line being above the orange line and the ADX also being above our threshold which in this case is 30. This is what we consider an uptrend in this strategy. Now to do the opposite we need something like this. You see the orange line is above the blue line and right here the ADX also surpasses our threshold. So this is where we consider a downtrend and start taking short trades. All right. So let's open Jess's dashboard and create a new strategy. I'm going to name this strategy something really fun such as trend wave rider. Now we can edit the code of it right from within the dashboard. But what's actually easier for me is to use VS code which is more advanced. So let's look it up. All right. So I'm going to define a new property and I'm going to call it trend. In it first I'm going to get the directional index. Now I'm going to say DI= TA. DA and I will simply pass the current candles. But we also need the ADX value. So I'm going to say ADX equals TADX. And then again I will pass the current candles. Now to get the final result I'm going to simply say if di plus is more than d minus which simply means this blue line being above the orange line and the adx value is above 50 I'm going to return one otherwise I will simply return minus one else if it's vice versa I will return minus one and If none of these are true, I will simply return zero. Now to give the entry rule of the strategy, I will simply say this. If the current trend equals 1, return true or in other words, open a long position for me. Now for a short position, I will simply do the opposite. All right. So now it's time to do the position sizing. So I'm going to say the entry price is going to be the current price. In other words, I want it to be a market order because I just want to keep it simple. Now, the quantity of the position is going to be utils risk to quantity. The first parameter is going to be self available margin. The second is going to be how many percentage I want to risk per position and I want it to be five. And then as the entry, I will pass the entry which I just defined. And here we actually should pass the sub. So let's also give it the sub price. Now I want it to be the current price and because it is a long position we need to subtract from it. So I want it to be the current ATR value multiplied by 3.5. But here's the thing. I did not define the ATR yet. So let's also do that. So let's go up here and I'm going to say actually it's a property. So I'll say it like this. And yes, so I will say return TATR and I will pass the current candles. All right. So let's go back. Now we have the sub price. So here I will pass it. And then we have the precision which I won't touch. But I do want to pass the current fee rate. So I will say fee rate equals fee rate. Now to submit the buy order, I will simply say this by equals the quantity and then the entry price. That's it. Now in here we are opening the position using one simple order and it's a market order. But if you wanted to do this with multiple orders, we should have used this syntax, right? So something like this would have opened the position using three orders. Of course, we should have also modified the price of the order, but again we don't need to do that. So we could simply pass it as this or this. Now for the short position I will do the opposite. So notice that instead of subtracting the current ATR from the current price we are adding it. And the quantity is going to be very similar just like this. And instead of using self buy I will use self.ell to submit the sell order again for a short position. Now, because we're using a market order to open this position, I do not need to use the should cancel function. But if that wasn't the case, we should have. All right. So, we have the entry rules of the strategy now. But we did not define how to exit the strategy. Now, I know we specify the sub price, but first of all, we're not actually submitting that order. And besides that, we did not define the takerit order. So for that I'm going to say def on open position and I will say if it's a long position I will say the current stop loss equals we need this price again. So let's copy it and I'm going to say now the first parameter has to be the quantity of that order and of course it's going to be the quantity of the current position. So I will say self position dotquantity and then I will pass this price. Now next to submit the take profit I will simply do the exact same thing but this time instead of subtracting the current ATR from the current price we are actually adding to it. Also I don't want it to be two times of the ATR. I want it to be 3.5. All right. So you know what? Let's actually make this simpler by simply removing this and replacing it here. Next, I'm going to say else, which means it's a short position. I will do the opposite. And for the takerit, I will again do the opposite. So, here we were subtracting the current ATR from the current price for our stop loss. And for take profit, we were adding to it. But for a short position, we are adding the current ATR to the current price for the stop loss and doing the other way around for a takerit. All right. So now we have both the entry and the exit rules of the strategy. So we should be able to start back testing it. So let's go back to Jesse and go to the back testing section. And here I'm going to look up the name of the strategy. So the trend wave rider. Now the time frame of 15 minutes is fine for me. As for the duration, I'm going to pick 2024 up until the end of 2024. So that would be this. I'm going to make sure the benchmark feature is on and I will also turn on the fast mode so that the back test would go faster. So let's give it a run. And while this is going, I'm going to also add another one with the 30 minutes time frame and another one with the hourly. So let's take a look at them in the benchmark page. Now if you take a look at the sharp ratio, the one with actually let's add the time frame here. All right. So the one with the hourly is actually performing better. So the sharp is 0.9. Let's take a look at the equity curve. So this is how it is. This is for 30 minutes and this is for 15 minutes. Now, I usually like the 15 minutes time frame because the average holding time of the position is significantly lower and I find that psychologically being easier for me. So, I'm going to try to improve the result of this. But again, so far the hourly looks really good and so does the 30 minutes. All right. So, let's go back to the chart and add an oscillator. I want to use the CC or in other words, the commodity channel index. So, let's add it. And let's actually remove this one. All right. So the way this works is it's really similar to any other escalator that you have used so far such as the RSI or the SAS. The way this one works is that the threshold is set at - 100 and + 100 when the value of it which is this blue line by the way. So the yellow line here is the moving average of it which we don't really care about. But the actual value of it this blue line when it's below this threshold the price is oversold like in this case for example and when it is above this threshold we consider it overbought. Now to take a long position we want it to be oversold like in this case for example but of course we also want our other conditions to be met. So let's go back to the code and here I'm going to define a new property and I will call it escalator. Now in it I'm going to say CC equals TA CCI. I will simply say if CC is more than 100 return minus one for again a short position. If it is below minus 100 return one and otherwise return zero. All right. So let's go to the entry rule and say and self oscillator equals 1 and also do it for our short positions. Now let's run the back test one more time. All right. So we can see the results improving at least a little bit. All right. Next I'm going to use two simple moving averages. So let's add them. Actually I'm going to use SMA which is moving average simple. Let's add one more. And I'm going to change the period from 9 into 25. Next, I will edit this one and I will use the 50 period. And I will also change the side of it to be slightly thicker. And I will also change its color into red. Now, the next entry rule is going to be this. I want to take long positions when the blue line is above the red line, like in this case. And I want to do the opposite like in this case. Now, I'm sure all you guys already know moving averages as simple as they are, they are very effective. All right, so let's go back to the code and define a new property. I'm going to call it MA trend and in it I will simply say fast MA equals TA SMA. The first one is the current candles and the second one is the periods which I will pass 25. Next, I will define a slow moving average and for the period I will use 50. Next, I will say if the fast moving average is more than slow moving average, I want to return one for an uptrend. And if it's the other way around, I will return minus one. And if it's none of these, I will return zero. Now in this case I could simply say else return minus one because this will never actually happen but this is good enough. All right. So let's go to the in rule and I will simply say and ma trend equals one. I will also do the opposite for my short positions. Now be careful not to mistake these numbers. All right. So, let's go to Jesse. And now remember these sharp ratio numbers. And let's rerun this one more time. All right. So, this does look slightly better. The 30 minutes is still looking the best. And here's the hourly. Now, the hourly is not profitable anymore. All right. So, the max draw on for all of them is actually quite low. This allows me to multiply it by at least a number such as three. So let's go to the golong function and I will simply add this by number such as three and I will also do the same for my short positions. So let's run it one more time because this way we'll be able to see the actual equity curve much more clearly. All right. So the max roden is actually it's not that much still. So I could even add it by a bigger number such as I don't know five. So let's run it one more time. So in case you're curious what's happening here because the max draw is not too big and what I define big is minus 30%. because it's not as bad as minus 30% yet. It allows me to add to the size of my positions, which allows us to end up making more money at the end of the day. But of course, if this was a losing strategy, this would have caused us to lose money. And of course, to be able to do this freely, we're going to need to add leverage. I mean, we are using leverage now, which also means that you need to go to the settings and make sure the leverage number is to a big number. So, for instance, in here, I have set it to six. That doesn't mean I'm using six times of leverage in my positions. In this case, I'm adding like five, but that's not even like five times of my capital all the time. This number we set into the settings is exactly like the number you set for leverage on the actual exchange. It doesn't mean you're using that much. It just means you're leaving that much space for your positions if it comes to the maximum, not all the time. All right, so these actually look good, especially the 30 minutes. You could go with the 30 minutes, but what I did is that I actually went with the 50 minutes because I want the holding period of my positions to be low because that makes it psychologically easier for me. So, let's close this and this. Now, let's do something else. I want to add other periods. So, let's begin since 2021. And here I want it to be 2022. 2023, 2024, and 2025. Now, this year isn't over yet, so let's just set it to three for the first quarter. Let's go to the benchmarking page. And now we can see the sharp ratio for all the values. So, let's begin with 2021. We are absolutely crushing the market. like this is super good in 2022. Again, this is good because we were in a nasty downtrend, but our equity curve is significantly high. In 2023, we are kind of ending where the market itself did. We just didn't do a good job here. If this wasn't happening and this would have continued like this, we would have ended up with a lot of profit. But unfortunately, that did not happen. And here's in 2024. In 2025, we are slightly losing money. But here's the thing. Almost any strategy that I know did not do a good job in the beginning of 2025. And that's not just for algo trading either. Like most manual traders also lost money thanks to the tariffs of Trump because the market did not make any sense. Now I also created another version of the strategy which I'm going to post on our website as a premium strategy. Now, this one performs significantly better on 2021. In 2022, it's also good. In 2023, it doesn't perform as well, but in 2024, again, it does really good, and in 2025, it doesn't lose as much. I optimized this one according to the latest market changes. And you could say this is a good thing because market conditions are changing all the time, and you want to make sure to modify your strategy accordingly. But this is also a bit dangerous because it increases the chance of the strategy being overfit and not performing as well in the future. But the other thing about this new version is that during the ranging markets, for example, if you remember what happened here in 2024, well, we were in the middle of the US election and the markets were uncertain. It was really bad. All these strategies were losing money. But this one is actually making money. If we go back to 2022, in here we were in a ranging market and again here it picked up going up. If I go back here, actually we did so good here that we cannot really pick up what was happening. But my point is this that it seems to me that the new version actually performs better during a ranging market while the previous one that I just described in this video performs better during a trending market. Now this is kind of good because you see you never want to run only one strategy. You want to have a portfolio of strategies and you want those strategies not to be correlated. What I mean by this is that let's say you have two strategies which perform really well during an uptrend, but they lose money during a ranging market. Well, in that case, when a ranging market hits, you're going to lose money on both of your strategies. But if one of them was actually making money during range market while the other one was losing, they're going to offset each other and hopefully your entire portfolio will end up actually making money no matter in which market condition we are in. So for that reason, I think it's actually a good idea to run both versions of the strategy simultaneously. Now I'm going to run both versions of the strategy on our strategies index page so you can check out the results for different periods or symbols and time frames. I hope you find this strategy useful, at least as a template for you to create your very own strategies on top of it because as always, I don't really want to give you guys trading signals or anything like that. My point is just show you how to write strategies with Jesse. Now, we're going to have a giveaway. A random person who likes this video, post a comment, and subscribe to the channel is going to win 1 million B token. All right, so let's pick the winner for the previous video. And the winner is fantastic as always. Not only do I get to learn new strategies to test, but I get useful information like ATR, ADX, PPPW to improve my existing strategies. I'll need to do more research on sharp and calmer ratios. Thanks again. Thank you so much for your comment. Please reach out to me so that I can send you your bunk tokens. Thanks for watching and I'll see you in the next one. [Music] [Applause] [Music]

Original Description

In this video, I’ll introduce you to the Trend Wave Rider strategy—powered by the Directional Movement Index (DMI) and the Commodity Channel Index (CCI)—and demonstrate how to implement it as a scalping strategy using Python within the Jesse framework. #ScalpingStrategy #TrendWaveRider #Trading #scalping #opensource #Backtesting #Python Performance metrics on other timeframes and symbols: https://jesse.trade/strategies/trendwaverider The premium version of it: https://jesse.trade/strategies/trendwaveriderv2 Join our FREE Discord community: https://jesse.trade/discord Apex signup URL for fee discounts: https://jesse.trade/apex Bybit signup URL for fee discounts: https://jesse.trade/bybit Explore our strategy listings: https://jesse.trade/strategies
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Related Reads

Up next
6-Phase SQL Roadmap 2026 | Data Analytics & Engineering | #shorts
SCALER
Watch →