YouTube2Text

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

by Algo-trading with Saleh · 3,486 words · 474 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hey guys, so in this video I'm going to
  2. 0:02write a strategy using this very simple
  3. 0:04indicator which not only gives us the
  4. 0:06direction of the trend, it also gives us
  5. 0:08a strength of it and the results are
  6. 0:10pretty good. As always, first I will
  7. 0:12show you the chart on the Trading View
  8. 0:13platform and then we will write the
  9. 0:15Python code for it and actually run some
  10. 0:17back tests on it. So if that sounds
  11. 0:18good, let's get right into it. The main
  12. 0:20indicator of this strategy is called the
  13. 0:22directional index. So let's look it up
  14. 0:25on Trading View. And here you can see we
  15. 0:28have both the directional movement index
  16. 0:30which is the one we want and we have the
  17. 0:32average directional index. So let's add
  18. 0:34this one. And here we have three lines.
  19. 0:36Now this red line here is actually the
  20. 0:39ADX which we're going to use but as a
  21. 0:43separate indicator. So here I'm going to
  22. 0:45disable it to make this easier to read.
  23. 0:47Now the rules are really simple. When
  24. 0:49the blue line goes above the orange
  25. 0:50line, we are in an uptrend. And when
  26. 0:53that is no longer the case, like for
  27. 0:55example in here, we are either in a
  28. 0:57downtrend or at least in a ranging
  29. 0:59market. However, remember that I said
  30. 1:01the ADX is also important. So let's
  31. 1:03actually bring it
  32. 1:06back. And for example, in this case, you
  33. 1:09can see the ADX value is really low. And
  34. 1:11we're going to need to have some kind of
  35. 1:12threshold for the ADX. We usually go
  36. 1:14with a number such as 40 or 30. So let's
  37. 1:17say the threshold for ADX was 30. That
  38. 1:20means in a case like this one, we would
  39. 1:23not have considered this a downtrend.
  40. 1:25Why? Because the ADX which shows simply
  41. 1:28the strength of the trend and not its
  42. 1:30direction is below 30. So we are looking
  43. 1:33for values such as this one for instance
  44. 1:36where the direction of the trend is
  45. 1:38uptrend by this blue line being above
  46. 1:40the orange line and the ADX also being
  47. 1:43above our threshold which in this case
  48. 1:45is 30. This is what we consider an
  49. 1:47uptrend in this strategy. Now to do the
  50. 1:49opposite we need something like this.
  51. 1:51You see the orange line is above the
  52. 1:53blue line and right here the ADX also
  53. 1:56surpasses our threshold. So this is
  54. 1:59where we consider a downtrend and start
  55. 2:01taking short trades. All right. So let's
  56. 2:03open Jess's dashboard and create a new
  57. 2:05strategy. I'm going to name this
  58. 2:07strategy something really fun such as
  59. 2:10trend wave rider. Now we can edit the
  60. 2:14code of it right from within the
  61. 2:15dashboard. But what's actually easier
  62. 2:17for me is to use VS code which is more
  63. 2:19advanced. So let's look it up. All
  64. 2:21right. So I'm going to define a new
  65. 2:23property and I'm going to call it trend.
  66. 2:27In it first I'm going to get the
  67. 2:29directional index. Now I'm going to say
  68. 2:31DI= TA. DA and I will simply pass the
  69. 2:35current candles. But we also need the
  70. 2:37ADX value. So I'm going to say ADX
  71. 2:39equals
  72. 2:40TADX. And then again I will pass the
  73. 2:43current candles. Now to get the final
  74. 2:45result I'm going to simply say if
  75. 2:49di plus is more than d minus which
  76. 2:55simply means this blue line being above
  77. 2:57the orange line and the adx value is
  78. 3:01above 50 I'm going to return one
  79. 3:04otherwise I will simply return minus one
  80. 3:07else if it's vice versa I will return
  81. 3:11minus one and If none of these are true,
  82. 3:15I will simply return zero. Now to give
  83. 3:17the entry rule of the strategy, I will
  84. 3:19simply say this. If
  85. 3:21the current
  86. 3:24trend equals 1, return true or in other
  87. 3:28words, open a long position for me. Now
  88. 3:30for a short position, I will simply do
  89. 3:32the opposite. All right. So now it's
  90. 3:34time to do the position sizing. So I'm
  91. 3:36going to say the entry price is going to
  92. 3:39be the current price. In other words, I
  93. 3:42want it to be a market order because I
  94. 3:45just want to keep it simple. Now, the
  95. 3:47quantity of the position is going to be
  96. 3:50utils risk to quantity. The first
  97. 3:53parameter is going to be self available
  98. 3:55margin. The second is going to be how
  99. 3:58many percentage I want to risk per
  100. 4:00position and I want it to be five. And
  101. 4:03then as the entry, I will pass the entry
  102. 4:05which I just defined. And here we
  103. 4:08actually should pass the sub. So let's
  104. 4:10also give it the sub price. Now I want
  105. 4:13it to be the current
  106. 4:16price and because it is a long position
  107. 4:18we need to subtract from it. So I want
  108. 4:21it to be the current ATR value
  109. 4:24multiplied by 3.5. But here's the thing.
  110. 4:27I did not define the ATR yet. So let's
  111. 4:30also do that. So let's go up here and
  112. 4:33I'm going to say actually it's a
  113. 4:36property. So I'll say it like this. And
  114. 4:39yes, so I will say return TATR and I
  115. 4:43will pass the current candles. All
  116. 4:45right. So let's go back. Now we have the
  117. 4:47sub price. So here I will pass it. And
  118. 4:50then we have the precision which I won't
  119. 4:52touch. But I do want to pass the current
  120. 4:54fee rate. So I will say fee rate equals
  121. 4:58fee rate. Now to submit the buy order, I
  122. 5:01will simply say this by equals the
  123. 5:05quantity and then the entry price.
  124. 5:08That's it. Now in here we are opening
  125. 5:10the position using one simple order and
  126. 5:12it's a market order. But if you wanted
  127. 5:14to do this with multiple orders, we
  128. 5:17should have used this
  129. 5:20syntax, right? So something like this
  130. 5:23would have opened the position using
  131. 5:24three orders. Of course, we should have
  132. 5:26also modified the price of the order,
  133. 5:29but again we don't need to do that. So
  134. 5:31we could simply pass it as this or this.
  135. 5:35Now for the short position I will do the
  136. 5:40opposite. So notice that instead of
  137. 5:43subtracting the current ATR from the
  138. 5:46current price we are adding it. And the
  139. 5:49quantity is going to be very similar
  140. 5:51just like this. And instead of using
  141. 5:53self buy I will use
  142. 5:55self.ell to submit the sell order again
  143. 5:59for a short position. Now, because we're
  144. 6:01using a market order to open this
  145. 6:02position, I do not need to use the
  146. 6:05should cancel function. But if that
  147. 6:08wasn't the case, we should have. All
  148. 6:09right. So, we have the entry rules of
  149. 6:12the strategy now. But we did not define
  150. 6:14how to exit the strategy. Now, I know we
  151. 6:17specify the sub price, but first of all,
  152. 6:20we're not actually submitting that
  153. 6:21order. And besides that, we did not
  154. 6:24define the takerit order. So for that
  155. 6:26I'm going to say def on open position
  156. 6:30and I will say if it's a long position I
  157. 6:35will say the current stop
  158. 6:37loss equals we need this price again. So
  159. 6:40let's copy it and I'm going to say now
  160. 6:44the first parameter has to be the
  161. 6:45quantity of that order and of course
  162. 6:47it's going to be the quantity of the
  163. 6:49current position. So I will say self
  164. 6:52position dotquantity and then I will
  165. 6:55pass this price. Now next to submit the
  166. 6:58take profit I will
  167. 7:00simply do the exact same thing but this
  168. 7:04time instead of subtracting the current
  169. 7:06ATR from the current price we are
  170. 7:08actually adding to it. Also I don't want
  171. 7:10it to be two times of the ATR. I want it
  172. 7:13to be 3.5. All right. So you know what?
  173. 7:15Let's actually make this simpler by
  174. 7:18simply removing this and replacing it
  175. 7:20here. Next, I'm going to say else, which
  176. 7:23means it's a short position. I will do
  177. 7:26the opposite. And for the takerit, I
  178. 7:29will again do the opposite. So, here we
  179. 7:32were subtracting the current ATR from
  180. 7:34the current price for our stop loss. And
  181. 7:36for take profit, we were adding to it.
  182. 7:38But for a short position, we are adding
  183. 7:40the current ATR to the current price for
  184. 7:43the stop loss and doing the other way
  185. 7:45around for a takerit. All right. So now
  186. 7:48we have both the entry and the exit
  187. 7:50rules of the strategy. So we should be
  188. 7:52able to start back testing it. So let's
  189. 7:54go back to Jesse and go to the back
  190. 7:56testing section. And here I'm going to
  191. 7:59look up the name of the strategy. So the
  192. 8:01trend wave rider. Now the time frame of
  193. 8:0415 minutes is fine for me. As for the
  194. 8:06duration, I'm going to pick 2024 up
  195. 8:09until the end of 2024. So that would be
  196. 8:14this. I'm going to make sure the
  197. 8:15benchmark feature is on and I will also
  198. 8:18turn on the fast mode so that the back
  199. 8:20test would go faster. So let's give it a
  200. 8:23run. And while this is going, I'm going
  201. 8:25to also add another one with the 30
  202. 8:27minutes time frame and another one with
  203. 8:30the hourly. So let's take a look at them
  204. 8:33in the benchmark page. Now if you take a
  205. 8:35look at the sharp ratio, the one with
  206. 8:38actually let's add the time frame here.
  207. 8:41All right. So the one with the hourly is
  208. 8:43actually performing better. So the sharp
  209. 8:45is
  210. 8:470.9. Let's take a look at the equity
  211. 8:49curve. So this is how it is. This is for
  212. 8:5230 minutes and this is for 15 minutes.
  213. 8:54Now, I usually like the 15 minutes time
  214. 8:56frame because the average holding time
  215. 8:58of the position is significantly lower
  216. 9:01and I find that psychologically being
  217. 9:03easier for me. So, I'm going to try to
  218. 9:06improve the result of this. But again,
  219. 9:08so far the hourly looks really good and
  220. 9:10so does the 30 minutes. All right. So,
  221. 9:12let's go back to the chart and add an
  222. 9:14oscillator. I want to use the CC or in
  223. 9:17other words, the commodity channel
  224. 9:19index. So, let's add it. And let's
  225. 9:22actually remove this one. All right. So
  226. 9:24the way this works is it's really
  227. 9:26similar to any other escalator that you
  228. 9:29have used so far such as the RSI or the
  229. 9:31SAS. The way this one works is that the
  230. 9:34threshold is set at - 100 and + 100 when
  231. 9:38the value of it which is this blue line
  232. 9:41by the way. So the yellow line here is
  233. 9:43the moving average of it which we don't
  234. 9:44really care about. But the actual value
  235. 9:46of it this blue line when it's below
  236. 9:49this threshold the price is
  237. 9:52oversold like in this case for example
  238. 9:55and when it is above this threshold we
  239. 9:58consider it overbought. Now to take a
  240. 10:00long position we want it to be oversold
  241. 10:03like in this case for example but of
  242. 10:05course we also want our other conditions
  243. 10:07to be met. So let's go back to the code
  244. 10:10and here I'm going to define a new
  245. 10:13property and I will call it
  246. 10:16escalator. Now in it I'm going to say CC
  247. 10:19equals TA CCI. I will simply say if CC
  248. 10:24is more than 100 return minus one for
  249. 10:30again a short position. If it is below
  250. 10:33minus 100 return one and otherwise
  251. 10:36return zero. All right. So let's go to
  252. 10:38the entry rule and say and self
  253. 10:43oscillator equals 1 and also do it for
  254. 10:47our short positions. Now let's run the
  255. 10:49back test one more time. All right. So
  256. 10:51we can see the results improving at
  257. 10:53least a little bit. All right. Next I'm
  258. 10:54going to use two simple moving averages.
  259. 10:57So let's add them. Actually I'm going to
  260. 10:59use SMA which is moving average simple.
  261. 11:02Let's add one more. And I'm going to
  262. 11:05change the
  263. 11:06period from 9 into 25. Next, I will edit
  264. 11:11this one and I will use the 50 period.
  265. 11:15And I will also change the side of it to
  266. 11:17be slightly thicker. And I will also
  267. 11:19change its color into red. Now, the next
  268. 11:23entry rule is going to be this. I want
  269. 11:25to take long positions when the blue
  270. 11:28line is above the red line, like in this
  271. 11:30case. And I want to do the opposite like
  272. 11:32in this case. Now, I'm sure all you guys
  273. 11:34already know moving averages as simple
  274. 11:36as they are, they are very effective.
  275. 11:39All right, so let's go back to the code
  276. 11:41and define a new property. I'm going to
  277. 11:44call
  278. 11:45it MA trend and in it I will simply
  279. 11:50say fast MA equals TA SMA. The first one
  280. 11:55is the current candles and the second
  281. 11:58one is the periods which I will pass 25.
  282. 12:02Next, I will define a slow moving
  283. 12:05average and for the period I will use
  284. 12:0950. Next, I will say if the fast moving
  285. 12:13average is more than slow moving
  286. 12:16average, I want to return one for an
  287. 12:20uptrend. And if it's the other way
  288. 12:23around, I will return minus one. And if
  289. 12:27it's none of these, I will return zero.
  290. 12:30Now in this case I could simply say else
  291. 12:32return minus one because this will never
  292. 12:34actually happen but this is good enough.
  293. 12:37All right. So let's go to the in rule
  294. 12:40and I will simply say and ma trend
  295. 12:43equals one. I will also do the opposite
  296. 12:48for my short positions. Now be careful
  297. 12:50not to mistake these numbers. All right.
  298. 12:52So, let's go to Jesse. And now remember
  299. 12:56these sharp ratio numbers. And let's
  300. 12:58rerun this one more
  301. 13:00time. All right. So, this does look
  302. 13:04slightly better. The 30 minutes is still
  303. 13:07looking the best. And here's the hourly.
  304. 13:10Now, the hourly is not profitable
  305. 13:12anymore. All right. So, the max draw on
  306. 13:15for all of them is actually quite low.
  307. 13:17This allows me to multiply it by at
  308. 13:20least a number such as three. So let's
  309. 13:23go to the golong function and I will
  310. 13:28simply add this by number such as three
  311. 13:32and I will also do the same for my short
  312. 13:36positions. So let's run it one more time
  313. 13:38because this way we'll be able to see
  314. 13:40the actual equity curve much more
  315. 13:43clearly. All right. So the max roden is
  316. 13:46actually it's not that much still. So I
  317. 13:50could even add it by a bigger number
  318. 13:51such as I don't know
  319. 13:56five. So let's run it one more
  320. 13:59time. So in case you're curious what's
  321. 14:02happening here because the max draw is
  322. 14:05not too big and what I define big is
  323. 14:08minus 30%. because it's not as bad as
  324. 14:10minus 30% yet. It allows me to add to
  325. 14:14the size of my positions, which allows
  326. 14:16us to end up making more money at the
  327. 14:18end of the day. But of course, if this
  328. 14:19was a losing strategy, this would have
  329. 14:21caused us to lose money. And of course,
  330. 14:24to be able to do this freely, we're
  331. 14:26going to need to add leverage. I mean,
  332. 14:28we are using leverage now, which also
  333. 14:30means that you need to go to the
  334. 14:32settings and make sure the leverage
  335. 14:34number is to a big number. So, for
  336. 14:36instance, in here, I have set it to six.
  337. 14:38That doesn't mean I'm using six times of
  338. 14:41leverage in my positions. In this case,
  339. 14:43I'm adding like five, but that's not
  340. 14:46even like five times of my capital all
  341. 14:48the time. This number we set into the
  342. 14:50settings is exactly like the number you
  343. 14:53set for leverage on the actual exchange.
  344. 14:55It doesn't mean you're using that much.
  345. 14:57It just means you're leaving that much
  346. 14:58space for your positions if it comes to
  347. 15:00the maximum, not all the time. All
  348. 15:02right, so these actually look good,
  349. 15:05especially the 30 minutes. You could go
  350. 15:08with the 30 minutes, but what I did is
  351. 15:09that I actually went with the 50 minutes
  352. 15:11because I want the holding period of my
  353. 15:13positions to be low because that makes
  354. 15:15it psychologically easier for me. So,
  355. 15:18let's close this and this. Now, let's do
  356. 15:21something else. I want to add other
  357. 15:23periods. So, let's begin since
  358. 15:312021. And here I want it to be 2022.
  359. 15:382023,
  360. 15:412024, and
  361. 15:442025. Now, this year isn't over yet, so
  362. 15:47let's just set it to three for the first
  363. 15:51quarter. Let's go to the benchmarking
  364. 15:54page. And now we can see the sharp ratio
  365. 15:56for all the values. So, let's begin with
  366. 15:592021. We are absolutely crushing the
  367. 16:02market. like this is super
  368. 16:04good in 2022. Again, this is good
  369. 16:08because we were in a nasty downtrend,
  370. 16:10but our equity curve is significantly
  371. 16:12high. In 2023, we are kind of ending
  372. 16:16where the market itself did. We just
  373. 16:18didn't do a good job here. If this
  374. 16:20wasn't happening and this would have
  375. 16:22continued like this, we would have ended
  376. 16:24up with a lot of profit. But
  377. 16:26unfortunately, that did not happen. And
  378. 16:29here's in 2024.
  379. 16:32In 2025, we are slightly losing money.
  380. 16:35But here's the thing. Almost any
  381. 16:36strategy that I know did not do a good
  382. 16:38job in the beginning of 2025. And that's
  383. 16:41not just for algo trading either. Like
  384. 16:44most manual traders also lost money
  385. 16:46thanks to the tariffs of Trump because
  386. 16:49the market did not make any sense. Now I
  387. 16:52also created another version of the
  388. 16:53strategy which I'm going to post on our
  389. 16:55website as a premium strategy. Now, this
  390. 16:57one performs significantly better on
  391. 17:002021. In 2022, it's also good. In 2023,
  392. 17:04it doesn't perform as well, but in 2024,
  393. 17:08again, it does really good, and in 2025,
  394. 17:12it doesn't lose as much. I optimized
  395. 17:14this one according to the latest market
  396. 17:16changes. And you could say this is a
  397. 17:18good thing because market conditions are
  398. 17:20changing all the time, and you want to
  399. 17:21make sure to modify your strategy
  400. 17:23accordingly. But this is also a bit
  401. 17:25dangerous because it increases the
  402. 17:27chance of the strategy being overfit and
  403. 17:29not performing as well in the future.
  404. 17:31But the other thing about this new
  405. 17:33version is that during the ranging
  406. 17:35markets, for example, if you remember
  407. 17:37what happened here in 2024, well, we
  408. 17:40were in the middle of the US election
  409. 17:42and the markets were uncertain. It was
  410. 17:44really bad. All these strategies were
  411. 17:46losing money. But this one is actually
  412. 17:48making money. If we go back to 2022, in
  413. 17:51here we were in a ranging market and
  414. 17:52again here it picked up going up. If I
  415. 17:55go back here, actually we did so good
  416. 17:58here that we cannot really pick up what
  417. 17:59was happening. But my point is this that
  418. 18:02it seems to me that the new version
  419. 18:04actually performs better during a
  420. 18:06ranging market while the previous one
  421. 18:08that I just described in this video
  422. 18:10performs better during a trending
  423. 18:11market. Now this is kind of good because
  424. 18:13you see you never want to run only one
  425. 18:16strategy. You want to have a portfolio
  426. 18:18of strategies and you want those
  427. 18:20strategies not to be correlated. What I
  428. 18:22mean by this is that let's say you have
  429. 18:24two strategies which perform really well
  430. 18:26during an uptrend, but they lose money
  431. 18:28during a ranging market. Well, in that
  432. 18:31case, when a ranging market hits, you're
  433. 18:33going to lose money on both of your
  434. 18:34strategies. But if one of them was
  435. 18:36actually making money during range
  436. 18:38market while the other one was losing,
  437. 18:40they're going to offset each other and
  438. 18:42hopefully your entire portfolio will end
  439. 18:44up actually making money no matter in
  440. 18:47which market condition we are in. So for
  441. 18:49that reason, I think it's actually a
  442. 18:50good idea to run both versions of the
  443. 18:52strategy simultaneously. Now I'm going
  444. 18:54to run both versions of the strategy on
  445. 18:57our strategies index page so you can
  446. 18:59check out the results for different
  447. 19:00periods or symbols and time frames. I
  448. 19:02hope you find this strategy useful, at
  449. 19:04least as a template for you to create
  450. 19:06your very own strategies on top of it
  451. 19:09because as always, I don't really want
  452. 19:10to give you guys trading signals or
  453. 19:12anything like that. My point is just
  454. 19:14show you how to write strategies with
  455. 19:16Jesse. Now, we're going to have a
  456. 19:17giveaway. A random person who likes this
  457. 19:19video, post a comment, and subscribe to
  458. 19:21the channel is going to win 1 million B
  459. 19:23token. All right, so let's pick the
  460. 19:24winner for the previous
  461. 19:29video. And the winner is fantastic as
  462. 19:32always. Not only do I get to learn new
  463. 19:34strategies to test, but I get useful
  464. 19:36information like ATR, ADX, PPPW to
  465. 19:38improve my existing strategies. I'll
  466. 19:40need to do more research on sharp and
  467. 19:43calmer ratios. Thanks again. Thank you
  468. 19:44so much for your comment. Please reach
  469. 19:46out to me so that I can send you your
  470. 19:47bunk tokens. Thanks for watching and
  471. 19:49I'll see you in the next one.
  472. 19:55[Music]
  473. 19:56[Applause]
  474. 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.