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