ChatGPT o1: Turtle Strategy in Python Makes 319% — Transcript
Full transcript
- 0:00[Music]
- 0:00hey guys it's Al today I'm going to code
- 0:02the turtle strategy using chat gp01
- 0:04preview model to guide me for my entry
- 0:07and exit rules it's going to be a fun
- 0:09experiment not only that it actually
- 0:10taught me about this one new indicator
- 0:12that I didn't know before and it
- 0:14improved the results of this strategy
- 0:16and my previous ones all right let's get
- 0:17done it so I simply asked chat GPT how
- 0:21does the turtle strategy work explain to
- 0:23me the entry and exit rules and how to
- 0:25set my stop loss and take profit so in
- 0:27case you don't know the turtle trading
- 0:28system is a classic Trend following
- 0:30system developed in the 1980s by
- 0:32legendary Traders Richard Dennis and
- 0:34William eart it was part of an
- 0:36experiment to determine whether great
- 0:38Traders are born or made the strategy
- 0:40focuses on entering trades when a strong
- 0:42trend is identified and employs specific
- 0:45rules for entry exit position sizing and
- 0:47risk management okay what's my entry
- 0:50role Buy Signal enter a long position
- 0:52when the price exceeds the highest high
- 0:54of the past 20 days okay and for sell
- 0:57signal inter is short position when the
- 0:59price Falls below the lowest low of the
- 1:01past 20 days so basically this is the
- 1:03definition of the donin channel
- 1:05indicator in case you didn't know that's
- 1:07exactly what it does what else it's also
- 1:09saying no re-entry rule If the previous
- 1:11breakout would have resulted in a
- 1:13profitable trade skip the next breakout
- 1:15signal to avoid potential false signals
- 1:18and as for position sizing saying to use
- 1:20the ATR which is what I always do for
- 1:22position sizing risk one or 2% I usually
- 1:25do risk 3% that's fine for exit rule is
- 1:28saying when the price Falls below the
- 1:29lowest low of the past 10 days system to
- 1:32exit when the price Falls below the
- 1:34lowest low of the past 20 days as for
- 1:36take profit saying use a trailing stop
- 1:39adj just a stop- loss order as the order
- 1:42becomes profitable maintaining the two
- 1:44and distance from the highest price
- 1:46achieved for long positions or the
- 1:47lowest price for short positions the
- 1:49position is closed when the exit
- 1:51breakout levels are breached okay so
- 1:54let's go to Jesse and create a new
- 1:56strategy and call it Turtle I because
- 2:00we're using AI for our rules I'm going
- 2:02to also include the name AI in it now
- 2:05let's go to my Pie charm editor and open
- 2:08that so first let me show you how the
- 2:10donchain channel look like on trading
- 2:12view so let's look it
- 2:15up and by default the period is set to
- 2:1820 which is what chat gbt was also
- 2:20telling us all right so you see when a
- 2:22new high is achieved the upper band goes
- 2:24up so basically the lower band is the
- 2:26low of the past 20 candles and the upper
- 2:29band is the high of the past 20 candles
- 2:31so let's define a new property and call
- 2:34it D chin and I'm going to say return ta
- 2:38dungeon and going to pass the current
- 2:42candles the period is by default 20 so
- 2:45we don't really have to set it but let's
- 2:47just do it anyways and but there's one
- 2:49thing I want to change so for example
- 2:51here we had a breakout right but if you
- 2:53see the upper band is also going up and
- 2:55that's because again it's just simply
- 2:57the highest of the past 20 candles right
- 2:59so if if the new candles is making a new
- 3:01high the value for done chain will also
- 3:04go up and that's not really great it's
- 3:06going to make it a bit difficult for us
- 3:08so instead of using this value I want to
- 3:10use the value of the previous scandle
- 3:12now we can do this in two ways in jessu
- 3:14the first one is that we pass the
- 3:17sequential parameter and set it to true
- 3:21so that this way in instead of giving us
- 3:23one single value is going to give us an
- 3:25array of values and then we're going to
- 3:27use not just the last value but the one
- 3:29before that but we could also do it in
- 3:31another way which is to Simply pass not
- 3:34just all the candles but we could simply
- 3:36not pass the last candle so I'm going to
- 3:39say this and here it is so we're saying
- 3:42give me all the candles up until the
- 3:44last one so it's not going to include
- 3:46the last one and by the way if I wanted
- 3:48to select all the candles of this nonay
- 3:50array I would have done it like this or
- 3:52simply just not pass it at all but now
- 3:55I'm going to do it like this all right
- 3:57so there's that and for our rule as J
- 4:01GPT told us we're going to say if the
- 4:03current price is more than the upper
- 4:05band of the current dchain Channel
- 4:09that's it and for our position sizing
- 4:12we're going to use the current price as
- 4:14our
- 4:15entry so it's going to be like this and
- 4:18as for the stop we're going to use the
- 4:21current price minus the ATR multiplied
- 4:24by 2.5 which works best for me and for
- 4:28our quantity of of the position is going
- 4:30to be utils do risk to quantity our
- 4:36capital is going to be self available
- 4:38margin the risk number is going to be
- 4:40three as for entry price let's say entry
- 4:44and then the Stop and the fee rate is
- 4:46going to be the current fee of the
- 4:48exchange that I'm trading now let's
- 4:50submit the buy order which would be self
- 4:53FL buy equals quantity and then the
- 4:55entry price now for our short position
- 4:59we're going to do the
- 5:02opposite all right now the shoot cancel
- 5:05order it doesn't really matter what we
- 5:07enter here because we're using a market
- 5:09order to enter our positions if you were
- 5:11using a limit order or a sub order the
- 5:14value for this would have mattered but
- 5:16now it doesn't for the subplus I want to
- 5:18do it as soon as the position is open so
- 5:19I'm going to say onopen
- 5:22position if it's a long position my
- 5:27stoploss order is going going to be the
- 5:31quantity of the current position and the
- 5:34price of it just like what we did
- 5:38here it's going to be the current price
- 5:41minus 2.5 times of the current ATR value
- 5:45now we're going to do the opposite for a
- 5:47short position and when I say opposite I
- 5:49mean instead of subtracting the ATR we
- 5:51are adding it all right so this is good
- 5:55now what about our take profit I'm going
- 5:57to do what chat gpg suggested here which
- 5:59is to use the trailing Stu and I
- 6:00actually did try other methods but they
- 6:03didn't really work well and I'm not
- 6:04going to waste your time with it so I
- 6:06will just write this one so I want it to
- 6:09be a trailing stop what does it mean we
- 6:11are already submitting the subplus order
- 6:13when the position opens so now whenever
- 6:16a new candle closes we want to update
- 6:18our suplus right so we will use the
- 6:21update position method which will get
- 6:24executed whenever a new candle is closed
- 6:27so I'm going to say if it's a long
- 6:29position again update my suplus with the
- 6:33current quantity and the price instead
- 6:37of simply giving it the new price well
- 6:39if I do it okay let me show you so if I
- 6:42do
- 6:43this like this and simply update my St
- 6:46plus whenever a new candle closes well
- 6:48the problem is that what if the price is
- 6:51not going above what if we not in profit
- 6:54we're actually sitting in a loss if we
- 6:56update our stplus in that case well the
- 6:58subplus just keep is going down and it
- 7:01never gets hit and that's actually
- 7:02horrible so we want to update our stplus
- 7:05whenever the new price of the subplus is
- 7:08actually better than the previous price
- 7:09so for a long position that would be the
- 7:12maximum price of the current average
- 7:14suplus price which in our case would be
- 7:18this or the new stop loss price which
- 7:21would be this and for a short position
- 7:24we're going to do the opposite so we're
- 7:26going to say the minimum of the current
- 7:28average stop loss or this new suplus
- 7:31price okay so again this is only going
- 7:34to submit it if the price is going in
- 7:36our favor if we are sitting in profit
- 7:39and we for example for a long position
- 7:41we want to move up this stplus price
- 7:43okay and wice Versa for a short position
- 7:46so this looks complete and we can start
- 7:49running it and seeing the results okay
- 7:51so let's go to Jesse to the back testing
- 7:55change
- 7:57the strategy to tal a I and the time
- 8:00frame is set to 1 hour the symbol is BTC
- 8:04UCT the starting point is
- 8:082022 up until 2024 all right so the fast
- 8:13mode and Benchmark is also enabled so
- 8:15let's run it okay so these are the
- 8:18results now for the first run is
- 8:21actually not bad especially during the
- 8:24bare Market it was performing really
- 8:27well the max ston is minus 43% which
- 8:30isn't
- 8:33great okay the V is 30% so at this point
- 8:36I went back to chat gbt and I simply
- 8:38said I Cod it as a strategy and it
- 8:40doesn't always work great what other
- 8:42indicators can I use to improve it
- 8:44because as you know guys using simply
- 8:46one indicator never yields the best
- 8:48results we always want to combine at
- 8:50least a couple of them to filter out bad
- 8:52trades so that the volatility would come
- 8:55down the max would come down so I asked
- 8:57this and it gave me this suggestions to
- 9:00use this a simple moving average to use
- 9:02the RSI which I did and it performed
- 9:04horribly to use the macd which again
- 9:07didn't work for me use the adx which
- 9:10always work fine for me at least for
- 9:12train following strategies use the
- 9:14Ballinger bands which didn't help me use
- 9:16the obv support and resistance levels
- 9:19which aren't really that useful in algo
- 9:21trading
- 9:22strategy and that's almost it now so as
- 9:27I start coding these this the moving
- 9:29average actually worked well now I want
- 9:31to use the moving average on a bigger
- 9:33time frame so first let's define a new
- 9:37property and call it long-term candles
- 9:42and in it I'm going to return
- 9:45self get candles and pass the current
- 9:50exchange the current symbol and the 4
- 9:54hours time frame now let's define
- 9:55another one and call it longterm
- 9:59moving
- 10:00average and I'm going to return T
- 10:05SMA of the long-term candles so instead
- 10:09of passing the current candles I passed
- 10:12long-term candles right and as the
- 10:16period I'm going to use 200 all right so
- 10:19now I'm going to come down and say I
- 10:21want to open long positions when the
- 10:23current price is above the long-term
- 10:25moving average and for shoot short I
- 10:29will do the opposite so let's go back
- 10:32and run it again all right so now we're
- 10:35definitely beating the market we ended
- 10:37up with 37% profit the max starton is
- 10:40down to 26 the win rate is 33% okay now
- 10:44by the way in this strategy because it's
- 10:47a trend following and we are trying to
- 10:49write the trend for as long as possible
- 10:51it's perfectly normal for our win rate
- 10:53to be lower than 50% that's perfectly
- 10:55normal for as long as our average win to
- 10:58loss is more than one and it is in here
- 11:01is 2.21 which is amazing all right so
- 11:04there's that another suggestion by chbt
- 11:07was the adx indicator which is what I
- 11:10always use anyways so let's also add
- 11:13that let's define a new property and
- 11:16return whether or not the current adx
- 11:21number is bigger
- 11:25than
- 11:2730 and for my in Rule now I'm going to
- 11:30Simply say and self.
- 11:33adx and for short I will also do the
- 11:35same let's go back and run it again so
- 11:39while this is going I wanted to quickly
- 11:40remind you guys that we have a Discord
- 11:42Community with more than 3,000 quants
- 11:44such as you and I we hang out there
- 11:46share ideas and help each other out and
- 11:47I would love to see you guys there all
- 11:49right so now the EO cure is much more
- 11:52smooth than what it was before and I
- 11:55really like that and yes the panel also
- 11:58got a bit better the Maxon came down a
- 12:01bit and the win rate actually went up to
- 12:0538% so let's go back to the strategy
- 12:07because I want to see the Donan Channel
- 12:09values for it so let's define another
- 12:12method called after and say self add
- 12:16line
- 12:18to Candle
- 12:20chart and I want the dine so the title
- 12:24is going to be the upper
- 12:26band and the
- 12:28value self dunge in Upper band and one
- 12:32more for the lower band so let's go back
- 12:34rerun this if I go back now I can see
- 12:37the upper and lower bands of the dungeon
- 12:39channels and one issue that I had with
- 12:41it which after plotting it on the chart
- 12:44I could see is that sometimes like in
- 12:47here there's a breakout it opens a
- 12:49position it closes it but when it does
- 12:52close it because the price is actually
- 12:54below the lower band it immediately
- 12:56opens another trade and I don't want to
- 12:58open a trade here now in this case it's
- 13:00not really that bad but in some cases it
- 13:02was horrible so I wanted to Cote this so
- 13:05that once you close a trade do not take
- 13:08another trade right right in the same
- 13:10candle all right just wait at least one
- 13:12more so for that we have to define a new
- 13:16variable just to hold the last index
- 13:20that we closed our trade so I'm going to
- 13:22call it last
- 13:25closed
- 13:27index and I'm I'm going to set it to
- 13:30zero and we need to update this whenever
- 13:33a trade is closed right so for that I'm
- 13:35going to
- 13:36say unclosed position I need you to
- 13:40update the last Clos index and set it to
- 13:43the current Index right and for my ING
- 13:49rules let's define a new property and
- 13:51call
- 13:52it past time and in it I'm going to say
- 13:57whether or not the current index minus
- 14:02the last close index is more than zero
- 14:06that's it so if it's even one that's
- 14:09okay but if it's zero it means it's in
- 14:11this current candle and just don't take
- 14:13any trades so let's go back and rerun
- 14:17this all right so I forgot to add it to
- 14:21this Shong and shoot
- 14:26short all right so let's go back and run
- 14:28it again
- 14:30all right so you see the pnl actually
- 14:32went up and the max ORD came down just
- 14:35with this one single
- 14:37change and everything else is actually
- 14:40pretty much the same such as the wing
- 14:41rate so that's why the results improved
- 14:44all right so at this point this is the
- 14:46result that I had but I wasn't super
- 14:48happy with it and I wanted to improve it
- 14:50again so here's what I did I went back
- 14:53and ask the same questions but this time
- 14:56not from chat gbt o1 preview but from
- 14:59chity for all model and it gave me
- 15:03pretty much the same result except it
- 15:05suggested this which changed everything
- 15:08for me it said the choppiness index
- 15:12purpose this is a lesser known but
- 15:14powerful indicator to measure Market
- 15:16consolidation choppy versus trending
- 15:18condition conditions and that's exactly
- 15:20what we always want in a trend following
- 15:21strategy right and that's why we use the
- 15:23adx always so it's saying if the
- 15:25choppiness index is high avoid taking
- 15:27breakout trades because the market is
- 15:30likely to be ranging only take trades
- 15:32when the choppiness index is low
- 15:34indicating that the market is in a
- 15:35training phase so let's go back and code
- 15:40it so I'm going to
- 15:44say the let's call it chop and say
- 15:49whether or
- 15:50not the Chop for the current candles are
- 15:55below
- 15:5640 and come down here
- 16:00and add this as another entry
- 16:04rule go back to Jesse and rerun this and
- 16:09look at that our panl went up the equity
- 16:13Cur looks much better the max Ron came
- 16:16down to minus 133% so this means we can
- 16:19add to our position to get the same Max
- 16:21Ron as before but this time we would get
- 16:23even better panl I'm going to show you
- 16:25that in a minute so the win rate
- 16:27actually went up to 40 % the average win
- 16:31to loss is 2.49 which is absolutely
- 16:35amazing and the sharp is
- 16:381.05 all right so why do I say the max Z
- 16:42here is really important now what did we
- 16:44have before actually let's bring this
- 16:46back and go to here and just return true
- 16:50so that this won't be used anymore and
- 16:53run it again to see what numbers we had
- 16:56now
- 16:57here the Max zon was-
- 17:0020% and the panl was 40 here the max zon
- 17:04isus 133% so that means I can just go to
- 17:09my code and if I return the chop but
- 17:12this time add to my position let's say
- 17:14multiply it by a number such as
- 17:181.8 to use leverage in other
- 17:22words and go back and run it
- 17:27again this time when we get
- 17:29approximately the same Max Thro number
- 17:32the p&l instead of 40% is now at
- 17:37106% which is pretty amazing all right
- 17:40so I really like these numbers and I'm
- 17:43going to submit this strategy for free
- 17:45on our strategy index page so if you
- 17:47want to use source code you can just
- 17:48copy it from there but I also kept
- 17:51working on it and tweak the parameters a
- 17:53bit did some optimization and I was able
- 17:55to improve the results up to this so
- 17:59instead of 100% for a Max ofus
- 18:0322% I got it up to
- 18:0739% with a Max Run of minus 18% so it
- 18:11was a huge jump in the results and I'm
- 18:13going to also submit this one as a
- 18:15premium strategy again to our strategy
- 18:17indexing page I hope you guys learned
- 18:18something from this video I know I did
- 18:20especially the choppiness index
- 18:22indicator which I didn't know about
- 18:24before and if you guys want me to create
- 18:26more videos like this one please let me
- 18:27know and by the way I've been working on
- 18:29some other types of strategies such as
- 18:31GRE trading and also trading using
- 18:33Fibonacci lines and the results of them
- 18:35weren't really great so that's why I
- 18:37haven't created a video about them yet
- 18:39but if you guys want me to make videos
- 18:41about experiments that are really fun
- 18:43and something that you might be curious
- 18:45about too but the results just aren't
- 18:47that profitable let me know down in the
- 18:49comments and as always we're going to
- 18:50have a giveaway a random person who
- 18:51likes this video post a comment and
- 18:53subscrib to the channel is going to
- 18:55receive 1 million bnk token let's pick
- 18:56the winner for my previous video
- 19:00and the winner is this was great thank
- 19:02you so much for your comment please
- 19:03reach out to me so that I can send you
- 19:05your bunk tokens thanks for watching
- 19:06guys and I'll see you in the next one
- 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.