GPT: Triple moving average strategy in Python makes 4983% — Transcript
Full transcript
- 0:00Hey guys, it's So today I'm going to
- 0:01show you a strategy which is super
- 0:04simple and yet the result of it is
- 0:06pretty great. It's a trend following
- 0:08strategy, but you could kind of say it's
- 0:10a mini version because we're going to
- 0:12use limit order to open the position at
- 0:14a pullback. Now, I'm not going to write
- 0:16the code of the strategy myself.
- 0:17Instead, I will be using GPT to convert
- 0:20the logic of the strategy. So that means
- 0:22the entry and the exit rules of it into
- 0:24Python code so we can run some back test
- 0:27on it and see some charts and numbers.
- 0:29So you're going to see that even if your
- 0:30Python knowledge isn't great, you can
- 0:32get started. So if that sounds good,
- 0:34let's get to it. The main indicator of
- 0:36this strategy is called TEMO, which is
- 0:38stands for triple exponential moving
- 0:40average. So let's look it up on Trading
- 0:42View
- 0:45and add two of it. Change the period of
- 0:49them to be 10
- 0:54and
- 0:5680.
- 0:59Now the entry rule is very simple. When
- 1:01this orange line which is temo with the
- 1:03period of 10 goes above the purple line
- 1:06which is temo with the period of 80, we
- 1:09consider that an uptrend. When it's vice
- 1:11versa, we consider it a downtrend. But
- 1:13first I want to show you the difference
- 1:15between tema indicator and the good old
- 1:17EMA. So let's disable the one with the
- 1:20period of 80 for a second. Add a regular
- 1:24EMA.
- 1:26change its period to equal the same
- 1:29which is 10. All right. So this orange
- 1:31line here is tema with the period of 10
- 1:35and the blue one is EMA with the period
- 1:37of 10. So they have the same period but
- 1:39let's see how they behave. So for
- 1:41instance in here you see when the price
- 1:43starts to go up the TMA indicator which
- 1:46again is this orange line it starts to
- 1:48go up way faster. And for example, in
- 1:51here where the price starts to go down,
- 1:53you can see the Tema line goes down way
- 1:56faster. Now to summarize it, you know
- 1:57the issue with moving averages, which is
- 1:59their lagging indicators. Well, if you
- 2:02use Tema instead of the good old EMA,
- 2:04you're going to have less lag. Or in
- 2:06other words, it moves significantly
- 2:09faster. All right, so let's change this
- 2:12back to what it was. bring back the ter
- 2:15with the period of 80 to have our inter
- 2:19rule. Now the second rule of the
- 2:20strategy is that we don't want to just
- 2:22look into the short-term trend. We also
- 2:24want to look at the long-term trend. Now
- 2:27for that I'm going to use the same
- 2:28indicator except with values of 20 and
- 2:3070 but on the bigger time frame
- 2:33specifically I want to use the 4our time
- 2:35frame. Now before I forget the trading
- 2:37time frame for this strategy is 30
- 2:39minutes which is why it is considered a
- 2:42day trading strategy. All right. Next,
- 2:44we want to use a volatility filter. And
- 2:46as most of my strategies, I'm going to
- 2:48use the ADX in here.
- 2:52So, basically, whenever this red line
- 2:54goes above the green line here, which is
- 2:56our threshold, we want to take the trade
- 2:58or for example in here. All right. Next,
- 3:00I want to use some kind of oscillator.
- 3:02And for this strategy, I'm going to use
- 3:04the Shae momentum indicator. So, let's
- 3:07look it up on Trading View.
- 3:12Now it is some kind of oscillator very
- 3:14similar to RSI. But the main difference
- 3:16you should care about is that it moves
- 3:19faster. It is more sensitive to the
- 3:21price change. So just like the TME
- 3:23indicator which was more sensitive to
- 3:24the good old EMA, the Shanda momentum
- 3:27oscillator or CMO for short is also more
- 3:31sensitive compared to a traditional
- 3:33oscillator such as the RSI. And the
- 3:35inter rule is very simple. So the
- 3:37threshold is at 40 and also minus 40. So
- 3:41basically whenever this line is above
- 3:44our threshold we want to look for long
- 3:46trades and whenever it is below minus 40
- 3:49we want to look for short trades. All
- 3:50right. So now we have all the entry
- 3:52rules of the strategy. And as for the
- 3:54position sizing as always I'm going to
- 3:56risk 3% of my capital per each trade.
- 3:59But for the entry price what I want to
- 4:01do is I want to use a limit order
- 4:03because I want to buy at a pullback. So
- 4:06I'm going to keep it simple. I will buy
- 4:07at 180R below the current price for a
- 4:10long position and do the opposite for a
- 4:13short position. All right. So I think
- 4:14now is a good time to actually go and
- 4:16code this thing so we can run some back
- 4:18test. Now to use this service you have
- 4:19two options. One is to use the cloud
- 4:21version which is hosted by us which you
- 4:24need to sign up for free to get started
- 4:26with or you can watch my previous video
- 4:28where I explain how to self-hosted by
- 4:31yourself which is better if you have
- 4:32privacy concerns or let's say you want
- 4:34to use premium models without paying us
- 4:36anything. So choose one of the two but
- 4:39in this video I'm going to use the cloud
- 4:41version as the LLM model. I have
- 4:43selected cloud 3.7 set. You can select
- 4:46whichever you think works best but in my
- 4:48cases cloud usually works best. And as
- 4:51for the instruction here it is. So right
- 4:54trend following strategy the short-term
- 4:56trend must be one representing an
- 4:58uptrend. To determine this use the tema
- 5:00indicator with a period of 10 which
- 5:02should be above the temo with a period
- 5:04of 80. If it's vice versa the trend is
- 5:06down. So you know basically just what I
- 5:08showed you. For the long-term trend, use
- 5:10the same indicator over the period of 20
- 5:12and 70. So, let's also ask it to use the
- 5:154 hours time frame except to use
- 5:19the 4 hours time frame. For volatility
- 5:23filter, use the ADX indicator. Its
- 5:25values must be above 40 to take any
- 5:27trades. Also, use the CH momentum
- 5:29indicator as an oscalator. For long
- 5:32trades, it value must be above 40. For
- 5:34short trades, do the exact opposite of
- 5:37the above conditions. For position
- 5:38sizing, risk 3% of the available margin
- 5:41per trade. For the entry price of the
- 5:43trades, use a limit order ATR below the
- 5:46entry price. For the stop loss, you use
- 5:48four times of the current ATR below the
- 5:50entry price. For exiting the trade, the
- 5:52stop loss must be as described above.
- 5:54And the takerit must be three times the
- 5:56ATR indicator. And that's it. So, I just
- 5:59told it basically what I need, just the
- 6:01entry and exit rules. So, let's hit
- 6:04enter and see how it writes the code.
- 6:07All
- 6:09right. So, here it is. This is the
- 6:10short-term trend. It's using Tema with a
- 6:12period of 10 and 80. It's returning
- 6:15either one or minus one. For long-term
- 6:17trend, it is using the first time frame
- 6:20and periods of 20 and 70, which is
- 6:22exactly what I ask for. Then need to
- 6:25find the ATR, the ADX, the CMO, and for
- 6:30shoot long, which is where we specify
- 6:32the inter rules of the strategy. For
- 6:34short positions, it's saying the
- 6:35short-term trend must be one, the
- 6:37long-term trend must be one, the ADX
- 6:39must be above 40, and so should the CMO.
- 6:42For uh for short positions, it's saying
- 6:45that the trends must be minus one, the
- 6:48ADX must be above 40, the CMO must be
- 6:51below minus 40. For position sizing, the
- 6:54entry price is a limit order one ATR
- 6:57below the current price. This is
- 6:58correct. The stop loss is four times of
- 7:00the current ATR minus the entry price.
- 7:03It is risking 3% using the riskto
- 7:05quantity utility function of Jesse to
- 7:07make sure we never lose more than 3% of
- 7:10our total capital per each trade. By the
- 7:13way, this doesn't mean to close the
- 7:15position when it goes 3% against us. It
- 7:17closes it when we are losing 3% of our
- 7:20total capital. It's a bit different. And
- 7:22then it is submitting the order using a
- 7:25buy order. The first parameter is the
- 7:27quantity of it and the second is the
- 7:29price. Now for short trades, it is doing
- 7:31the opposite which is correct. Now this
- 7:34one also must be here and return true.
- 7:37Now what it does is because we're using
- 7:39limit orders. What would happen if we
- 7:41submit the order but it doesn't get
- 7:43filled during that candle? Well, when
- 7:45the next candle comes, we want to cancel
- 7:47the previous one and submit a new order
- 7:50using the current conditions such as the
- 7:52current ATR value. And when the position
- 7:54opens, it submits a stop loss like this.
- 7:58Four times the current ATR minus the
- 8:00enterprise of the position. And it is
- 8:02also using the quantity of the current
- 8:04position for the stop loss. For the take
- 8:07profit, it's doing exactly the same
- 8:09except three times the ATR. Also,
- 8:12instead of subtracting the price, it is
- 8:14adding it. And for a short position,
- 8:16it's doing exactly the opposite. So,
- 8:18this is perfect. So, let's go up here
- 8:23and copy the whole thing. Go to J's
- 8:26dashboard and go to new strategy. I'm
- 8:29going to call it tema
- 8:32trend following.
- 8:37Let's paste the whole thing here.
- 8:41Go to back testing page. The exchange is
- 8:44Binance perpetual futures. The route BTC
- 8:47UCT is correct. The trading time frame
- 8:49must be 30 minutes. Here, let's choose
- 8:52tema trend following. We also have one
- 8:56data route because we're using the
- 8:58bigger time frame which is 4 hours with
- 9:01the same symbol. And let's begin by back
- 9:04testing the first six month of 2025.
- 9:10Let's enable the interactive charts, the
- 9:14fast mode, and the benchmark feature.
- 9:16So, let's run it.
- 9:21And there it is. So, let's scroll down.
- 9:24The P&L is 32%. The maxon is minus 3%,
- 9:29which is crazy.
- 9:31The win rate is 81%. The average holding
- 9:35time is 12 hours. The sharp ratio is
- 9:374.34.
- 9:39Now, by the way, this is a bit too good
- 9:41to be true. Like, yes, we're getting it
- 9:43on 2025, but I don't expect it to be
- 9:45this good in all the periods. And I'm
- 9:48going to back test it on other periods
- 9:50just in a second. Let's take a look at
- 9:52the interactive charts. So, we can see
- 9:55the type of trades that it took. So, for
- 9:56instance, it opens it here and closes it
- 10:00here. It opens it here and closes it
- 10:03here. We can also see the trades here.
- 10:06And let's see there's one that I really
- 10:08want to see like this one. I can just
- 10:11click on it and it will take me to it.
- 10:15Right? So this is where we sold and this
- 10:18is where we close our short with a loss.
- 10:24Then again we have here and if you want
- 10:26to see the details of any trade by the
- 10:28way click on it and you can see the
- 10:30orders. And then if you click on just
- 10:32any of them, you can also see other
- 10:34metrics such as the quantity of that
- 10:36trade, the entry price, exit price, the
- 10:39fees that we paid, and the P&L. But
- 10:41actually something really helpful with
- 10:43these strategies is to see the indicator
- 10:46values when we are taking the trade. So
- 10:49let's go back to Jessie GPT and simply
- 10:52ask the AI to add the values for us. I
- 10:56need you to add values for the charts so
- 10:58I can debug the strategy.
- 11:05All right. So it added this after
- 11:07function here which will do just that.
- 11:11So let's copy the whole thing. Go to
- 11:14this is dashboard. Press new session.
- 11:17Click here to see the code of the
- 11:19strategy and paste the whole thing here.
- 11:21Now, by the way, this watch list that it
- 11:22added is really helpful, but only if you
- 11:25are trading the strategy live. So, it's
- 11:27not really for back testing. So, I'm
- 11:29going to remove this. And let's go back
- 11:33here and click the back test one more
- 11:36time. Let's go to view charts. And now,
- 11:41not only we can see the trades, we can
- 11:43also see the demo values. So, 10 and 80
- 11:47periods. We can also see the ADX. So for
- 11:50example when it opened this long
- 11:53position we can see the ADX value is
- 11:55indeed above the threshold. So it was at
- 11:5850 and the value for CMO was also above
- 12:0240.
- 12:04So let's take a look at the short trade
- 12:09like this one.
- 12:12So again the ADX is above 40 and the
- 12:16value for CMO is above minus 40. All
- 12:19right. So now let's back test it on
- 12:21other periods. In fact, I'm going to
- 12:23back test it as early as 2021, which is
- 12:26the amount of candles that I have up
- 12:29until the 6 month of 2025. Now, to make
- 12:33sure the back test will go faster, I'm
- 12:36going to disable this line here, which
- 12:39is for charts. Go back here. And by the
- 12:43way, if you don't want to use the editor
- 12:45inside Jess's dashboard, you can always
- 12:47use something such as the VS code and
- 12:50look up your strategy. So for instance,
- 12:53tema trend following and you can see the
- 12:57code here and you can edit it right from
- 13:00here instead of the dashboard. All
- 13:02right, so everything looks good. Now
- 13:04let's start it. Now while this is going,
- 13:07I want to also run another one without
- 13:10this benchmark value here.
- 13:13Let's run it. So, while that's going, I
- 13:15want to quickly remind you guys about
- 13:16Apex Omni, which is my favorite deck
- 13:19made by the team behind Bybit. It has
- 13:21low trading fees, instant order
- 13:23execution, and of course, no KYC
- 13:25whatsoever. If you're going to check
- 13:27them out, please consider using our
- 13:28link, which not only will give you
- 13:30trading fee discounts, but it will also
- 13:32support me in order to make more videos
- 13:34like this. And there we go.
- 13:37So, by the way, this max draw down here
- 13:40is really awesome. It allows me to
- 13:43easily add to the size of my position.
- 13:45In fact, let's go here and
- 13:49increase the size of the position with a
- 13:51number such as three.
- 13:55And also do the same thing in my short
- 13:58positions.
- 14:00So, and if I go to the benchmark page, I
- 14:03can just rerun both of them
- 14:04simultaneously, which is really cool.
- 14:06And you know what? While this is going,
- 14:08let's also duplicate this one. Go to
- 14:10here and back test each year separately.
- 14:15So, starting 2021 up until 2022.
- 14:19Again, let's enable benchmark.
- 14:22Disable interactive charts started.
- 14:25Let's do the same since the beginning of
- 14:282022 up until 2023.
- 14:312023
- 14:34up until 2024.
- 14:36and since the beginning of 2025 up until
- 14:41the sixth month.
- 14:45All right. So this is for 2021. We are
- 14:49clearly beating the market. The draw
- 14:52down is minus 20%, which is great. The
- 14:55P&L is 167%. We paid this much in fees.
- 15:00So that means if you started with
- 15:02$10,000, you would have ended with
- 15:0426,700.
- 15:07Now the win to loss ratio is 0.65
- 15:11and that is because for our take profit
- 15:14we're using three times of the ATR and
- 15:16for stop loss we're using four times.
- 15:19But on the other hand, the win rate is
- 15:2071%. So you could say it's more similar
- 15:23to a mean reversion rather than a
- 15:26typical trend following. The average
- 15:28holding time is 44 hours. The sharp
- 15:30ratio is 1.98
- 15:32which is really great.
- 15:35Let's look at 2022.
- 15:38So here's the equity curve.
- 15:42We ended with 35% P&L. The max return is
- 15:45minus 30%. Actually let's just look at
- 15:47the equity curves. So this is for 2023.
- 15:51We didn't beat the market. I mean in the
- 15:54beginning we did but in the end we
- 15:55didn't. And this is for 2025, which I
- 15:59mean this is just off the charts. Now,
- 16:02let's also compare them from the
- 16:04benchmark page. Oh, I forgot 2024. So,
- 16:08let's also back this one.
- 16:15All right, there we go. So, this is also
- 16:17really good. So, we made 300% P&L. The
- 16:22max done is minus 25%.
- 16:25The winner is 75%
- 16:28and the win to loss ratio is still 63.
- 16:33The sharp ratio is near three which is
- 16:37again off the charts. So let's also
- 16:40compare them inside the benchmarking
- 16:41page. So here are the P&L. They're all
- 16:46positive. The maxon is also really good.
- 16:49On our best year it was - 9.2%. On our
- 16:52worst year it was minus 37%. The sharp
- 16:56at the worst year it is 0.8. At the best
- 16:59year it is 4.3
- 17:04and the annual return is on average
- 17:08above 100% for sure. All right. So this
- 17:13looks really great. Also let's take a
- 17:15look at the equity curve of the whole
- 17:174.42
- 17:19years. So this is it
- 17:22and this is if we consider the price of
- 17:25BTC itself. So you see as soon as here
- 17:29we are beating the market and then after
- 17:31that we were always in profit. But
- 17:33here's the thing some people only care
- 17:35about the ending number the P&L. They
- 17:38read this and they're like wow close to
- 17:405,000%. So that means this strategy must
- 17:44be making money for me all the time.
- 17:46Well that's not true. So if you take a
- 17:49closer look at this equity curve, yes we
- 17:51ended here which is amazing but we had
- 17:55so many draw down periods. So for
- 17:57example in here this is 1 2 3 4 5 6 7 8
- 18:039 10. So you see for about eight or nine
- 18:07months I didn't calculate it exactly we
- 18:10were in a draw down period. So that
- 18:12means if we started trading the strategy
- 18:15let's say from here up until this moment
- 18:19we would have been in a loss or if we
- 18:21started here we would have been in a
- 18:23loss for two or 3 months. Now in here we
- 18:29didn't lose much. You could say this is
- 18:31a range but still this took one two
- 18:35three four five six seven for about
- 18:39seven or eight months our equity curve
- 18:41would have been flat. So trust me when I
- 18:45say if you were trading in this live you
- 18:47would not have been happy during this
- 18:49period. In fact most of us wouldn't have
- 18:52continued trading it and would have
- 18:53never seen this huge jump in our equity.
- 18:56Now in here it was really great. So no
- 18:59complaints. It also did pretty well here
- 19:02and here. So yeah, most of the times
- 19:04it's making money. It's going up and
- 19:06that's really great. But there are draw
- 19:09down periods. And I really want to
- 19:11emphasize on this that if you are going
- 19:13to trade a strategy like this, you
- 19:15shouldn't trade all your capital just
- 19:17with this one single strategy. In fact,
- 19:19you want to have a basket of strategies
- 19:22like this one. So that while one of them
- 19:24is going through a draw down period like
- 19:26in this case for example, your other
- 19:28strategy is making money during the same
- 19:30period and they're going to offset each
- 19:33other. In fact, maybe even instead of
- 19:35two strategies, you could run 10 of them
- 19:37simultaneously. Now this is a big topic
- 19:39that I am going to talk about more maybe
- 19:42in a separate video but I just want to
- 19:45emphasize that just don't only look at
- 19:47the ending number especially P&L because
- 19:50at least you want to consider the risk
- 19:53and for that read another number such as
- 19:55the sharp ratio or calma ratio. I'm
- 19:58going to submit the results of this
- 20:00strategy and the code on our website's
- 20:02strategy page where you can find the
- 20:04results of this strategy on different
- 20:06symbols and time frames if you are
- 20:08curious about that. Also, you can find
- 20:10my other strategies and their metrics to
- 20:12maybe create your own basket of
- 20:14strategies as I just described. Now,
- 20:16before I leave, we're going to have a
- 20:17giveaway. A random person who likes this
- 20:19video, post a comment, and subscribes to
- 20:21the channel is going to win 1 million
- 20:23bunk token. All right, let's pick the
- 20:24winner for the previous video.
- 20:28And the winner is Malik. Sorry I cannot
- 20:31pronounce your whole name. Thank you so
- 20:33much for your comment. Please reach out
- 20:34to me so that I can send you your bunk
- 20:36tokens. Thanks for watching and I'll see
- 20:38you in the next one.
- 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.