GPT: ADX scalping strategy in Python makes 4479% — Transcript
Full transcript
- 0:00Hey guys, so today I'm going to show you
- 0:01a scalping strategy which not only is
- 0:04super simple but the result of it is
- 0:06probably the best that I have achieved
- 0:08yet. First I'm going to show you the
- 0:10entry and exit rules of the strategy on
- 0:12trading view and then I'm going to use
- 0:14GPT to convert those rules into Python
- 0:17code so we can run some back test on it.
- 0:19So if that all sounds good, let's get
- 0:20right into it. First let's talk about
- 0:23the entry rules of the strategy. The
- 0:25main indicator of this strategy is
- 0:27called the directional index. So let's
- 0:30add it to our chart. This indicator is
- 0:32very simple. We have three lines. The
- 0:34red line here is simply the ADX
- 0:36indicator which shows us the strength of
- 0:39the trend. Because this is a trend
- 0:40following strategy. We only want to take
- 0:42trades when the volatility is high. And
- 0:44that's what the ADX does. So let's add
- 0:46the threshold of 50. So we will only
- 0:49take trades when this red line here is
- 0:51above the threshold. Next, we use this
- 0:53blue and the orange line in order to
- 0:55determine the direction of the trend. If
- 0:57for example in here the blue line is
- 0:59above this orange line, we are in an
- 1:01uptrend which we can clearly see here.
- 1:03And if the orange line crosses the blue
- 1:05line, for example in here, we are in a
- 1:08clear downtrend. By combining the
- 1:10direction of the trend and also the
- 1:12strength of it using the ADX, which is
- 1:14this red line here, we have a pretty
- 1:16good indicator for taking trades when
- 1:18the volatility is high. Now, other than
- 1:20this indicator, we also use an
- 1:22oscillator. Now, you probably already
- 1:24know such as the RSI or stocastic, but
- 1:27in this strategy, we're going to use
- 1:29Williams percentage R. So, let's look it
- 1:32up on Trading View. Williams percent
- 1:36range.
- 1:37It looks like any other oscillator
- 1:39except that usually we have the values
- 1:42of 20 to 80 for a typical oscalator. But
- 1:46for this one, we have minus 80 and minus
- 1:5020. And we want to take a long trade,
- 1:51for example, in here where the price is
- 1:53oversold. And we want to take a short
- 1:55trade, for example, in here when the
- 1:57price is oversold. And that's it. Those
- 1:59are the only two rules that we have for
- 2:01this strategy. But now, let's talk about
- 2:03the exit rules. Now, for the stop loss,
- 2:05I'm going to use a super simple method
- 2:07that I actually have never done in my
- 2:09previous videos, and that is simply
- 2:10using an SMA or moving average. Simple
- 2:15but changing the value of it from 9
- 2:20into 50.
- 2:23So let's hide these two.
- 2:26All right. So if we are taking a long
- 2:29trade, we want to use this blue line. So
- 2:31whenever the price hits this 50 moving
- 2:33average, we're saying, hey, the trend is
- 2:35over and I don't want to be in this
- 2:37trade anymore. And if it's a short
- 2:39trade, we again use this moving average.
- 2:41And for example in here we would have
- 2:43hit our stop loss. As for the take
- 2:45profit if it's a short position. So
- 2:47let's say this is a short trade that we
- 2:48were taking. And let's say we enter the
- 2:51trade in here. For the take profit price
- 2:53I want it to be the lowest value of the
- 2:55price in the last 30 candles. So if you
- 2:58do it in here it's going to be at here
- 3:01and we would have hit this price at this
- 3:03point. Now if it's a long position we
- 3:05want to do the opposite. So I want the
- 3:07highest value of the price in the last
- 3:0930 candles. So for example, if we had
- 3:11opened the position in here or in here,
- 3:13it doesn't really matter. The highest
- 3:15price would have been at this point
- 3:17which we would have reached here. Now we
- 3:19do have another exit rule of the
- 3:21strategy and that is let's say we open a
- 3:23long position but for whatever reason
- 3:26the direction of the trend has now
- 3:28changed. It is now in a downtrend. Then
- 3:30we want to close the position. All
- 3:32right. Now that we have all the entry
- 3:34and exit rules of the strategy, we can
- 3:36begin feeding it into our GPT to write
- 3:38the Python code for us. So we can run
- 3:40some back test on it. Now in case you're
- 3:42not familiar with this service which we
- 3:44call Jess GPT, it is our own customized
- 3:46version of GFT which uses all sorts of
- 3:49LL models such as Gemini, deepc cloth or
- 3:52whichever edge model really and you can
- 3:54get it started with it completely for
- 3:56free. But for whatever reason, let's say
- 3:58for a privacy concern or let's say you
- 4:00don't like the pricing of our website,
- 4:02you can watch my previous video which
- 4:03I'm going to link somewhere on the
- 4:05screen which teaches you how to
- 4:06self-hosted yourself. So again, using
- 4:08this service is not mandatory, but
- 4:10that's what I'm going to use in this
- 4:12video. All right. So I simply wrote down
- 4:14whatever I just described to you on the
- 4:16chart and I'm asking it to write me a
- 4:18strategy. And here are the rules. For a
- 4:21long position, I want the directional
- 4:22indexes plus value, which is this blue
- 4:25line here, to be above the minus, which
- 4:29is this orange line here. And I also
- 4:32want the ADX value to be above 50, which
- 4:34again is this red line here. As for the
- 4:37stop loss, I want the SMA with a period
- 4:39of 50. For the take profit, if it's a
- 4:41long position, I want the highest high
- 4:43of the last 30 candles. And if it's a
- 4:45short position, I want the lowest low of
- 4:47the last 30 candles. Also for opted
- 4:49position assuming we already have an
- 4:51open position close if entry rule is the
- 4:54opposite directional now and as for the
- 4:56risk management I'm saying risk 3% per
- 4:58each trade and use the market order for
- 5:01entry and that's all I am feeding this
- 5:04LLM. Now, one more thing. I want to
- 5:05change the model, but I'm going to have
- 5:07to copy this value. Change this into
- 5:11cloud set, which is my favorite coding
- 5:13model. And paste it again here. And hit
- 5:16the enter to get the response.
- 5:20And it has started writing it for us.
- 5:24This looks really nice.
- 5:27Let's wait for it to finish. And boom,
- 5:30we're done. Now, usually I change the
- 5:31names that these models give to the
- 5:33strategy, but I think this one is quite
- 5:35nice. So, let's copy it and go to the
- 5:37Jess's dashboard and create a new
- 5:39strategy and I'm going to paste that
- 5:41value here. Next, I'll go to VS Code,
- 5:43which is my editor, and I will look it
- 5:45up. And then I'm going to go back to
- 5:47Jesse GPT, copy this whole thing, go
- 5:51back here, and paste it.
- 5:53Now, let's go through it, see how it
- 5:55looks like. So the definition of ADX
- 5:58indicator is perfectly fine. The
- 6:00directional index is also fine. The 50
- 6:03moving average is great. The highest
- 6:06high it is using the max of the last 30
- 6:09candles and the index of three. Now
- 6:12remember the index of zero is the time
- 6:14stamp of the candle. One is the opening
- 6:16price. Two is close. The three is the
- 6:19high. So this is perfectly right. The
- 6:21lowest low is also correct. The inter
- 6:23rule for short positions is the DI plus
- 6:27must be above the DI minus. The inter
- 6:30rule for the long positions is that the
- 6:32plus value must be bigger than minus and
- 6:35the ADX must be above 50. This is
- 6:37correct, but I think it forgot the
- 6:39oscalator. Actually guys, I forgot to
- 6:41tell the model about the oscalator. So
- 6:43let's ask it to add that to the code.
- 6:45Please also use an oscalator for the
- 6:47entry of the strategy. If the value of
- 6:50the Williams percentage R is below minus
- 6:5380, we want to look for long positions.
- 6:56And if it's above minus20, we want to
- 6:58look for short positions. Let's hit
- 7:00enter.
- 7:05Let's wait for it to finish. All right,
- 7:07let's go back here. Copy this value. Go
- 7:11back. Paste it here. All right, so let's
- 7:13go up. Here's the definition of Williams
- 7:16R. And you can see this is correct
- 7:18because if I hold the option key I can
- 7:21see its definition. So I know the syntax
- 7:23is correct. Everything else is
- 7:25untouched. Now our entry rule is also
- 7:29saying that the value of Williams R must
- 7:31be below minus 80. For a short position
- 7:34it says it needs to be above minus20. I
- 7:37also like these little comments that it
- 7:39added. Now as for the position sizing
- 7:42it's using the market order for entry.
- 7:45The surplus is the current SMA 50 which
- 7:48is exactly what we asked. And as for the
- 7:50quantity, it is risking 3% which is
- 7:52exactly what I asked and it is
- 7:55submitting the buy order with the exact
- 7:57correct syntax of Jesse. Now as for the
- 8:00short position, it's doing the exact
- 8:01thing except that instead of using the
- 8:04selfby variable for submitting the buy
- 8:07order in Jesse, we use self.ell. And
- 8:10again the first parameter is the
- 8:12quantity of the order and the second one
- 8:13is the entry price. We're also saying
- 8:15once the position is opened if it's long
- 8:17position the stop loss is going to be
- 8:20the quantity of the current position and
- 8:22the price is going to be the current SMA
- 8:2650. As for the take profit we're using
- 8:29again the quantity of the current
- 8:31position and the price of it is being
- 8:33the highest high which again this is the
- 8:36definition of it. So we're getting the
- 8:38last 30 candles here but only their high
- 8:42price which has index of three and we're
- 8:44getting the max value of it and if it's
- 8:46a short position we do just the
- 8:48opposite. Now we're also saying how to
- 8:50update the position. So assuming we do
- 8:52have an open position now we're saying
- 8:54if it's a long position and the rules
- 8:56inside the shoot short function are now
- 8:58true liquidate the current position and
- 9:02if it's vice versa do the opposite. And
- 9:05if it's the opposite, again, liquidate
- 9:07the position. So, this seems actually
- 9:09perfect. I don't think there's going to
- 9:10be any errors. So, let's copy the name
- 9:12of the strategy. Go back to Jesse and
- 9:15look up the name of the strategy here.
- 9:17All right. So, if you don't see it here,
- 9:19just give it a refresh. All right. So,
- 9:20it seems like once we ask the LLM to add
- 9:23the Williams percentage R indicator to
- 9:26the strategy, it also changed the name
- 9:28of it. So, now I could go back and run
- 9:30it with the previous name. And this is
- 9:32going to behind the scene change the
- 9:34name to what it used to be without any
- 9:36errors. Or we could create a new
- 9:38strategy with this name because I I
- 9:40think this name is actually better. So
- 9:42let's go back to Jesse. Create a new
- 9:44strategy with this name. Go back here.
- 9:48Actually, let's look this up first. Copy
- 9:50the whole thing and paste it here. So
- 9:54now here I should be able to look it up.
- 9:57ADX Williams strategy.
- 10:00Let's change the time frame to 15 and
- 10:03the symbol into BTC UC. The exchange is
- 10:07Binance perpetual futures.
- 10:09As for the duration, I'm going to do
- 10:11this. So, let's begin since 2021
- 10:15up until
- 10:172022
- 10:19and the debug mode should be off. I do
- 10:23want to see the interactive charts. So,
- 10:25let's leave this on. I want the fast
- 10:27mode to be on and also the benchmark
- 10:30feature. So, let's run this. Now, I'm
- 10:33going to add another one and change the
- 10:34duration to begin since 2022 up until
- 10:372023
- 10:39and then again
- 10:42since 2023 up until 2024.
- 10:45And then since 2024 up until 2025
- 10:49and one last time since the beginning of
- 10:522025
- 10:54up until just a few days ago. So that
- 10:57would be like the 12th of the month.
- 11:01So let's start this one too. All right.
- 11:03So if I go to the benchmark page, I can
- 11:06see all the values simultaneously.
- 11:08All right. So I really like these
- 11:10numbers. So check this out. The sharp
- 11:12ratio is 1.9 for 2021. It is two for
- 11:172022, 1.7 in 2023, 1.2 in 2025, and 1.1
- 11:25in 2025. So let's take a look at the
- 11:29equity curve. All right, so this looks
- 11:31fantastic by the way because if we
- 11:34consider the draw down, it is minus 6%.
- 11:37So that's crazy. But it also allows us
- 11:40to add to the size of the position. So
- 11:42this panel number that you see here, you
- 11:45might think that's nothing. Well, we can
- 11:47easily multiply the size of our
- 11:49position. So let's go back and do that.
- 11:51So I'm going to go to go long
- 11:55and multiply my quantity by five.
- 12:00And also do the same thing for my short
- 12:02positions.
- 12:04So let's go back to Jesse. I could rerun
- 12:06this one by one or I could simply go to
- 12:10the benchmark page and rerun all of them
- 12:12at the same time. All right, so check
- 12:14this out. Now the equity curve of our
- 12:16strategy is clearly beating the market
- 12:20in 2022. It also did the same thing. It
- 12:23looks fantastic.
- 12:25And again, just check out the draw down.
- 12:27So with minus 25 even though the market
- 12:30lost nearly 70%.
- 12:33We made 210%.
- 12:35The win rate would have been 60% the
- 12:38sharp would have been near two and the
- 12:40average holding time of the positions is
- 12:42neared 8 hours which is really great
- 12:44considering how hard it is to watch your
- 12:47strategy do something and then maybe
- 12:49lose at the end which makes it really
- 12:50difficult to continue with the whole
- 12:52trading. All right. On 2023,
- 12:56this is our equity curve. We did not
- 12:58beat the market, but we did end very
- 13:00near. And I don't know the max of the
- 13:03benchmark, which in this case is BTC UC,
- 13:07but I still this equity curve looks fine
- 13:09to me. In 2024,
- 13:12we did beat the market up until here
- 13:14until the price just went on a hike in
- 13:16here. But overall, this equity curve
- 13:18looks really good to me. And the max is
- 13:20only minus 20%. So you could say we
- 13:23could add even more to the size of the
- 13:25position in this year. And if we did
- 13:28that, we would have beaten the market
- 13:30here. But the thing is, you never know,
- 13:32right? Like this could have been also a
- 13:34bad year. So you always want to be
- 13:36careful not to add too much to the size
- 13:38of your positions. Now in 2025, we did
- 13:41end up beating the market. In the
- 13:43beginning of it, we didn't do great, but
- 13:45we still didn't lose much. And that's
- 13:47really good for me because because the
- 13:49beginning of this year actually was
- 13:51really bad on most of strategies that I
- 13:53know. And the fact that this one isn't
- 13:55losing much, I consider that a win. But
- 13:58if you do end up trading something like
- 14:00this, please remember that, you know,
- 14:02for even a few months, you may have been
- 14:04in a loss. It wouldn't have been a big
- 14:06loss, but still a loss. And that's going
- 14:09to be really difficult from a psychology
- 14:11point. So just remember that side of
- 14:13trading is still difficult even if you
- 14:15use an algo like this one. Now, I do
- 14:17want to point this that because I added
- 14:20to the size of my position and multiply
- 14:21it by five. If you are running this back
- 14:24test yourself, you do need to make sure
- 14:26to go to the settings, find the exchange
- 14:29that you're running the back test on,
- 14:30and increase the leverage number. Now,
- 14:32in here, it is set to 100 because of
- 14:34another strategy that I was using. But
- 14:36in this one, we don't need it to be this
- 14:38high. We could use a number such as five
- 14:40or six would be enough. And also because
- 14:43we are using market orders in this
- 14:45strategy, if you want to be careful and
- 14:47consider the slippage value, which may
- 14:49not be really important on an exchange
- 14:51such as Binance, but in anyways, if you
- 14:53want to do that, maybe just increase the
- 14:55trading fees by a number such as this,
- 14:57so that it would be more close to the
- 14:59actual trading results that you will get
- 15:01with this strategy. Now, let's do one
- 15:03more thing. I want to run another back
- 15:04test since the beginning of 2021 up
- 15:08until this stage. So we can see the
- 15:10total equity curve.
- 15:15So while that's going, I want to quickly
- 15:16remind you guys about Apex Omni, which
- 15:18is my favorite deck made by the team
- 15:21behind Bybit. It has low trading fees,
- 15:23instant order execution, and of course,
- 15:25no KYC whatsoever. If you're going to
- 15:28check him out, please consider using our
- 15:29link, which not only will give you
- 15:31trading fee discounts, but it will also
- 15:33support me in order to make more videos
- 15:35like this. All right, so check this out.
- 15:36We finished the back test for more than
- 15:39four years in near 100 seconds and we
- 15:43ended up making 4,400%
- 15:45in P&L. So assuming we started with
- 15:4810,000 in trading capital, we would have
- 15:50finished with nearly half a million. The
- 15:52max lodon was minus 30. The win rate was
- 15:5561%. The sharp ratio was 1.66 which is
- 15:59absolutely amazing over this long period
- 16:02of time. and our average holding time
- 16:04would have been about 14 hours. All
- 16:06right, so this looks really good. Now, I
- 16:08also want to show you guys something
- 16:09else. So, let's take a look at the
- 16:11interactive charts which shows us the
- 16:14trades that the strategy took. So, here
- 16:16you can see the example of a losing
- 16:18trade. So, it opened a long position,
- 16:20but it had to open it right here. And
- 16:23here is an example of a winning trade.
- 16:25So, it would have shorted in here and
- 16:28closed the position in here. So I'm
- 16:30guessing this would have been the exact
- 16:32price because this was the lowest low
- 16:34value. We can also check out another
- 16:36one. So here we would have gone long and
- 16:40closed it in here. Again, this highest
- 16:43high would have been the takerit. Now we
- 16:45could also do something really cool. We
- 16:47could also see the values of the
- 16:48indicator while this trade was taken. So
- 16:51I went back to JCGPT and I simply said
- 16:53add indicator values to the interactive
- 16:55chart so I can see them. and it gave me
- 16:58the new code, but I just want this part.
- 17:01So, let's copy it. Go back to the code
- 17:05and add it here. Now, by the way, this
- 17:07watch list that it added here is really
- 17:09useful for live trading, but it has no
- 17:12use case in back testing. All right, so
- 17:14let's go back to our editor
- 17:16and paste it here. Now, in case you're
- 17:18not familiar with it, this is the syntax
- 17:19we use for displaying the indicator
- 17:22values to the chart. You can check it
- 17:23out on our documentation or watch my
- 17:25previous videos about it. So, but in
- 17:27this case, we just got it from Jess GPT.
- 17:30And if I go back and rerun this one more
- 17:32time, but just so that it would be
- 17:34quicker, let's run this one.
- 17:38All right. So, we're getting an error.
- 17:39It's saying that there's no attribute
- 17:41with this name. So, let's go back.
- 17:45And yeah, we don't have this. We have
- 17:47this one. Okay. So, this one also seems
- 17:50to be wrong. So, let's All right. So, it
- 17:53didn't get the names of this correct,
- 17:55but it's not that bad. So, let's just
- 17:57manually change them.
- 18:04Okay. So, actually, I'm guessing this is
- 18:06happening because I didn't copy the
- 18:08whole thing. You know what? Let's
- 18:09actually go back cuz I want to see if it
- 18:13also changed the names of these in here.
- 18:20So yeah, it did change the names of
- 18:22those variables. So if I did copy the
- 18:24whole thing from here, it would have
- 18:26worked. But that's okay. Let's just
- 18:28change this manually
- 18:32and we should be good to go. So let's go
- 18:34back to Jesse and run it one more time.
- 18:39All right. So let's open the charts. All
- 18:41right. So let's go to this one for
- 18:42example, which is a losing trade. So you
- 18:44see we opened it here and closed it
- 18:46here. And you can also see the values.
- 18:49So yes, the ADX was above the threshold
- 18:51which in here is red. And the DI value
- 18:54was also like this. So because this DI
- 18:58plus value was above the DI minus which
- 19:01is this red line in here, we opened the
- 19:03long position and the William R was also
- 19:06oversold. So all the entry rules were
- 19:09met in here and you can clearly see
- 19:11that. But still this was a losing trade
- 19:13and you could use this scenario here to
- 19:17maybe add another filter so that this
- 19:19losing trade wouldn't have been taken.
- 19:21But if you are going to do that be very
- 19:23careful because that's basically the
- 19:25recipe for overfitting. Now you could do
- 19:28it a little bit and that's fine but
- 19:30overdoing it is not okay. Also when you
- 19:32do something to not take a losing trade
- 19:35you're also going to not take some of
- 19:36your winning trades. So it's not a
- 19:38perfect system. Now let's check out a
- 19:40winning trade. So let's double click on
- 19:43this to reset it. All right. So we took
- 19:45this right here. The ADX was clearly
- 19:48above the threshold and the DI plus
- 19:51value was below the DI minus and that's
- 19:54because this was a short position and
- 19:56the William R was also overbought. So
- 20:00all the integer rules were met at this
- 20:02point. Now I am going to submit this
- 20:04strategy to our strategies index page
- 20:07which allows you to see the results of
- 20:09it for other symbols and also time
- 20:12periods or time frames. You can also
- 20:14download the code for previous
- 20:15strategies that I have created. So I
- 20:17actually really like the results of this
- 20:19strategy and I think I'm going to keep
- 20:20working on it. I may even create a
- 20:22premium version of it and again submit
- 20:24it to our strategies page. Now before I
- 20:26leave, we're going to have a giveaway. A
- 20:28random person who likes this video, post
- 20:29a comment and subscribes to the channel
- 20:31is going to win 1 million bank token.
- 20:33All right, let's pick the winner from
- 20:34the previous video and the winner is
- 20:36Antune Line. I hope I didn't butcher
- 20:39your name. Thank you so much for your
- 20:40comment. Please reach out to me so that
- 20:42I can send you your bank tokens. Thank
- 20:44you guys for watching and I'll see you
- 20:45in the next one.
- 20:51[Music]
- 20:52[Applause]
- 20:54[Music]
About this transcript
This page contains the full transcript of GPT: ADX scalping strategy in Python makes 4479% by Algo-trading with Saleh, generated from the public captions YouTube serves with the video. The transcript has 3,880 words across 527 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.