YouTube2Text

GPT: Triple moving average strategy in Python makes 4983% — Transcript

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

Full transcript

  1. 0:00Hey guys, it's So today I'm going to
  2. 0:01show you a strategy which is super
  3. 0:04simple and yet the result of it is
  4. 0:06pretty great. It's a trend following
  5. 0:08strategy, but you could kind of say it's
  6. 0:10a mini version because we're going to
  7. 0:12use limit order to open the position at
  8. 0:14a pullback. Now, I'm not going to write
  9. 0:16the code of the strategy myself.
  10. 0:17Instead, I will be using GPT to convert
  11. 0:20the logic of the strategy. So that means
  12. 0:22the entry and the exit rules of it into
  13. 0:24Python code so we can run some back test
  14. 0:27on it and see some charts and numbers.
  15. 0:29So you're going to see that even if your
  16. 0:30Python knowledge isn't great, you can
  17. 0:32get started. So if that sounds good,
  18. 0:34let's get to it. The main indicator of
  19. 0:36this strategy is called TEMO, which is
  20. 0:38stands for triple exponential moving
  21. 0:40average. So let's look it up on Trading
  22. 0:42View
  23. 0:45and add two of it. Change the period of
  24. 0:49them to be 10
  25. 0:54and
  26. 0:5680.
  27. 0:59Now the entry rule is very simple. When
  28. 1:01this orange line which is temo with the
  29. 1:03period of 10 goes above the purple line
  30. 1:06which is temo with the period of 80, we
  31. 1:09consider that an uptrend. When it's vice
  32. 1:11versa, we consider it a downtrend. But
  33. 1:13first I want to show you the difference
  34. 1:15between tema indicator and the good old
  35. 1:17EMA. So let's disable the one with the
  36. 1:20period of 80 for a second. Add a regular
  37. 1:24EMA.
  38. 1:26change its period to equal the same
  39. 1:29which is 10. All right. So this orange
  40. 1:31line here is tema with the period of 10
  41. 1:35and the blue one is EMA with the period
  42. 1:37of 10. So they have the same period but
  43. 1:39let's see how they behave. So for
  44. 1:41instance in here you see when the price
  45. 1:43starts to go up the TMA indicator which
  46. 1:46again is this orange line it starts to
  47. 1:48go up way faster. And for example, in
  48. 1:51here where the price starts to go down,
  49. 1:53you can see the Tema line goes down way
  50. 1:56faster. Now to summarize it, you know
  51. 1:57the issue with moving averages, which is
  52. 1:59their lagging indicators. Well, if you
  53. 2:02use Tema instead of the good old EMA,
  54. 2:04you're going to have less lag. Or in
  55. 2:06other words, it moves significantly
  56. 2:09faster. All right, so let's change this
  57. 2:12back to what it was. bring back the ter
  58. 2:15with the period of 80 to have our inter
  59. 2:19rule. Now the second rule of the
  60. 2:20strategy is that we don't want to just
  61. 2:22look into the short-term trend. We also
  62. 2:24want to look at the long-term trend. Now
  63. 2:27for that I'm going to use the same
  64. 2:28indicator except with values of 20 and
  65. 2:3070 but on the bigger time frame
  66. 2:33specifically I want to use the 4our time
  67. 2:35frame. Now before I forget the trading
  68. 2:37time frame for this strategy is 30
  69. 2:39minutes which is why it is considered a
  70. 2:42day trading strategy. All right. Next,
  71. 2:44we want to use a volatility filter. And
  72. 2:46as most of my strategies, I'm going to
  73. 2:48use the ADX in here.
  74. 2:52So, basically, whenever this red line
  75. 2:54goes above the green line here, which is
  76. 2:56our threshold, we want to take the trade
  77. 2:58or for example in here. All right. Next,
  78. 3:00I want to use some kind of oscillator.
  79. 3:02And for this strategy, I'm going to use
  80. 3:04the Shae momentum indicator. So, let's
  81. 3:07look it up on Trading View.
  82. 3:12Now it is some kind of oscillator very
  83. 3:14similar to RSI. But the main difference
  84. 3:16you should care about is that it moves
  85. 3:19faster. It is more sensitive to the
  86. 3:21price change. So just like the TME
  87. 3:23indicator which was more sensitive to
  88. 3:24the good old EMA, the Shanda momentum
  89. 3:27oscillator or CMO for short is also more
  90. 3:31sensitive compared to a traditional
  91. 3:33oscillator such as the RSI. And the
  92. 3:35inter rule is very simple. So the
  93. 3:37threshold is at 40 and also minus 40. So
  94. 3:41basically whenever this line is above
  95. 3:44our threshold we want to look for long
  96. 3:46trades and whenever it is below minus 40
  97. 3:49we want to look for short trades. All
  98. 3:50right. So now we have all the entry
  99. 3:52rules of the strategy. And as for the
  100. 3:54position sizing as always I'm going to
  101. 3:56risk 3% of my capital per each trade.
  102. 3:59But for the entry price what I want to
  103. 4:01do is I want to use a limit order
  104. 4:03because I want to buy at a pullback. So
  105. 4:06I'm going to keep it simple. I will buy
  106. 4:07at 180R below the current price for a
  107. 4:10long position and do the opposite for a
  108. 4:13short position. All right. So I think
  109. 4:14now is a good time to actually go and
  110. 4:16code this thing so we can run some back
  111. 4:18test. Now to use this service you have
  112. 4:19two options. One is to use the cloud
  113. 4:21version which is hosted by us which you
  114. 4:24need to sign up for free to get started
  115. 4:26with or you can watch my previous video
  116. 4:28where I explain how to self-hosted by
  117. 4:31yourself which is better if you have
  118. 4:32privacy concerns or let's say you want
  119. 4:34to use premium models without paying us
  120. 4:36anything. So choose one of the two but
  121. 4:39in this video I'm going to use the cloud
  122. 4:41version as the LLM model. I have
  123. 4:43selected cloud 3.7 set. You can select
  124. 4:46whichever you think works best but in my
  125. 4:48cases cloud usually works best. And as
  126. 4:51for the instruction here it is. So right
  127. 4:54trend following strategy the short-term
  128. 4:56trend must be one representing an
  129. 4:58uptrend. To determine this use the tema
  130. 5:00indicator with a period of 10 which
  131. 5:02should be above the temo with a period
  132. 5:04of 80. If it's vice versa the trend is
  133. 5:06down. So you know basically just what I
  134. 5:08showed you. For the long-term trend, use
  135. 5:10the same indicator over the period of 20
  136. 5:12and 70. So, let's also ask it to use the
  137. 5:154 hours time frame except to use
  138. 5:19the 4 hours time frame. For volatility
  139. 5:23filter, use the ADX indicator. Its
  140. 5:25values must be above 40 to take any
  141. 5:27trades. Also, use the CH momentum
  142. 5:29indicator as an oscalator. For long
  143. 5:32trades, it value must be above 40. For
  144. 5:34short trades, do the exact opposite of
  145. 5:37the above conditions. For position
  146. 5:38sizing, risk 3% of the available margin
  147. 5:41per trade. For the entry price of the
  148. 5:43trades, use a limit order ATR below the
  149. 5:46entry price. For the stop loss, you use
  150. 5:48four times of the current ATR below the
  151. 5:50entry price. For exiting the trade, the
  152. 5:52stop loss must be as described above.
  153. 5:54And the takerit must be three times the
  154. 5:56ATR indicator. And that's it. So, I just
  155. 5:59told it basically what I need, just the
  156. 6:01entry and exit rules. So, let's hit
  157. 6:04enter and see how it writes the code.
  158. 6:07All
  159. 6:09right. So, here it is. This is the
  160. 6:10short-term trend. It's using Tema with a
  161. 6:12period of 10 and 80. It's returning
  162. 6:15either one or minus one. For long-term
  163. 6:17trend, it is using the first time frame
  164. 6:20and periods of 20 and 70, which is
  165. 6:22exactly what I ask for. Then need to
  166. 6:25find the ATR, the ADX, the CMO, and for
  167. 6:30shoot long, which is where we specify
  168. 6:32the inter rules of the strategy. For
  169. 6:34short positions, it's saying the
  170. 6:35short-term trend must be one, the
  171. 6:37long-term trend must be one, the ADX
  172. 6:39must be above 40, and so should the CMO.
  173. 6:42For uh for short positions, it's saying
  174. 6:45that the trends must be minus one, the
  175. 6:48ADX must be above 40, the CMO must be
  176. 6:51below minus 40. For position sizing, the
  177. 6:54entry price is a limit order one ATR
  178. 6:57below the current price. This is
  179. 6:58correct. The stop loss is four times of
  180. 7:00the current ATR minus the entry price.
  181. 7:03It is risking 3% using the riskto
  182. 7:05quantity utility function of Jesse to
  183. 7:07make sure we never lose more than 3% of
  184. 7:10our total capital per each trade. By the
  185. 7:13way, this doesn't mean to close the
  186. 7:15position when it goes 3% against us. It
  187. 7:17closes it when we are losing 3% of our
  188. 7:20total capital. It's a bit different. And
  189. 7:22then it is submitting the order using a
  190. 7:25buy order. The first parameter is the
  191. 7:27quantity of it and the second is the
  192. 7:29price. Now for short trades, it is doing
  193. 7:31the opposite which is correct. Now this
  194. 7:34one also must be here and return true.
  195. 7:37Now what it does is because we're using
  196. 7:39limit orders. What would happen if we
  197. 7:41submit the order but it doesn't get
  198. 7:43filled during that candle? Well, when
  199. 7:45the next candle comes, we want to cancel
  200. 7:47the previous one and submit a new order
  201. 7:50using the current conditions such as the
  202. 7:52current ATR value. And when the position
  203. 7:54opens, it submits a stop loss like this.
  204. 7:58Four times the current ATR minus the
  205. 8:00enterprise of the position. And it is
  206. 8:02also using the quantity of the current
  207. 8:04position for the stop loss. For the take
  208. 8:07profit, it's doing exactly the same
  209. 8:09except three times the ATR. Also,
  210. 8:12instead of subtracting the price, it is
  211. 8:14adding it. And for a short position,
  212. 8:16it's doing exactly the opposite. So,
  213. 8:18this is perfect. So, let's go up here
  214. 8:23and copy the whole thing. Go to J's
  215. 8:26dashboard and go to new strategy. I'm
  216. 8:29going to call it tema
  217. 8:32trend following.
  218. 8:37Let's paste the whole thing here.
  219. 8:41Go to back testing page. The exchange is
  220. 8:44Binance perpetual futures. The route BTC
  221. 8:47UCT is correct. The trading time frame
  222. 8:49must be 30 minutes. Here, let's choose
  223. 8:52tema trend following. We also have one
  224. 8:56data route because we're using the
  225. 8:58bigger time frame which is 4 hours with
  226. 9:01the same symbol. And let's begin by back
  227. 9:04testing the first six month of 2025.
  228. 9:10Let's enable the interactive charts, the
  229. 9:14fast mode, and the benchmark feature.
  230. 9:16So, let's run it.
  231. 9:21And there it is. So, let's scroll down.
  232. 9:24The P&L is 32%. The maxon is minus 3%,
  233. 9:29which is crazy.
  234. 9:31The win rate is 81%. The average holding
  235. 9:35time is 12 hours. The sharp ratio is
  236. 9:374.34.
  237. 9:39Now, by the way, this is a bit too good
  238. 9:41to be true. Like, yes, we're getting it
  239. 9:43on 2025, but I don't expect it to be
  240. 9:45this good in all the periods. And I'm
  241. 9:48going to back test it on other periods
  242. 9:50just in a second. Let's take a look at
  243. 9:52the interactive charts. So, we can see
  244. 9:55the type of trades that it took. So, for
  245. 9:56instance, it opens it here and closes it
  246. 10:00here. It opens it here and closes it
  247. 10:03here. We can also see the trades here.
  248. 10:06And let's see there's one that I really
  249. 10:08want to see like this one. I can just
  250. 10:11click on it and it will take me to it.
  251. 10:15Right? So this is where we sold and this
  252. 10:18is where we close our short with a loss.
  253. 10:24Then again we have here and if you want
  254. 10:26to see the details of any trade by the
  255. 10:28way click on it and you can see the
  256. 10:30orders. And then if you click on just
  257. 10:32any of them, you can also see other
  258. 10:34metrics such as the quantity of that
  259. 10:36trade, the entry price, exit price, the
  260. 10:39fees that we paid, and the P&L. But
  261. 10:41actually something really helpful with
  262. 10:43these strategies is to see the indicator
  263. 10:46values when we are taking the trade. So
  264. 10:49let's go back to Jessie GPT and simply
  265. 10:52ask the AI to add the values for us. I
  266. 10:56need you to add values for the charts so
  267. 10:58I can debug the strategy.
  268. 11:05All right. So it added this after
  269. 11:07function here which will do just that.
  270. 11:11So let's copy the whole thing. Go to
  271. 11:14this is dashboard. Press new session.
  272. 11:17Click here to see the code of the
  273. 11:19strategy and paste the whole thing here.
  274. 11:21Now, by the way, this watch list that it
  275. 11:22added is really helpful, but only if you
  276. 11:25are trading the strategy live. So, it's
  277. 11:27not really for back testing. So, I'm
  278. 11:29going to remove this. And let's go back
  279. 11:33here and click the back test one more
  280. 11:36time. Let's go to view charts. And now,
  281. 11:41not only we can see the trades, we can
  282. 11:43also see the demo values. So, 10 and 80
  283. 11:47periods. We can also see the ADX. So for
  284. 11:50example when it opened this long
  285. 11:53position we can see the ADX value is
  286. 11:55indeed above the threshold. So it was at
  287. 11:5850 and the value for CMO was also above
  288. 12:0240.
  289. 12:04So let's take a look at the short trade
  290. 12:09like this one.
  291. 12:12So again the ADX is above 40 and the
  292. 12:16value for CMO is above minus 40. All
  293. 12:19right. So now let's back test it on
  294. 12:21other periods. In fact, I'm going to
  295. 12:23back test it as early as 2021, which is
  296. 12:26the amount of candles that I have up
  297. 12:29until the 6 month of 2025. Now, to make
  298. 12:33sure the back test will go faster, I'm
  299. 12:36going to disable this line here, which
  300. 12:39is for charts. Go back here. And by the
  301. 12:43way, if you don't want to use the editor
  302. 12:45inside Jess's dashboard, you can always
  303. 12:47use something such as the VS code and
  304. 12:50look up your strategy. So for instance,
  305. 12:53tema trend following and you can see the
  306. 12:57code here and you can edit it right from
  307. 13:00here instead of the dashboard. All
  308. 13:02right, so everything looks good. Now
  309. 13:04let's start it. Now while this is going,
  310. 13:07I want to also run another one without
  311. 13:10this benchmark value here.
  312. 13:13Let's run it. So, while that's going, I
  313. 13:15want to quickly remind you guys about
  314. 13:16Apex Omni, which is my favorite deck
  315. 13:19made by the team behind Bybit. It has
  316. 13:21low trading fees, instant order
  317. 13:23execution, and of course, no KYC
  318. 13:25whatsoever. If you're going to check
  319. 13:27them out, please consider using our
  320. 13:28link, which not only will give you
  321. 13:30trading fee discounts, but it will also
  322. 13:32support me in order to make more videos
  323. 13:34like this. And there we go.
  324. 13:37So, by the way, this max draw down here
  325. 13:40is really awesome. It allows me to
  326. 13:43easily add to the size of my position.
  327. 13:45In fact, let's go here and
  328. 13:49increase the size of the position with a
  329. 13:51number such as three.
  330. 13:55And also do the same thing in my short
  331. 13:58positions.
  332. 14:00So, and if I go to the benchmark page, I
  333. 14:03can just rerun both of them
  334. 14:04simultaneously, which is really cool.
  335. 14:06And you know what? While this is going,
  336. 14:08let's also duplicate this one. Go to
  337. 14:10here and back test each year separately.
  338. 14:15So, starting 2021 up until 2022.
  339. 14:19Again, let's enable benchmark.
  340. 14:22Disable interactive charts started.
  341. 14:25Let's do the same since the beginning of
  342. 14:282022 up until 2023.
  343. 14:312023
  344. 14:34up until 2024.
  345. 14:36and since the beginning of 2025 up until
  346. 14:41the sixth month.
  347. 14:45All right. So this is for 2021. We are
  348. 14:49clearly beating the market. The draw
  349. 14:52down is minus 20%, which is great. The
  350. 14:55P&L is 167%. We paid this much in fees.
  351. 15:00So that means if you started with
  352. 15:02$10,000, you would have ended with
  353. 15:0426,700.
  354. 15:07Now the win to loss ratio is 0.65
  355. 15:11and that is because for our take profit
  356. 15:14we're using three times of the ATR and
  357. 15:16for stop loss we're using four times.
  358. 15:19But on the other hand, the win rate is
  359. 15:2071%. So you could say it's more similar
  360. 15:23to a mean reversion rather than a
  361. 15:26typical trend following. The average
  362. 15:28holding time is 44 hours. The sharp
  363. 15:30ratio is 1.98
  364. 15:32which is really great.
  365. 15:35Let's look at 2022.
  366. 15:38So here's the equity curve.
  367. 15:42We ended with 35% P&L. The max return is
  368. 15:45minus 30%. Actually let's just look at
  369. 15:47the equity curves. So this is for 2023.
  370. 15:51We didn't beat the market. I mean in the
  371. 15:54beginning we did but in the end we
  372. 15:55didn't. And this is for 2025, which I
  373. 15:59mean this is just off the charts. Now,
  374. 16:02let's also compare them from the
  375. 16:04benchmark page. Oh, I forgot 2024. So,
  376. 16:08let's also back this one.
  377. 16:15All right, there we go. So, this is also
  378. 16:17really good. So, we made 300% P&L. The
  379. 16:22max done is minus 25%.
  380. 16:25The winner is 75%
  381. 16:28and the win to loss ratio is still 63.
  382. 16:33The sharp ratio is near three which is
  383. 16:37again off the charts. So let's also
  384. 16:40compare them inside the benchmarking
  385. 16:41page. So here are the P&L. They're all
  386. 16:46positive. The maxon is also really good.
  387. 16:49On our best year it was - 9.2%. On our
  388. 16:52worst year it was minus 37%. The sharp
  389. 16:56at the worst year it is 0.8. At the best
  390. 16:59year it is 4.3
  391. 17:04and the annual return is on average
  392. 17:08above 100% for sure. All right. So this
  393. 17:13looks really great. Also let's take a
  394. 17:15look at the equity curve of the whole
  395. 17:174.42
  396. 17:19years. So this is it
  397. 17:22and this is if we consider the price of
  398. 17:25BTC itself. So you see as soon as here
  399. 17:29we are beating the market and then after
  400. 17:31that we were always in profit. But
  401. 17:33here's the thing some people only care
  402. 17:35about the ending number the P&L. They
  403. 17:38read this and they're like wow close to
  404. 17:405,000%. So that means this strategy must
  405. 17:44be making money for me all the time.
  406. 17:46Well that's not true. So if you take a
  407. 17:49closer look at this equity curve, yes we
  408. 17:51ended here which is amazing but we had
  409. 17:55so many draw down periods. So for
  410. 17:57example in here this is 1 2 3 4 5 6 7 8
  411. 18:039 10. So you see for about eight or nine
  412. 18:07months I didn't calculate it exactly we
  413. 18:10were in a draw down period. So that
  414. 18:12means if we started trading the strategy
  415. 18:15let's say from here up until this moment
  416. 18:19we would have been in a loss or if we
  417. 18:21started here we would have been in a
  418. 18:23loss for two or 3 months. Now in here we
  419. 18:29didn't lose much. You could say this is
  420. 18:31a range but still this took one two
  421. 18:35three four five six seven for about
  422. 18:39seven or eight months our equity curve
  423. 18:41would have been flat. So trust me when I
  424. 18:45say if you were trading in this live you
  425. 18:47would not have been happy during this
  426. 18:49period. In fact most of us wouldn't have
  427. 18:52continued trading it and would have
  428. 18:53never seen this huge jump in our equity.
  429. 18:56Now in here it was really great. So no
  430. 18:59complaints. It also did pretty well here
  431. 19:02and here. So yeah, most of the times
  432. 19:04it's making money. It's going up and
  433. 19:06that's really great. But there are draw
  434. 19:09down periods. And I really want to
  435. 19:11emphasize on this that if you are going
  436. 19:13to trade a strategy like this, you
  437. 19:15shouldn't trade all your capital just
  438. 19:17with this one single strategy. In fact,
  439. 19:19you want to have a basket of strategies
  440. 19:22like this one. So that while one of them
  441. 19:24is going through a draw down period like
  442. 19:26in this case for example, your other
  443. 19:28strategy is making money during the same
  444. 19:30period and they're going to offset each
  445. 19:33other. In fact, maybe even instead of
  446. 19:35two strategies, you could run 10 of them
  447. 19:37simultaneously. Now this is a big topic
  448. 19:39that I am going to talk about more maybe
  449. 19:42in a separate video but I just want to
  450. 19:45emphasize that just don't only look at
  451. 19:47the ending number especially P&L because
  452. 19:50at least you want to consider the risk
  453. 19:53and for that read another number such as
  454. 19:55the sharp ratio or calma ratio. I'm
  455. 19:58going to submit the results of this
  456. 20:00strategy and the code on our website's
  457. 20:02strategy page where you can find the
  458. 20:04results of this strategy on different
  459. 20:06symbols and time frames if you are
  460. 20:08curious about that. Also, you can find
  461. 20:10my other strategies and their metrics to
  462. 20:12maybe create your own basket of
  463. 20:14strategies as I just described. Now,
  464. 20:16before I leave, we're going to have a
  465. 20:17giveaway. A random person who likes this
  466. 20:19video, post a comment, and subscribes to
  467. 20:21the channel is going to win 1 million
  468. 20:23bunk token. All right, let's pick the
  469. 20:24winner for the previous video.
  470. 20:28And the winner is Malik. Sorry I cannot
  471. 20:31pronounce your whole name. Thank you so
  472. 20:33much for your comment. Please reach out
  473. 20:34to me so that I can send you your bunk
  474. 20:36tokens. Thanks for watching and I'll see
  475. 20:38you in the next one.
  476. 20:42[Music]

About this transcript

This page contains the full transcript of GPT: Triple moving average strategy in Python makes 4983% by Algo-trading with Saleh, generated from the public captions YouTube serves with the video. The transcript has 3,455 words across 476 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.