YouTube2Text

ChatGPT o1: Turtle Strategy in Python Makes 319% — Transcript

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

Full transcript

  1. 0:00[Music]
  2. 0:00hey guys it's Al today I'm going to code
  3. 0:02the turtle strategy using chat gp01
  4. 0:04preview model to guide me for my entry
  5. 0:07and exit rules it's going to be a fun
  6. 0:09experiment not only that it actually
  7. 0:10taught me about this one new indicator
  8. 0:12that I didn't know before and it
  9. 0:14improved the results of this strategy
  10. 0:16and my previous ones all right let's get
  11. 0:17done it so I simply asked chat GPT how
  12. 0:21does the turtle strategy work explain to
  13. 0:23me the entry and exit rules and how to
  14. 0:25set my stop loss and take profit so in
  15. 0:27case you don't know the turtle trading
  16. 0:28system is a classic Trend following
  17. 0:30system developed in the 1980s by
  18. 0:32legendary Traders Richard Dennis and
  19. 0:34William eart it was part of an
  20. 0:36experiment to determine whether great
  21. 0:38Traders are born or made the strategy
  22. 0:40focuses on entering trades when a strong
  23. 0:42trend is identified and employs specific
  24. 0:45rules for entry exit position sizing and
  25. 0:47risk management okay what's my entry
  26. 0:50role Buy Signal enter a long position
  27. 0:52when the price exceeds the highest high
  28. 0:54of the past 20 days okay and for sell
  29. 0:57signal inter is short position when the
  30. 0:59price Falls below the lowest low of the
  31. 1:01past 20 days so basically this is the
  32. 1:03definition of the donin channel
  33. 1:05indicator in case you didn't know that's
  34. 1:07exactly what it does what else it's also
  35. 1:09saying no re-entry rule If the previous
  36. 1:11breakout would have resulted in a
  37. 1:13profitable trade skip the next breakout
  38. 1:15signal to avoid potential false signals
  39. 1:18and as for position sizing saying to use
  40. 1:20the ATR which is what I always do for
  41. 1:22position sizing risk one or 2% I usually
  42. 1:25do risk 3% that's fine for exit rule is
  43. 1:28saying when the price Falls below the
  44. 1:29lowest low of the past 10 days system to
  45. 1:32exit when the price Falls below the
  46. 1:34lowest low of the past 20 days as for
  47. 1:36take profit saying use a trailing stop
  48. 1:39adj just a stop- loss order as the order
  49. 1:42becomes profitable maintaining the two
  50. 1:44and distance from the highest price
  51. 1:46achieved for long positions or the
  52. 1:47lowest price for short positions the
  53. 1:49position is closed when the exit
  54. 1:51breakout levels are breached okay so
  55. 1:54let's go to Jesse and create a new
  56. 1:56strategy and call it Turtle I because
  57. 2:00we're using AI for our rules I'm going
  58. 2:02to also include the name AI in it now
  59. 2:05let's go to my Pie charm editor and open
  60. 2:08that so first let me show you how the
  61. 2:10donchain channel look like on trading
  62. 2:12view so let's look it
  63. 2:15up and by default the period is set to
  64. 2:1820 which is what chat gbt was also
  65. 2:20telling us all right so you see when a
  66. 2:22new high is achieved the upper band goes
  67. 2:24up so basically the lower band is the
  68. 2:26low of the past 20 candles and the upper
  69. 2:29band is the high of the past 20 candles
  70. 2:31so let's define a new property and call
  71. 2:34it D chin and I'm going to say return ta
  72. 2:38dungeon and going to pass the current
  73. 2:42candles the period is by default 20 so
  74. 2:45we don't really have to set it but let's
  75. 2:47just do it anyways and but there's one
  76. 2:49thing I want to change so for example
  77. 2:51here we had a breakout right but if you
  78. 2:53see the upper band is also going up and
  79. 2:55that's because again it's just simply
  80. 2:57the highest of the past 20 candles right
  81. 2:59so if if the new candles is making a new
  82. 3:01high the value for done chain will also
  83. 3:04go up and that's not really great it's
  84. 3:06going to make it a bit difficult for us
  85. 3:08so instead of using this value I want to
  86. 3:10use the value of the previous scandle
  87. 3:12now we can do this in two ways in jessu
  88. 3:14the first one is that we pass the
  89. 3:17sequential parameter and set it to true
  90. 3:21so that this way in instead of giving us
  91. 3:23one single value is going to give us an
  92. 3:25array of values and then we're going to
  93. 3:27use not just the last value but the one
  94. 3:29before that but we could also do it in
  95. 3:31another way which is to Simply pass not
  96. 3:34just all the candles but we could simply
  97. 3:36not pass the last candle so I'm going to
  98. 3:39say this and here it is so we're saying
  99. 3:42give me all the candles up until the
  100. 3:44last one so it's not going to include
  101. 3:46the last one and by the way if I wanted
  102. 3:48to select all the candles of this nonay
  103. 3:50array I would have done it like this or
  104. 3:52simply just not pass it at all but now
  105. 3:55I'm going to do it like this all right
  106. 3:57so there's that and for our rule as J
  107. 4:01GPT told us we're going to say if the
  108. 4:03current price is more than the upper
  109. 4:05band of the current dchain Channel
  110. 4:09that's it and for our position sizing
  111. 4:12we're going to use the current price as
  112. 4:14our
  113. 4:15entry so it's going to be like this and
  114. 4:18as for the stop we're going to use the
  115. 4:21current price minus the ATR multiplied
  116. 4:24by 2.5 which works best for me and for
  117. 4:28our quantity of of the position is going
  118. 4:30to be utils do risk to quantity our
  119. 4:36capital is going to be self available
  120. 4:38margin the risk number is going to be
  121. 4:40three as for entry price let's say entry
  122. 4:44and then the Stop and the fee rate is
  123. 4:46going to be the current fee of the
  124. 4:48exchange that I'm trading now let's
  125. 4:50submit the buy order which would be self
  126. 4:53FL buy equals quantity and then the
  127. 4:55entry price now for our short position
  128. 4:59we're going to do the
  129. 5:02opposite all right now the shoot cancel
  130. 5:05order it doesn't really matter what we
  131. 5:07enter here because we're using a market
  132. 5:09order to enter our positions if you were
  133. 5:11using a limit order or a sub order the
  134. 5:14value for this would have mattered but
  135. 5:16now it doesn't for the subplus I want to
  136. 5:18do it as soon as the position is open so
  137. 5:19I'm going to say onopen
  138. 5:22position if it's a long position my
  139. 5:27stoploss order is going going to be the
  140. 5:31quantity of the current position and the
  141. 5:34price of it just like what we did
  142. 5:38here it's going to be the current price
  143. 5:41minus 2.5 times of the current ATR value
  144. 5:45now we're going to do the opposite for a
  145. 5:47short position and when I say opposite I
  146. 5:49mean instead of subtracting the ATR we
  147. 5:51are adding it all right so this is good
  148. 5:55now what about our take profit I'm going
  149. 5:57to do what chat gpg suggested here which
  150. 5:59is to use the trailing Stu and I
  151. 6:00actually did try other methods but they
  152. 6:03didn't really work well and I'm not
  153. 6:04going to waste your time with it so I
  154. 6:06will just write this one so I want it to
  155. 6:09be a trailing stop what does it mean we
  156. 6:11are already submitting the subplus order
  157. 6:13when the position opens so now whenever
  158. 6:16a new candle closes we want to update
  159. 6:18our suplus right so we will use the
  160. 6:21update position method which will get
  161. 6:24executed whenever a new candle is closed
  162. 6:27so I'm going to say if it's a long
  163. 6:29position again update my suplus with the
  164. 6:33current quantity and the price instead
  165. 6:37of simply giving it the new price well
  166. 6:39if I do it okay let me show you so if I
  167. 6:42do
  168. 6:43this like this and simply update my St
  169. 6:46plus whenever a new candle closes well
  170. 6:48the problem is that what if the price is
  171. 6:51not going above what if we not in profit
  172. 6:54we're actually sitting in a loss if we
  173. 6:56update our stplus in that case well the
  174. 6:58subplus just keep is going down and it
  175. 7:01never gets hit and that's actually
  176. 7:02horrible so we want to update our stplus
  177. 7:05whenever the new price of the subplus is
  178. 7:08actually better than the previous price
  179. 7:09so for a long position that would be the
  180. 7:12maximum price of the current average
  181. 7:14suplus price which in our case would be
  182. 7:18this or the new stop loss price which
  183. 7:21would be this and for a short position
  184. 7:24we're going to do the opposite so we're
  185. 7:26going to say the minimum of the current
  186. 7:28average stop loss or this new suplus
  187. 7:31price okay so again this is only going
  188. 7:34to submit it if the price is going in
  189. 7:36our favor if we are sitting in profit
  190. 7:39and we for example for a long position
  191. 7:41we want to move up this stplus price
  192. 7:43okay and wice Versa for a short position
  193. 7:46so this looks complete and we can start
  194. 7:49running it and seeing the results okay
  195. 7:51so let's go to Jesse to the back testing
  196. 7:55change
  197. 7:57the strategy to tal a I and the time
  198. 8:00frame is set to 1 hour the symbol is BTC
  199. 8:04UCT the starting point is
  200. 8:082022 up until 2024 all right so the fast
  201. 8:13mode and Benchmark is also enabled so
  202. 8:15let's run it okay so these are the
  203. 8:18results now for the first run is
  204. 8:21actually not bad especially during the
  205. 8:24bare Market it was performing really
  206. 8:27well the max ston is minus 43% which
  207. 8:30isn't
  208. 8:33great okay the V is 30% so at this point
  209. 8:36I went back to chat gbt and I simply
  210. 8:38said I Cod it as a strategy and it
  211. 8:40doesn't always work great what other
  212. 8:42indicators can I use to improve it
  213. 8:44because as you know guys using simply
  214. 8:46one indicator never yields the best
  215. 8:48results we always want to combine at
  216. 8:50least a couple of them to filter out bad
  217. 8:52trades so that the volatility would come
  218. 8:55down the max would come down so I asked
  219. 8:57this and it gave me this suggestions to
  220. 9:00use this a simple moving average to use
  221. 9:02the RSI which I did and it performed
  222. 9:04horribly to use the macd which again
  223. 9:07didn't work for me use the adx which
  224. 9:10always work fine for me at least for
  225. 9:12train following strategies use the
  226. 9:14Ballinger bands which didn't help me use
  227. 9:16the obv support and resistance levels
  228. 9:19which aren't really that useful in algo
  229. 9:21trading
  230. 9:22strategy and that's almost it now so as
  231. 9:27I start coding these this the moving
  232. 9:29average actually worked well now I want
  233. 9:31to use the moving average on a bigger
  234. 9:33time frame so first let's define a new
  235. 9:37property and call it long-term candles
  236. 9:42and in it I'm going to return
  237. 9:45self get candles and pass the current
  238. 9:50exchange the current symbol and the 4
  239. 9:54hours time frame now let's define
  240. 9:55another one and call it longterm
  241. 9:59moving
  242. 10:00average and I'm going to return T
  243. 10:05SMA of the long-term candles so instead
  244. 10:09of passing the current candles I passed
  245. 10:12long-term candles right and as the
  246. 10:16period I'm going to use 200 all right so
  247. 10:19now I'm going to come down and say I
  248. 10:21want to open long positions when the
  249. 10:23current price is above the long-term
  250. 10:25moving average and for shoot short I
  251. 10:29will do the opposite so let's go back
  252. 10:32and run it again all right so now we're
  253. 10:35definitely beating the market we ended
  254. 10:37up with 37% profit the max starton is
  255. 10:40down to 26 the win rate is 33% okay now
  256. 10:44by the way in this strategy because it's
  257. 10:47a trend following and we are trying to
  258. 10:49write the trend for as long as possible
  259. 10:51it's perfectly normal for our win rate
  260. 10:53to be lower than 50% that's perfectly
  261. 10:55normal for as long as our average win to
  262. 10:58loss is more than one and it is in here
  263. 11:01is 2.21 which is amazing all right so
  264. 11:04there's that another suggestion by chbt
  265. 11:07was the adx indicator which is what I
  266. 11:10always use anyways so let's also add
  267. 11:13that let's define a new property and
  268. 11:16return whether or not the current adx
  269. 11:21number is bigger
  270. 11:25than
  271. 11:2730 and for my in Rule now I'm going to
  272. 11:30Simply say and self.
  273. 11:33adx and for short I will also do the
  274. 11:35same let's go back and run it again so
  275. 11:39while this is going I wanted to quickly
  276. 11:40remind you guys that we have a Discord
  277. 11:42Community with more than 3,000 quants
  278. 11:44such as you and I we hang out there
  279. 11:46share ideas and help each other out and
  280. 11:47I would love to see you guys there all
  281. 11:49right so now the EO cure is much more
  282. 11:52smooth than what it was before and I
  283. 11:55really like that and yes the panel also
  284. 11:58got a bit better the Maxon came down a
  285. 12:01bit and the win rate actually went up to
  286. 12:0538% so let's go back to the strategy
  287. 12:07because I want to see the Donan Channel
  288. 12:09values for it so let's define another
  289. 12:12method called after and say self add
  290. 12:16line
  291. 12:18to Candle
  292. 12:20chart and I want the dine so the title
  293. 12:24is going to be the upper
  294. 12:26band and the
  295. 12:28value self dunge in Upper band and one
  296. 12:32more for the lower band so let's go back
  297. 12:34rerun this if I go back now I can see
  298. 12:37the upper and lower bands of the dungeon
  299. 12:39channels and one issue that I had with
  300. 12:41it which after plotting it on the chart
  301. 12:44I could see is that sometimes like in
  302. 12:47here there's a breakout it opens a
  303. 12:49position it closes it but when it does
  304. 12:52close it because the price is actually
  305. 12:54below the lower band it immediately
  306. 12:56opens another trade and I don't want to
  307. 12:58open a trade here now in this case it's
  308. 13:00not really that bad but in some cases it
  309. 13:02was horrible so I wanted to Cote this so
  310. 13:05that once you close a trade do not take
  311. 13:08another trade right right in the same
  312. 13:10candle all right just wait at least one
  313. 13:12more so for that we have to define a new
  314. 13:16variable just to hold the last index
  315. 13:20that we closed our trade so I'm going to
  316. 13:22call it last
  317. 13:25closed
  318. 13:27index and I'm I'm going to set it to
  319. 13:30zero and we need to update this whenever
  320. 13:33a trade is closed right so for that I'm
  321. 13:35going to
  322. 13:36say unclosed position I need you to
  323. 13:40update the last Clos index and set it to
  324. 13:43the current Index right and for my ING
  325. 13:49rules let's define a new property and
  326. 13:51call
  327. 13:52it past time and in it I'm going to say
  328. 13:57whether or not the current index minus
  329. 14:02the last close index is more than zero
  330. 14:06that's it so if it's even one that's
  331. 14:09okay but if it's zero it means it's in
  332. 14:11this current candle and just don't take
  333. 14:13any trades so let's go back and rerun
  334. 14:17this all right so I forgot to add it to
  335. 14:21this Shong and shoot
  336. 14:26short all right so let's go back and run
  337. 14:28it again
  338. 14:30all right so you see the pnl actually
  339. 14:32went up and the max ORD came down just
  340. 14:35with this one single
  341. 14:37change and everything else is actually
  342. 14:40pretty much the same such as the wing
  343. 14:41rate so that's why the results improved
  344. 14:44all right so at this point this is the
  345. 14:46result that I had but I wasn't super
  346. 14:48happy with it and I wanted to improve it
  347. 14:50again so here's what I did I went back
  348. 14:53and ask the same questions but this time
  349. 14:56not from chat gbt o1 preview but from
  350. 14:59chity for all model and it gave me
  351. 15:03pretty much the same result except it
  352. 15:05suggested this which changed everything
  353. 15:08for me it said the choppiness index
  354. 15:12purpose this is a lesser known but
  355. 15:14powerful indicator to measure Market
  356. 15:16consolidation choppy versus trending
  357. 15:18condition conditions and that's exactly
  358. 15:20what we always want in a trend following
  359. 15:21strategy right and that's why we use the
  360. 15:23adx always so it's saying if the
  361. 15:25choppiness index is high avoid taking
  362. 15:27breakout trades because the market is
  363. 15:30likely to be ranging only take trades
  364. 15:32when the choppiness index is low
  365. 15:34indicating that the market is in a
  366. 15:35training phase so let's go back and code
  367. 15:40it so I'm going to
  368. 15:44say the let's call it chop and say
  369. 15:49whether or
  370. 15:50not the Chop for the current candles are
  371. 15:55below
  372. 15:5640 and come down here
  373. 16:00and add this as another entry
  374. 16:04rule go back to Jesse and rerun this and
  375. 16:09look at that our panl went up the equity
  376. 16:13Cur looks much better the max Ron came
  377. 16:16down to minus 133% so this means we can
  378. 16:19add to our position to get the same Max
  379. 16:21Ron as before but this time we would get
  380. 16:23even better panl I'm going to show you
  381. 16:25that in a minute so the win rate
  382. 16:27actually went up to 40 % the average win
  383. 16:31to loss is 2.49 which is absolutely
  384. 16:35amazing and the sharp is
  385. 16:381.05 all right so why do I say the max Z
  386. 16:42here is really important now what did we
  387. 16:44have before actually let's bring this
  388. 16:46back and go to here and just return true
  389. 16:50so that this won't be used anymore and
  390. 16:53run it again to see what numbers we had
  391. 16:56now
  392. 16:57here the Max zon was-
  393. 17:0020% and the panl was 40 here the max zon
  394. 17:04isus 133% so that means I can just go to
  395. 17:09my code and if I return the chop but
  396. 17:12this time add to my position let's say
  397. 17:14multiply it by a number such as
  398. 17:181.8 to use leverage in other
  399. 17:22words and go back and run it
  400. 17:27again this time when we get
  401. 17:29approximately the same Max Thro number
  402. 17:32the p&l instead of 40% is now at
  403. 17:37106% which is pretty amazing all right
  404. 17:40so I really like these numbers and I'm
  405. 17:43going to submit this strategy for free
  406. 17:45on our strategy index page so if you
  407. 17:47want to use source code you can just
  408. 17:48copy it from there but I also kept
  409. 17:51working on it and tweak the parameters a
  410. 17:53bit did some optimization and I was able
  411. 17:55to improve the results up to this so
  412. 17:59instead of 100% for a Max ofus
  413. 18:0322% I got it up to
  414. 18:0739% with a Max Run of minus 18% so it
  415. 18:11was a huge jump in the results and I'm
  416. 18:13going to also submit this one as a
  417. 18:15premium strategy again to our strategy
  418. 18:17indexing page I hope you guys learned
  419. 18:18something from this video I know I did
  420. 18:20especially the choppiness index
  421. 18:22indicator which I didn't know about
  422. 18:24before and if you guys want me to create
  423. 18:26more videos like this one please let me
  424. 18:27know and by the way I've been working on
  425. 18:29some other types of strategies such as
  426. 18:31GRE trading and also trading using
  427. 18:33Fibonacci lines and the results of them
  428. 18:35weren't really great so that's why I
  429. 18:37haven't created a video about them yet
  430. 18:39but if you guys want me to make videos
  431. 18:41about experiments that are really fun
  432. 18:43and something that you might be curious
  433. 18:45about too but the results just aren't
  434. 18:47that profitable let me know down in the
  435. 18:49comments and as always we're going to
  436. 18:50have a giveaway a random person who
  437. 18:51likes this video post a comment and
  438. 18:53subscrib to the channel is going to
  439. 18:55receive 1 million bnk token let's pick
  440. 18:56the winner for my previous video
  441. 19:00and the winner is this was great thank
  442. 19:02you so much for your comment please
  443. 19:03reach out to me so that I can send you
  444. 19:05your bunk tokens thanks for watching
  445. 19:06guys and I'll see you in the next one
  446. 19:09[Music]

About this transcript

This page contains the full transcript of ChatGPT o1: Turtle Strategy in Python Makes 319% by Algo-trading with Saleh, generated from the public captions YouTube serves with the video. The transcript has 3,291 words across 446 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.