YouTube2Text

GPT: KAMA Scalping Strategy in Python Makes 795% — Transcript

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

Full transcript

  1. 0:01hey guys Sol today I'm going to act as a
  2. 0:03Trader who has a good strategy but maybe
  3. 0:05he's not necessarily a good programmer
  4. 0:07so I'm going to ask our GPT to write the
  5. 0:10code for me now of course I'll be there
  6. 0:12guiding it if it makes any mistakes but
  7. 0:14I'll do my best not to touch The Code by
  8. 0:16myself now the main indicator that I'm
  9. 0:18using in this strategy has become my
  10. 0:20most favorite indicator so far it be
  11. 0:24super Trend moving averages or anything
  12. 0:25else that I used before all right let me
  13. 0:27show you why
  14. 0:30the main indicator of this strategy is
  15. 0:32called kofman adaptive moving average
  16. 0:34don't let the name scare you it's
  17. 0:36actually very simple to use so basically
  18. 0:38when the line is red we're in a
  19. 0:40downtrend when it's green we are in an
  20. 0:42uptrend in other words when the current
  21. 0:44price is below the moving average we're
  22. 0:46in a downtrend when it's above we're in
  23. 0:48upt all right this is important because
  24. 0:50that's how we're going to write the code
  25. 0:52but the really cool thing about this is
  26. 0:54that it actually reacts to the price
  27. 0:56very quickly to compare let's add the
  28. 0:58super Trend which used to be my favorite
  29. 1:00indicator for Trend following notice
  30. 1:02that in this uptrend the super Trend
  31. 1:04started getting green in here while the
  32. 1:08cman moving average actually gave us the
  33. 1:10signal here so that's like eight or 10
  34. 1:13candles before that it's also the same
  35. 1:15in here so the super Trend it started
  36. 1:18getting red in here but the kman moving
  37. 1:21average or comma in short it started
  38. 1:23giving us that signal here right in here
  39. 1:26I'm look at this the comma started
  40. 1:28getting green here but the super Trend
  41. 1:31gave us the signal here you see the
  42. 1:33difference is really huge all right so I
  43. 1:35simply asked GPT to write a trend
  44. 1:37following strategy using the comma
  45. 1:39indicator to determine the trend
  46. 1:41Direction risk 3% per trade which is
  47. 1:43what I usually do set the suplus and
  48. 1:46take profit at 2.5 times of the current
  49. 1:49ATR which again is something that I do
  50. 1:51in many strategies this is the code that
  51. 1:52it gave me so first let's copy the name
  52. 1:55and go to Jesse and create a new
  53. 1:57strategy with the same name and then I'm
  54. 2:00going to copy the whole thing and open
  55. 2:02my IDE and I'm going to paste the whole
  56. 2:05thing and I'm also going to zoom so it
  57. 2:08would be easier for you guys to see so
  58. 2:09let's go through it one by one so first
  59. 2:12it Define a new property for the comma
  60. 2:13indicator and the syntax is perfectly
  61. 2:16correct then it defined the ATR now it's
  62. 2:19simply saying ta. ATR then this is
  63. 2:22passing the current candles again
  64. 2:23perfectly fine for the shoot long which
  65. 2:26is our entry rule it is saying return
  66. 2:28true if the the current price is above
  67. 2:31the comma line this is exactly what I
  68. 2:33said that when the current price is
  69. 2:34above this line we are in uptrend and
  70. 2:37vice versa for short positions so that's
  71. 2:40exactly what it is doing here and once
  72. 2:44the entry rules are met we're going to
  73. 2:46use the go long method to open the long
  74. 2:48position and the go short for the short
  75. 2:50position and it's saying that the inter
  76. 2:52price is the current price which would
  77. 2:54be a market order and that's exactly
  78. 2:55what I wanted the sub plusus is the
  79. 2:57current price minus 2.5 * h
  80. 3:00which again is what I specified for it
  81. 3:03and for the quantity it's using the risk
  82. 3:05to quantity utility function of JC which
  83. 3:07first you will pass the available margin
  84. 3:10or your capital and then the percentage
  85. 3:12risk and that's three which is what I
  86. 3:15asked in my prompt then the entry price
  87. 3:18the suplus which it calculated here and
  88. 3:20then passing the current fee of the
  89. 3:22exchange for trading and finally it is
  90. 3:24submitting the buy order and to do that
  91. 3:27is first is passing the quantity and
  92. 3:29then the entry price right so then it's
  93. 3:31doing the opposite for short positions
  94. 3:33and now we need to submit the stop loss
  95. 3:36and take profit at some point right and
  96. 3:38it's doing that right after we open a
  97. 3:40position so using the unopen position
  98. 3:42event we're saying if it's a long
  99. 3:44position I want the Stop Plus to be the
  100. 3:47quantity of my current position and the
  101. 3:50price is going to be the current price
  102. 3:51minus 2.5 * the current ATR and we're
  103. 3:55doing the opposite for a take profit now
  104. 3:57this is exactly what I asked in my
  105. 3:59prompt and it wrote it perfectly fine
  106. 4:01and it's doing the opposite for short
  107. 4:03positions it also defined the update
  108. 4:05position method which is used sometimes
  109. 4:08for for example saying if it's a long
  110. 4:10position and the current price is below
  111. 4:12the comma line in other words when it's
  112. 4:14the opposite of our inter rule I want to
  113. 4:16liquidate the position now I tried this
  114. 4:18and it didn't work fine with this
  115. 4:19strategy so I don't want it to be here
  116. 4:22right and it's not what I asked in the
  117. 4:23prompt all right so let's go to Jesse to
  118. 4:25the back testing section and choose our
  119. 4:28strategy and as for time frame I will
  120. 4:30begin with 15 minutes the symbol is BTC
  121. 4:33UCT the duration I'm beginning since
  122. 4:352022 up until just a few days ago and
  123. 4:40I've also selected the fast mode and The
  124. 4:42Benchmark right so we should be able to
  125. 4:45start the first practice while this is
  126. 4:47going I'm going to add another one and
  127. 4:49pick the 30 minutes time frame and then
  128. 4:52another one for the 1
  129. 4:54hour and another one for 4 hours all
  130. 4:58right so let's take a look at The
  131. 5:00Benchmark page this is for the 15
  132. 5:02minutes which is absolutely horrible but
  133. 5:04that is basically because we're taking
  134. 5:05just too many trades and we probably
  135. 5:08paying just too much trading fees I look
  136. 5:10at it here we're paying 12,000
  137. 5:13fees while the starting Capital was just
  138. 5:1610,000 so obviously we need some filters
  139. 5:19now this is for 30 minutes it looks
  140. 5:20better because we're taking less trades
  141. 5:22this is for hourly and 4 hours all right
  142. 5:25so at this point I went back to GPT and
  143. 5:28I said remove the object position part
  144. 5:30which is what I didn't want to do
  145. 5:32because I didn't ask you to do that and
  146. 5:34I also add the adx filter so that I
  147. 5:36don't want the strategy to take any
  148. 5:37trades if the adx is below 50 now I
  149. 5:40always use the adx filter when I want to
  150. 5:43avoid taking a trade when the market is
  151. 5:46ranging which is what we always want to
  152. 5:48do with Trend following strategies so
  153. 5:50this is the code that it gave me let's
  154. 5:53go back paste it in now firstly it
  155. 5:55removed what I asked it to remove but it
  156. 5:57did add the shoot cancel entry method
  157. 5:59which we don't really need in this
  158. 6:01strategy because we are using a market
  159. 6:03order here to enter the position so
  160. 6:06there isn't any entry to cancel or not
  161. 6:08right so we can just remove this now it
  162. 6:10also added the adx property using the
  163. 6:14ta. adx and then it just passed the
  164. 6:16candles using the default parameters
  165. 6:18which is exactly what I wanted and then
  166. 6:21in my entry rule it added this one it's
  167. 6:24saying and self. adx is above 50 and
  168. 6:28it's doing the same thing for short
  169. 6:29positions so this is perfect let's go
  170. 6:32back to Jesse and run another back test
  171. 6:35so while this is going I wanted to
  172. 6:36quickly remind you guys that we have a
  173. 6:38Discord Community with more than 3,000
  174. 6:40quants such as you and I we hang out
  175. 6:42there share ideas and help each other
  176. 6:44out and I would love to see you guys
  177. 6:45there all right so the result looks
  178. 6:47significantly better this is for 1550
  179. 6:49minutes this is for 30 minutes this is
  180. 6:52hourly and this is for 4 hours so you
  181. 6:55can see we're actually profitable at
  182. 6:57this point right especially with the 4
  183. 6:59hours now the main reason that we got
  184. 7:02profitable at this point is that instead
  185. 7:04of trading thousands we are trading just
  186. 7:07573 trades so we're not paying as much
  187. 7:10in trading fees anymore although it's
  188. 7:12still by the way we're paying 7,000 in
  189. 7:15trading fees imagine if this was added
  190. 7:18to our ending balance we would have been
  191. 7:20sitting on a really nice profit so at
  192. 7:22this point I went back to GPT and I
  193. 7:24asked it to do something that I always
  194. 7:26do so basically whenever I have an
  195. 7:28indicator that I really like it usually
  196. 7:31works really well if I use the same
  197. 7:34indicator as it is but also on a bigger
  198. 7:37time frame all right so let me show it
  199. 7:39to you here so this is the comma
  200. 7:42indicator that we are using now I just
  201. 7:44added another one now because it doesn't
  202. 7:47have the option to set time frame in it
  203. 7:50because it's a community built indicator
  204. 7:52what we can do instead is to just
  205. 7:54increase the length from 14 to let's say
  206. 7:58250 but in Jesse we can specify the time
  207. 8:01frame and that's what we're going to do
  208. 8:02so check this out so this means we now
  209. 8:05have two integrals not just one so for
  210. 8:08example in here this comma line went
  211. 8:11green but this one was still red so
  212. 8:14because of that we did not take the
  213. 8:16trade now maybe this isn't really a good
  214. 8:18example of it but in here for instance
  215. 8:21here it became red but we're not taking
  216. 8:24a short position because the below one
  217. 8:26or the slow one the one with the bigger
  218. 8:28time frame is green so because they are
  219. 8:31not saying the same thing we're not
  220. 8:33going to take any trades and as a result
  221. 8:35it wouldn't have been a false breakout
  222. 8:37here all right so I simply ask GPT this
  223. 8:39is good but firstly remove the shoot
  224. 8:41cancel inry method because we don't need
  225. 8:43it and I need you to Define another
  226. 8:46property for the direction of the trend
  227. 8:48again using the comma indicator except
  228. 8:51this time use the bigger time frame
  229. 8:52candle use the 4 hours as a bigger time
  230. 8:54frame but if the current trading time
  231. 8:56frame is 4 hours itself then use the 6
  232. 8:59hours now this is the code that it gave
  233. 9:01me all right so first it defined a new
  234. 9:04property called the long-term candles so
  235. 9:06instead of passing the candles like this
  236. 9:08for this case we're going to pass the
  237. 9:10long-term candles and in it it said that
  238. 9:12the big time frame equals 4 hours but if
  239. 9:15the current time frame is 4 hours then
  240. 9:17the bigger time frame is 6 hours and
  241. 9:19then it's using the get candles built in
  242. 9:21method of Jesse which will give us the
  243. 9:23candles for whichever exchange we tell
  244. 9:26it to whichever symbol and time frame
  245. 9:28and it is passing this variable as a
  246. 9:30time frame all right and then it defined
  247. 9:34another one called long-term comma which
  248. 9:37is just using that and then it defined
  249. 9:40another property called Trend Direction
  250. 9:42which is using that to determine the
  251. 9:45trend but the weird thing is that it is
  252. 9:47not using this or anything else inside
  253. 9:50our actual iny rule so it's flood so I
  254. 9:53went back to it and I just said this is
  255. 9:55good but we're not using the value of
  256. 9:57the trend Direction in your ined rules
  257. 9:59also in it go ahead and just put the
  258. 10:01part where we checked the direction of
  259. 10:02the trend using the self comma also in
  260. 10:05it so that our shoot long and shoot
  261. 10:06short would be cleaner so this is the
  262. 10:09correction that it gave me and now if
  263. 10:12you check it again that property doesn't
  264. 10:14exist but instead inside our shoot long
  265. 10:17and shoot short it is using this line to
  266. 10:20check for the direction of the trend
  267. 10:22with the longterm comma now let's go
  268. 10:24back to Jesse and rerun the entire back
  269. 10:28test now remember these numbers so the
  270. 10:29sharp here is 0.6 1.2 right so the
  271. 10:33results are slightly improved not too
  272. 10:35much but they are especially with the 30
  273. 10:38minutes I like this Equity curve better
  274. 10:41right so now I want to add another
  275. 10:43indicator which is very similar to adx
  276. 10:46except it kind of works the opposite so
  277. 10:48with the adx we want the volatility to
  278. 10:50be high to take a trade so that's why we
  279. 10:52say take the trade if the adx is above
  280. 10:5550 but with the chop index index it's
  281. 10:58actually the opposite we want want the
  282. 10:59choppiness or the randomness of the
  283. 11:01market to be low and the way it works is
  284. 11:03that we Define some kind of threshold
  285. 11:06usually at number 50 and we want the
  286. 11:10choppiness to be below that so here for
  287. 11:12instance you see it was in a ranging
  288. 11:14Market which means it was random the
  289. 11:17choppiness was high and you can see it
  290. 11:19in here the number is actually above our
  291. 11:22threshold but here which we had some
  292. 11:25kind of trend the value for the chop
  293. 11:27index is actually low the same goes for
  294. 11:31here actually so we were just beginning
  295. 11:33to see some structure but then again we
  296. 11:36went into range so the value is is
  297. 11:38clearly seeing that no the market is
  298. 11:40just randomly working so that's why I
  299. 11:42really like this indicator for trending
  300. 11:44strategies so I went back to Jesse and I
  301. 11:47said add another filter for our in rules
  302. 11:50I want to take only positions when the
  303. 11:51choppiness index is below 50 and this is
  304. 11:54what it gave me right so it defined a
  305. 11:57new property called Chop and in it it
  306. 12:00said ta. chop and then pass the current
  307. 12:02candles all right so it also reformatted
  308. 12:05our inter rules and I really like it
  309. 12:07this way because you can clearly see we
  310. 12:09have four in rules for the strategy in
  311. 12:12the end of it it said the self the chop
  312. 12:14is below 50 it also did the same thing
  313. 12:17for short positions all right so let's
  314. 12:18go back to Jesse now remember these
  315. 12:20numbers sharp is 0.9 1.1
  316. 12:250.7 so let's reexecute everything one
  317. 12:28more time right so check this out the
  318. 12:30sharp ratio of all the time frames is
  319. 12:32now improved so with the 15 minutes now
  320. 12:34we have a sharp of one with 30 minutes
  321. 12:36we have 1.3 so let's take a look at the
  322. 12:39equity curve so it looks slightly better
  323. 12:42this is for 30
  324. 12:43minutes and this is for hourly and this
  325. 12:47is for 4 hours all right so this is
  326. 12:49really cool but now I want to show you
  327. 12:51another technique that I use with this
  328. 12:53sub of strategy so you see sometimes
  329. 12:55there is a trend for example in here but
  330. 12:58because there was such a huge jump in
  331. 13:00the price like out of nowhere we don't
  332. 13:02really want to take the position here
  333. 13:04because there's a good chance that there
  334. 13:06will be a pullback now how can we know
  335. 13:08about this one way is to use the
  336. 13:10Ballinger bands indicator and if you
  337. 13:12take a look while this was the case the
  338. 13:15width of the Ballinger bands so the
  339. 13:17difference between this line and this
  340. 13:19line is actually really low but during
  341. 13:21here when the price had a huge surge the
  342. 13:24difference is really huge right you can
  343. 13:27see the same thing here for instance so
  344. 13:29we don't really want to take a trade
  345. 13:31here because now the difference between
  346. 13:32the upper and lower band of the
  347. 13:34Ballinger bands is really huge that
  348. 13:36means that the price is just moving too
  349. 13:39much and it has already went up too much
  350. 13:41and if you take the trade here there's a
  351. 13:44good chance there's going to be a
  352. 13:45pullback and we're going to end with a
  353. 13:46loss now how can we measure this well
  354. 13:49there's a really easy way and that is to
  355. 13:51use another indicator called the Binger
  356. 13:53band WID now with this one what we get
  357. 13:57is actually just what I describ which is
  358. 13:59the difference between these two lines
  359. 14:01and for instance in here which you can
  360. 14:03see it's really tight the value for this
  361. 14:06is almost one but in here the value goes
  362. 14:09up to near nine right so it's really
  363. 14:13huge and in this line that I said you
  364. 14:15know we don't want to take the trade the
  365. 14:16value is almost at seven so now I asked
  366. 14:19GPT to add another filter using the
  367. 14:22Ballinger band with value and I said I
  368. 14:24want to take a trade only if the value
  369. 14:26of it multiplied by 100 is below 7 now
  370. 14:29why did they ask it to be multiplied by
  371. 14:31100 that's because in the calculation
  372. 14:34that the trading view is using that's
  373. 14:35what they're doing they are multiplying
  374. 14:37it by 100 otherwise this value would
  375. 14:39have been 0.07 instead of just 7 which
  376. 14:42is just really easier on the eyes
  377. 14:44because I want it to be the same as
  378. 14:46trading view I just asked it to multiply
  379. 14:48it by 100 all right so let's copy this
  380. 14:50go back paste it
  381. 14:53here and now we have a new property
  382. 14:56called BB width and in it is using ta.
  383. 15:00Ballinger bands and it's actually
  384. 15:01calculating the value of the BB width
  385. 15:04that I wanted instead of using the
  386. 15:06builtin indicator that Jessi has for
  387. 15:08this indicator so I went back and I
  388. 15:10simply asked that this seems fine but I
  389. 15:12need you to use the built-in volunteer
  390. 15:14bands with indicator of Jessi it gave me
  391. 15:16this one which is indeed using the
  392. 15:19Ballinger bands with built-in indicator
  393. 15:21of Jessi and in the in rule it's saying
  394. 15:25that the value of it multiplied by 100
  395. 15:28must be below seven and it's using the
  396. 15:30same thing for a short position all
  397. 15:32right so there's one more filter that I
  398. 15:33wanted to add you see sometimes we take
  399. 15:35a trade and it actually goes really well
  400. 15:37we close the position but we're kind of
  401. 15:39done with that Trend especially because
  402. 15:41this is a scouting strategy we want to
  403. 15:43get in and out very quickly so we don't
  404. 15:45want to write the trend for for for
  405. 15:47example for as long as possible but
  406. 15:49sometimes our in rules are still true so
  407. 15:52that means even though the strategy
  408. 15:54closes one trade it immediately takes
  409. 15:56another one so I wanted to implement
  410. 15:58some kind of tool off mechanism so I
  411. 16:00went back to GPT and I said lastly add
  412. 16:02another inry rule I need the strategy to
  413. 16:05remember the last index that it took a
  414. 16:07trade and when a trade is over I don't
  415. 16:09want to take another trade until at
  416. 16:11least another 10 candles has been passed
  417. 16:14so let's copy this all right so first it
  418. 16:16Define a new variable because we're
  419. 16:18going to need to hold the value of that
  420. 16:20index it's called last trade index and
  421. 16:22then in our entry rule it said if the
  422. 16:25current index minus the last trate index
  423. 16:28is bigger or equal to 10 which is
  424. 16:31exactly what I wanted it also did the
  425. 16:32same thing for our Sho short method but
  426. 16:35where is it updating this because we
  427. 16:37need to specifically update this it's
  428. 16:39doing that inside the go long and go
  429. 16:41short method so once we are opening the
  430. 16:44position it is updating this value using
  431. 16:47the current index now this line is
  432. 16:51perfectly correct but there is one
  433. 16:53mistake at this point we are just
  434. 16:55opening the position but I wanted to
  435. 16:59wait 10 candles after we close the
  436. 17:01position all right so this ISS to change
  437. 17:04so I went back and I told it that you
  438. 17:06are updating the last index inside the
  439. 17:08go long and go short methods but that's
  440. 17:10for when we are opening the position I
  441. 17:12need you to update it inside the on
  442. 17:15close position method instead and it
  443. 17:17gave me this
  444. 17:20one so now it added another method
  445. 17:23called on close position which is a real
  446. 17:26event method inside Jesse and in it is
  447. 17:28saying that I want to set the current
  448. 17:30index inside the last word index
  449. 17:33variable which is exactly what you
  450. 17:34wanted and it removed that other one all
  451. 17:37right perfect so let's go back to Jesse
  452. 17:40and run another back test so remember
  453. 17:42these numbers the sharp is one 1.3 1.1
  454. 17:46and
  455. 17:471.1 all right check this out the sharp
  456. 17:51is upgraded to 1.9 on the 15 minutes
  457. 17:55time frame and the Cal R is 3.7 which is
  458. 17:58amazing and the max thron for almost all
  459. 18:01of them is below 10% that's just awesome
  460. 18:04with the 30 minutes it's 1.3 which is
  461. 18:06still awesome so let's take a look at
  462. 18:09the equity curve this looks
  463. 18:12fantastic and this is on the 30 minutes
  464. 18:15now you may think that this is a
  465. 18:17straight line but it's not actually it
  466. 18:20is still going up and because the max
  467. 18:22thron is really low we can simply add to
  468. 18:25our position size so that this would
  469. 18:27look better now this is with the hourly
  470. 18:30and this is with the 4 hours now the
  471. 18:32hourly and the four 4 hours I think
  472. 18:34should be retired at this
  473. 18:36point but these two look really well but
  474. 18:39the max Ron is still really low so that
  475. 18:41means we can easily add to size of our
  476. 18:44position so if I go back and in here for
  477. 18:47instance I can just add to this quantity
  478. 18:50by number such as let's say three and
  479. 18:53rerun the two of them all right so now
  480. 18:55with the max throw down of minus 24%
  481. 18:57we're making nearly
  482. 18:59800% profit all right so this is the
  483. 19:02equity curve now obviously this looks
  484. 19:05still really good and this is with with
  485. 19:08the 30 minutes now you see my point it
  486. 19:10wasn't really a straight line it is
  487. 19:12still going up but we weren't really
  488. 19:15seeing it because there wasn't enough
  489. 19:16volatility in the daily balance but now
  490. 19:19that we added to the position sides it's
  491. 19:21much more but still these Max R numbers
  492. 19:24I think it's really safe to just
  493. 19:26increase them because my risk cap allows
  494. 19:29me to take up onus 30% Max R down and if
  495. 19:32we do that we're going to make even more
  496. 19:34penal numbers in here you can access the
  497. 19:36source code of this strategy on our
  498. 19:38website if you haven't checked out this
  499. 19:39page yet now is the time to do so there
  500. 19:41are tons of other strategies in here and
  501. 19:43you can very quickly see the results of
  502. 19:45each strategy on various periods and
  503. 19:47symbols and time frames now this was a
  504. 19:50new type of video that I just did where
  505. 19:52the idea of the strategy was from me but
  506. 19:55the implementation was done by the AI
  507. 19:57while me being the teacher and guiding
  508. 19:59it now if you like this format please
  509. 20:01let me know and if you didn't if you
  510. 20:02want me to go back to the previous
  511. 20:04format where I take the idea let's say
  512. 20:06from the AI but I called it from a
  513. 20:07scratch myself again please let me know
  514. 20:10now we're going to have a giveaway a
  515. 20:11random person who likes this video posts
  516. 20:13a comment and subscribes to the channel
  517. 20:15is going to receive 1 million bnk token
  518. 20:18all right let's pick the winner for my
  519. 20:19previous
  520. 20:21video and the winner is amazing results
  521. 20:24well done thank you so much for your
  522. 20:26comments please reach out to me so that
  523. 20:27I can send you your buk tokens thanks
  524. 20:29for watching and I'll see you in the
  525. 20:31next one
  526. 20:32[Music]

About this transcript

This page contains the full transcript of GPT: KAMA Scalping Strategy in Python Makes 795% by Algo-trading with Saleh, generated from the public captions YouTube serves with the video. The transcript has 3,994 words across 526 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.