YouTube2Text

CODING TRADING AUTOMATIONS | July 24 | Michele Rossi — Transcript

by FunderPro · 5,360 words · 906 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Here
  2. 0:02we are again. Welcome back, beautiful
  3. 0:06people. If you can hear me or see me,
  4. 0:09leave a comment in the chat. Say hello
  5. 0:11and subscribe to the channel. Thank you
  6. 0:13so much, Fun Pro, for having me. This is
  7. 0:16the second lesson we're going to have
  8. 0:19about
  9. 0:21creating a strategy
  10. 0:24from the idea to the final
  11. 0:29functional
  12. 0:31strategy and bot to deploy on a prop
  13. 0:35firm. So in the last lesson we talked
  14. 0:39about everything about on how to create
  15. 0:43a strategy. We talked about
  16. 0:47technicals let's say I mean just we wrap
  17. 0:51around our head around the idea on why
  18. 0:55is it a good idea to code the strategy
  19. 0:58um and why
  20. 1:00is a good idea to use automation build
  21. 1:05your own strategy back test the strategy
  22. 1:08and then deploy it live on your prop
  23. 1:11firm uh today we're gonna
  24. 1:14have the first step and we're going to
  25. 1:16start to put our hands in the mud and
  26. 1:19start creating something. Today we start
  27. 1:22from the idea. Um, so we're going to go
  28. 1:27from the idea to the first working
  29. 1:30version today. So be careful, listen
  30. 1:34carefully, take some notes and if you
  31. 1:37want you will find this video recorded
  32. 1:41on YouTube on the YouTube channel of
  33. 1:43funprog.
  34. 2:02Trading.
  35. 2:18So, welcome to the first chapter of this
  36. 2:21week. Today, we're going to build the
  37. 2:23first working version of a trading
  38. 2:25strategy.
  39. 2:27um not just look at the chart and say
  40. 2:29this could work. We are going to start
  41. 2:32with a market idea. Turn that idea into
  42. 2:37precise rules and give those rule to
  43. 2:40codeex. We're going to use chat GPT you
  44. 2:42can use codeex you can use cloud code
  45. 2:46whatever it works best for you and we're
  46. 2:49going to use it to generate a pine
  47. 2:51script strategy. I know this is not the
  48. 2:56institutional way to do stuff but
  49. 3:01we're working on proper okay we're not
  50. 3:06competing against institutions that's
  51. 3:10not our job we are working into a
  52. 3:14virtual environment
  53. 3:17we're just looking at the real market
  54. 3:19we're not actually intervene
  55. 3:22in the real market. So, we're going to
  56. 3:25go deep on this um statement later on,
  57. 3:31but for now, so we're going to code the
  58. 3:35strategy with CHBT. We're going to have
  59. 3:38a Pine Script strategy. We're going to
  60. 3:40add it to Trading View. We're going to
  61. 3:43inspect the results and find the first
  62. 3:46problems and correct them. So by the end
  63. 3:49of this lesson, we will have a real
  64. 3:52baseline version of our strategy.
  65. 3:55It may be not profitable. It may not be
  66. 4:00robust. It will certainly not be ready
  67. 4:04to deploy yet, but it will be something
  68. 4:08that we can test, that we can measure
  69. 4:12and improve. And this is the first
  70. 4:15important step because you cannot
  71. 4:17properly validate an idea that has never
  72. 4:21been defined before. You cannot optimize
  73. 4:25rules that keep changing
  74. 4:28and you should never deploy a strategy
  75. 4:31that exists only as a bug concept in
  76. 4:36your head. [snorts] Over the next four
  77. 4:39lessons, we will follow the complete
  78. 4:42process. Today we move from the idea to
  79. 4:45the first functioning version. In the
  80. 4:48next lessons we will validate the
  81. 4:50strategy using trading view data. We
  82. 4:53will collect the complete list of trades
  83. 4:55and give that data to codeex. We will
  84. 4:58ask Codex to analyze the results and
  85. 5:00identify weaknesses, test different
  86. 5:03assumptions and help us investigate
  87. 5:06whether the strategy has a real edge or
  88. 5:08whether the historical results is simply
  89. 5:12the product of overfeeding.
  90. 5:16Again, we're not using
  91. 5:19all the indepth level three data. Of
  92. 5:24course, we're using a um an entrylevel
  93. 5:29data which is trading view. They have
  94. 5:33few tick datas, not even the full
  95. 5:35history, but it's more than enough for
  96. 5:38us to start
  97. 5:40understand the concept on how to code a
  98. 5:43strategy,
  99. 5:45back test the strategy automatically,
  100. 5:47um optimize it, validate it and deploy.
  101. 5:51And you are going to be surprised on how
  102. 5:56much this could potentially be really
  103. 6:00really profitable.
  104. 6:02Okay,
  105. 6:04we will also look at a Monte Carlo
  106. 6:06testing in sample and out of sample
  107. 6:09testing and cross validation. Finally,
  108. 6:13once we have a version that has survived
  109. 6:16the validation process, we will discuss
  110. 6:19deployment. At that point, we could
  111. 6:22convert the strategy into, if you wish,
  112. 6:24MQL5 for MetaTrader 5 or Ninja Trader
  113. 6:29with Python or C++ or we could leave the
  114. 6:32strategy on Trading View and use an
  115. 6:35external bridge to copy the signal to
  116. 6:37the account we choose. For this project,
  117. 6:40we are going to keep the strategy on
  118. 6:41Trading View. But first, we need to
  119. 6:43build it correctly.
  120. 6:46All right, let's start and let's begin
  121. 6:49with the idea. The strategy we are going
  122. 6:53to use is the orb is the most discussed
  123. 6:58and talked strategy of the last couple
  124. 7:01of years, but it's running around
  125. 7:07since the 80s, since the 70s,
  126. 7:121970s, 1980s.
  127. 7:14I don't know. But it's it exists from a
  128. 7:17long time. And you might think
  129. 7:21okay if it exists
  130. 7:24for this very long time maybe we got
  131. 7:28alpha decay the strategy is no more
  132. 7:30profitable. No that's not the case
  133. 7:33because we're not talking about a
  134. 7:36precise set of rule. We're talking about
  135. 7:40the overall concept which is the opening
  136. 7:44range breakout around that we can build
  137. 7:48multiple layers of filters not too much
  138. 7:51to avoid overfeitting
  139. 7:54to find a little small new edge that we
  140. 7:59can use if it exists to pass the
  141. 8:03challenges and to make payouts. That's
  142. 8:05the idea and I've already done that. so
  143. 8:09many times. My students have already
  144. 8:11done that so many times. So can you.
  145. 8:16So the OB stands for opening range
  146. 8:20breakout. The name sounds complicated
  147. 8:23but the basic idea is very simple. At
  148. 8:25the beginning of a trading session, we
  149. 8:28are going to
  150. 8:31define a range.
  151. 8:34Right? [snorts]
  152. 8:36For example, we can use the first 15
  153. 8:39minutes after the New York market opens.
  154. 8:44So, if you're in Italy, as I was for the
  155. 8:49last 40 years,
  156. 8:52the opening range is going to be between
  157. 8:553:30 to 3:45
  158. 9:00p.m.
  159. 9:04GMT + 2. Okay, this is the New York
  160. 9:08Stock Exchange opening first
  161. 9:1415 minutes,
  162. 9:16right? This is the opening range and
  163. 9:19you're going to have such a candle
  164. 9:24with a it's
  165. 9:28high low opening and close. Let's say
  166. 9:32it's like this of HCL.
  167. 9:39This is the low. This is the high. This
  168. 9:41is the opening. And this is the closing
  169. 9:44of the candle. Right at the end of these
  170. 9:49of the 15minut period, we have two
  171. 9:52important level.
  172. 9:55The high of the opening range and the
  173. 9:58low of the opening range. After that we
  174. 10:01wait. If price
  175. 10:05is going to
  176. 10:07closes above the opening range high, we
  177. 10:11look for a long trade.
  178. 10:16If price closes below
  179. 10:21the opening range, we're going to short
  180. 10:25[snorts] and sell
  181. 10:28the price.
  182. 10:30That is the basic ORB concept, the orb.
  183. 10:35But now we need to ask the question that
  184. 10:37should always come before writing code.
  185. 10:41Why should this idea work?
  186. 10:46Why would the first 15 minutes of a
  187. 10:49trading session be important?
  188. 10:52The reason is that the market does not
  189. 10:54behave exactly the same way throughout
  190. 10:57the day. When an important session
  191. 11:00opens, activity often increases.
  192. 11:05There may have been news during the
  193. 11:07night. There may be orders waiting to be
  194. 11:11executed. There may be a difference
  195. 11:14between the price accepted during the
  196. 11:16overnight trading and the price accepted
  197. 11:20when the main market opens.
  198. 11:23uh buyers and sellers begin to interact
  199. 11:26more aggressively.
  200. 11:30So the first few minutes can therefore
  201. 11:34create a kind of initial balance.
  202. 11:38The high range tell us where buyers
  203. 11:42stopped the market during that initial
  204. 11:45period. The low tells us where sellers
  205. 11:48stopped it. If price later breaks
  206. 11:52through one of those levels, the
  207. 11:55breakout may show that one side is
  208. 11:57becoming more aggressive.
  209. 12:01A close above the range may suggest that
  210. 12:04buyers are willing to continue paying
  211. 12:07higher prices.
  212. 12:09A close below the range may suggest the
  213. 12:12sellers are willing to continue
  214. 12:13accepting lower prices. That is
  215. 12:18that is the market hypothesis
  216. 12:22and I want to be precise about the word
  217. 12:24hypothesis. We are not saying that orb
  218. 12:28works. We are not saying that every
  219. 12:30breakout continues. We are not saying
  220. 12:33that the strategy
  221. 12:35has an edge simply because the idea
  222. 12:38sounds logical. We are saying that the
  223. 12:42behavioral
  224. 12:45the behavior is specific enough to
  225. 12:47investigate.
  226. 12:50That is the difference between an idea
  227. 12:52and the conclusion. An idea says maybe
  228. 12:56the opening range contains useful
  229. 12:59information about the next part of the
  230. 13:01session.
  231. 13:03A conclusion say the historical data
  232. 13:06shows that the behavior creates a
  233. 13:08repeatable advantage after realistic
  234. 13:11costs. We are not at the conclusion yet.
  235. 13:14We just started today. We are only
  236. 13:16building the system that will allow us
  237. 13:19to investigate the idea properly.
  238. 13:23Let me show you how this can look on a
  239. 13:26real chart. Okay,
  240. 13:29let me clean up the chart.
  241. 13:34>> [snorts]
  242. 13:36>> So for this example, I'm going to use uh
  243. 13:40the the a 15minute range. Let me go
  244. 13:43back. I I'm going to cherrypicking the
  245. 13:46idea. So it's going to be
  246. 13:49useful and clear for you.
  247. 13:53There it is. Let me go back. Let me find
  248. 13:58some good or example. This can be one.
  249. 14:01There it goes.
  250. 14:04[snorts] Beautiful.
  251. 14:06I know it's cherrypicked, but this is
  252. 14:08educational, okay? I'm not going to
  253. 14:10cherrypick anything else, but I need to
  254. 14:13show you how the process work. So, I'm
  255. 14:16going to use a 15inut opening range on
  256. 14:19the New York session. There it is. Is it
  257. 14:243:30? The market open [snorts]
  258. 14:27right here.
  259. 14:34So this is the first five minute candle.
  260. 14:37This one right here. 5 minute 5 minute 5
  261. 14:41minute. We have our 15 minute range.
  262. 14:48Right.
  263. 14:50We're gonna have the orb
  264. 14:53opening range high
  265. 14:57and we're gonna have we already have
  266. 15:01actually our open range low.
  267. 15:09The market and the exact ticker are
  268. 15:14important. If you use one trading view
  269. 15:17symbol and then you use another, we may
  270. 15:20not get the same prices, the same spread
  271. 15:22or the same session data. So I'm going
  272. 15:24to use the exact symbol visible here.
  273. 15:28Okay, I'm using the micro MQ micro E
  274. 15:33mini NASDAQ 100 index futures of CME.
  275. 15:39Right? So you can do the same.
  276. 15:42Um
  277. 15:44now
  278. 15:49the session begin here
  279. 15:54for the first 15 minutes. I'm not
  280. 15:56interested in taking any trades. One,
  281. 16:00two, three, 15 minutes. One, two, three,
  282. 16:03five, 10, 15. [snorts] I'm only
  283. 16:06measuring the market. During this
  284. 16:10period, the range
  285. 16:12is being created.
  286. 16:18This candle reaches the
  287. 16:22the high the highest price of the
  288. 16:24opening window. This candle reaches the
  289. 16:27lowest price. So at the end of the
  290. 16:29opening period, these two levels become
  291. 16:33our first range high and range low. From
  292. 16:37this point forward, the range should
  293. 16:39remain fixed. Now look at what happens
  294. 16:42next. Price move above the range high.
  295. 16:51There it goes. And we have a closure.
  296. 16:54There it is. Let me go back one candle.
  297. 16:58There it is. Our opening range high.
  298. 17:02Sorry, I already have my
  299. 17:05some of my bots installed here.
  300. 17:08So, this is the first trigger candle.
  301. 17:14That is the type of event we are going
  302. 17:16to code.
  303. 17:18The important detail is that the entry
  304. 17:21is based on the close,
  305. 17:24not simply on a week. So if we had a
  306. 17:28previous candle that wicked and closed
  307. 17:30back inside of the range, that is not an
  308. 17:32entry.
  309. 17:35This is one of the decisions that makes
  310. 17:38the strategy precise. If you we don't
  311. 17:42define this, someone else could
  312. 17:43implement an intraar entry and get
  313. 17:46completely different results. Now let's
  314. 17:50use this number. We're going to have our
  315. 17:53entry right here.
  316. 17:57We're going to have a our stop loss.
  317. 18:01Let's figure out we're going to put it
  318. 18:03on the opposite range. So on the or low
  319. 18:10and we're going to target a one to two
  320. 18:14risk to reward.
  321. 18:16We're risking one to target two. We're
  322. 18:20risking 1% to make it 2%.
  323. 18:28And we have to be very careful and
  324. 18:31precise on what we are going to say to
  325. 18:37define our strategy. So the rules at the
  326. 18:41moment are very simple. Wait for the
  327. 18:45first 15minut candle. Mark up the high
  328. 18:49and the low of the range and wait for a
  329. 18:51candle of five minute closing above or
  330. 18:55below. We have our candle closing above.
  331. 18:58Right at the close, we open a buy
  332. 19:04order. We're going to put our stop loss
  333. 19:07on the opposite range on the or low and
  334. 19:10we're going to target a one to two
  335. 19:12risk-to-reward.
  336. 19:14These are the rule of the strategy.
  337. 19:17Okay. [snorts]
  338. 19:20Um, of course, we also have to
  339. 19:26uh ask ourself some follow-up question.
  340. 19:31Are we going to enter on the same candle
  341. 19:33or on the next bar? Are we including
  342. 19:35commission? Are we including slippage?
  343. 19:37What happens if the breakout occurs five
  344. 19:40minutes before the session closes? What
  345. 19:42happens if price breaks both sides of
  346. 19:45the range? These are not secondary
  347. 19:48question. Those are very important
  348. 19:50question. We're going to ask these
  349. 19:51questions a little bit later. And this
  350. 19:54is also why most strategies found on the
  351. 19:57internet are not immediately useful.
  352. 20:00Often they are presented as a visual
  353. 20:03ideas rather than a complete system.
  354. 20:06Someone shows us a chart and say by the
  355. 20:08breakout. But which breakout? The first
  356. 20:12breakout of the day, the breakout after
  357. 20:14a pullback, a breakout confirmed by
  358. 20:17volume, a breakout that closes above the
  359. 20:21level, and what happens after the
  360. 20:24entitle, when is the stop-loss, when is
  361. 20:27the target, when do we stop trading? If
  362. 20:30these questions are unanswered, the
  363. 20:33strategy cannot be reproduced. Another
  364. 20:36problem is that we usually see only the
  365. 20:39best examples like we're doing right
  366. 20:41now, but for educational purposes. We
  367. 20:44see three winning trades on a shorts on
  368. 20:47Tik Tok or Instagram, but we do not see
  369. 20:50the losing trades.
  370. 20:53[snorts]
  371. 20:53We do not know whether the performance
  372. 20:56includes commissions and slippage and
  373. 21:00perhaps spreads. If you are on CFD
  374. 21:02especially,
  375. 21:04we do not know if the strategy is using
  376. 21:07future information and sometimes the
  377. 21:10strategy has been optimized so many
  378. 21:12times that it works only because it has
  379. 21:14been fitted to one particular historical
  380. 21:18period. A real edge is not a magical
  381. 21:21indicator
  382. 21:22uh is not a win rate is not a beautiful
  383. 21:24equity curve in edge is a repeatable
  384. 21:28statistical advantage. A strategy can
  385. 21:31win 40% of its trades and still be
  386. 21:34profitable if its winning trades are
  387. 21:38sufficiently larger than its losing
  388. 21:41trades. A strategy can win 80% of its
  389. 21:44trades and still lose money if the
  390. 21:46occasional losses are too large. So we
  391. 21:50need to study the complete distribution
  392. 21:53of results. We need to look at average
  393. 21:56trade, profit factor, draw down, losing
  394. 21:59streak, and performance across different
  395. 22:01periods. But before any of that, we need
  396. 22:04a strategy that is stable enough to
  397. 22:07test.
  398. 22:09Now, I'm going to write the technical
  399. 22:13specification.
  400. 22:15I'm doing this before asking Codex to
  401. 22:18write the code. We're doing together.
  402. 22:20Don't worry. This is important. Codeex
  403. 22:23can write pine script very quickly as
  404. 22:25well as
  405. 22:27uh cloud code or any other AI but it
  406. 22:31cannot read my mind. If I give it a v
  407. 22:34idea it must make assumptions and if
  408. 22:37those assumptions remain hidden I may
  409. 22:41end up testing rules that I never
  410. 22:43intended to create. So, I'm going to
  411. 22:46write the specification
  412. 22:48directly here so you can see and you can
  413. 22:51try and do the same. I don't like the
  414. 22:54red. Let me use blue. No, it's not
  415. 22:57visible. Let me use yellow. Let's go
  416. 23:00with the yellow.
  417. 23:03There it goes. So,
  418. 23:07the first part is the market. I will
  419. 23:09write we are using
  420. 23:13>> [snorts]
  421. 23:14>> uh the selected
  422. 23:18trading view symbol.
  423. 23:22Right? This is the first thing we have
  424. 23:24to say codeex. What symbol are we using
  425. 23:28at the moment?
  426. 23:31Right? MNQ. So we're going to use
  427. 23:35MNQ, right?
  428. 23:39But of course we can use the same we
  429. 23:42want to be able to use the strategy on
  430. 23:45different chart and test it on different
  431. 23:47scenario. Maybe you want to use it on YM
  432. 23:50which is the Dow Jones. You might want
  433. 23:52to use it on ES which is the S&P 500. So
  434. 23:55we are using
  435. 23:59the selected trading view symbol means
  436. 24:02that whatever symbol we are using the
  437. 24:05strategy whatever chart we are using the
  438. 24:07strategy on trading view is going to uh
  439. 24:13test the strategy on that symbol. The
  440. 24:15ticker
  441. 24:17must not
  442. 24:19be hard
  443. 24:23coded.
  444. 24:26This mean the script should work with
  445. 24:27the symbol displayed on the chart. This
  446. 24:29is simple. The second part is the
  447. 24:32session.
  448. 24:34The strategy
  449. 24:37uses the New York
  450. 24:41um
  451. 24:44session
  452. 24:45and the
  453. 24:49America
  454. 24:52New
  455. 24:54York time.
  456. 24:59Sorry, let me go
  457. 25:03time zone. Right. You can use the
  458. 25:09Italy time zone. You can use the India
  459. 25:13time zone. You can use Japan time zone.
  460. 25:17But we're going to use the New York
  461. 25:18session. We're going to trade in the New
  462. 25:20York session. I'm deliberately
  463. 25:24specifying the time zone. I do not want
  464. 25:27the strategy to use the time zone of my
  465. 25:29computer or whatever time zone happens
  466. 25:33to be selected on the chart. The third
  467. 25:35part is the opening range. This is also
  468. 25:38very important for [snorts] Metatrader,
  469. 25:41but we're going to talk in another time.
  470. 25:43The range begin at 9:30 a.m.
  471. 26:01New York time
  472. 26:04and ends
  473. 26:08[snorts]
  474. 26:08at 9:45
  475. 26:12a.m.
  476. 26:17During
  477. 26:20the those
  478. 26:2315 minutes,
  479. 26:25the strategy
  480. 26:28records
  481. 26:30the highest
  482. 26:33and the lowest
  483. 26:37low.
  484. 26:39So, the highest high
  485. 26:42and the lowest low.
  486. 26:46No trade
  487. 26:48is allowed
  488. 26:52while
  489. 26:54the range is forming.
  490. 27:00Once the range is complete,
  491. 27:06the levels
  492. 27:09are fixed.
  493. 27:15Okay. Now the fourth part is the entry,
  494. 27:20right? We need to tell when to enter
  495. 27:22long and when to enter short. So,
  496. 27:28a long signal
  497. 27:31occurs
  498. 27:34only when a confirmed candle
  499. 27:41[snorts]
  500. 27:42closes
  501. 27:47above
  502. 27:50the range high.
  503. 27:54While for a short
  504. 27:57[snorts]
  505. 28:01signal, a short signal occur only when a
  506. 28:05confirmed candle closes below the range
  507. 28:10low. Right? [snorts]
  508. 28:14only one entry
  509. 28:23um is allowed per
  510. 28:27session.
  511. 28:32If the first trade, let me dictate. So,
  512. 28:34I'm going to go faster. If the first
  513. 28:36trade is long,
  514. 28:40we do not later open a short trade on
  515. 28:43the same day.
  516. 28:45Oh, it's not working. Let me write it
  517. 28:47down. If the first
  518. 28:53trade is long,
  519. 28:57[snorts]
  520. 28:59we
  521. 29:01do not later open a short trade
  522. 29:09on the same day.
  523. 29:17Same apply
  524. 29:20for the short. If the first trade is
  525. 29:24short, we do not later open a long
  526. 29:27trade [snorts] on the same day just to
  527. 29:30be sure
  528. 29:32we're hardcoding every property,
  529. 29:37every rule, every idea,
  530. 29:41everything that can mess up with the
  531. 29:43with the logic of the strategy.
  532. 29:47So the sixth part is the stop for a long
  533. 29:51trade.
  534. 29:57Let me see if we can do this right. We
  535. 30:00can do this. I can dictate now. Okay.
  536. 30:04For a long trade, the stop goes at the
  537. 30:07opening range low. It works.
  538. 30:12For a short trade, the stop goes at the
  539. 30:16opening range high.
  540. 30:18Right?
  541. 30:20Then let me stop the right. Then the
  542. 30:24seventh part is the target.
  543. 30:28So what are we going to say
  544. 30:31is
  545. 30:33we use a configurable risk-to-reward
  546. 30:37ratio with a default value of two.
  547. 30:41Perfect. Wisher pearl is crazy good.
  548. 30:47I need to remember to stop and restart.
  549. 30:52Then the target must be calculated from
  550. 30:57the actual entry price and the initial
  551. 31:00stop distance.
  552. 31:02Right?
  553. 31:05Then the eighth part is the session
  554. 31:07exit.
  555. 31:11Any open position is closed at the end
  556. 31:14of the session. There is no overnight
  557. 31:17holding
  558. 31:20this.
  559. 31:22Let me go a little bit smaller.
  560. 31:29And the ninth part is position size. For
  561. 31:33the first version, we will use a
  562. 31:35configurable quantity. We are not trying
  563. 31:37to solve the entire portfolio risk
  564. 31:39management problem here.
  565. 31:47There it goes.
  566. 31:50[snorts]
  567. 31:51Um, so
  568. 31:53we are trying to create a clean
  569. 31:55baseline.
  570. 31:57The final part is the visual behavior.
  571. 32:00So we need to tell the script to show
  572. 32:03because we want to see we we can we can
  573. 32:05do it. So we we can we want to also be
  574. 32:08able to see the script must show the
  575. 32:11range high and low. It must shade the
  576. 32:14opening range area. It must mark
  577. 32:17entries. It must show the active stop
  578. 32:21and target. That way we can compare what
  579. 32:24the code does with what the rule say it
  580. 32:28should do.
  581. 32:34Come on. Whisper plot, please don't
  582. 32:37abandon me. There it goes. So, this is
  583. 32:41our complete first specification. It is
  584. 32:44simple but is precise. Now, I'm going to
  585. 32:47turn that specification into the prompt
  586. 32:50I will use with codeex. I want to show
  587. 32:53you the exact process because the prompt
  588. 32:55is part of the development workflow. I'm
  589. 32:58not going to describe the prompt
  590. 33:00afterwards. I'm going to write it, sand
  591. 33:03it, and use the results. Okay,
  592. 33:07so I already have this prepared. I'm
  593. 33:10going to copy and paste it inside of
  594. 33:15Codeex.
  595. 33:17So, let me open up Codeex.
  596. 33:26There it is.
  597. 33:34There it goes.
  598. 33:37Right.
  599. 33:39I'm going to use 5.6 salt or whatever
  600. 33:43you have. I'm going to paste this whole
  601. 33:45code. Let me write it to you. Let me
  602. 33:48read it to you guys. Okay. So, it's very
  603. 33:53simple and you can copy paste. You are
  604. 33:56an experienced Pine script developer and
  605. 34:00systematic trading researcher. Create a
  606. 34:03trading view strategy in Pine version
  607. 34:05six based on the following
  608. 34:07specification.
  609. 34:09And these are the specification.
  610. 34:12Use the trading view symbol selected by
  611. 34:14the user. Do not hardcode a ticker. Do
  612. 34:16use American New York at the session
  613. 34:18time zone. Do not use the computer's
  614. 34:20local time zone or the charts time zone.
  615. 34:23The trading session begins at 9:30 New
  616. 34:25York time. The opening range lasts for
  617. 34:2715 minutes and end 9:45 New York time.
  618. 34:30During the opening range, record the
  619. 34:32highest high. Record the highest low. Do
  620. 34:34not open any trade. After the opening
  621. 34:36range is complete, enter long only after
  622. 34:39a confirmed candle closes above the
  623. 34:42opening range high. Enter short only
  624. 34:44after a confirmed candle closes below
  625. 34:46the opening range low. Allow only one
  626. 34:49entry per session. Do not reverse the
  627. 34:52position during the same session. For a
  628. 34:55long trade, place the stop- loss at the
  629. 34:56opening range low. Calculate the profit
  630. 34:58target using a configurable
  631. 35:00risk-to-reward ratio. For a short trade,
  632. 35:03place the stop- loss at opening range
  633. 35:05high. Calculate the profit target using
  634. 35:08the same configurable risk-to-reward
  635. 35:10ratio. Use a default risk-to-reward
  636. 35:12ratio of 2.0. Close any open position at
  637. 35:16the session end. Do not hold positions
  638. 35:18overnight. Create inputs for sessions
  639. 35:20serve time, sessions and time, opening
  640. 35:22range duration, riskto-reward ratio,
  641. 35:24position size, commission, sleepage,
  642. 35:28visual requirement. Plot the opening
  643. 35:31range high and low, shady opening range
  644. 35:33area. Plot the active stop-loss and
  645. 35:35target. Mark long and short entries.
  646. 35:38Include an optional debug mode.
  647. 35:40Technical requirements. Use confirm bar
  648. 35:43data. Avoid look ahead bias. Reset all
  649. 35:47daily and session variables correctly.
  650. 35:50Make the code readable. Add commands
  651. 35:53explaining the session logic and trade
  652. 35:56logic. Include alerts for long entries,
  653. 35:59short entries, stop losses, target, and
  654. 36:02sessions close.
  655. 36:05Before providing the coin the code,
  656. 36:08explain the main assumption and
  657. 36:11execution model. then provide the
  658. 36:13complete fine script.
  659. 36:16Right? Here we go. So this is it.
  660. 36:23Is that everything clear?
  661. 36:26Do you guys have any questions about it?
  662. 36:30Please let me know in the chat.
  663. 36:39Beautiful.
  664. 36:41Beautiful,
  665. 36:52right? Okay, cool. Let's send it to
  666. 36:55codeex
  667. 36:57and wait.
  668. 37:03So while the code is being generated
  669. 37:08by codeex notice what we are doing we
  670. 37:13are not asking codeex to find a
  671. 37:15profitable strategy. We are not asking
  672. 37:18it to optimize the parameters. We are
  673. 37:20not asking it to add indicators until
  674. 37:23the equity curve looks good. We are
  675. 37:26asking it to implement a clearly defined
  676. 37:31hypothesis.
  677. 37:33That distinction is extremely important.
  678. 37:37If we ask codeex to make the strategy
  679. 37:40profitable, it may change the rules and
  680. 37:44filters or optimize parameters before we
  681. 37:48even understand the baseline.
  682. 37:51So for now, we need a faithful
  683. 37:54implementation,
  684. 37:55right? We need to wait. It's going to
  685. 37:57take
  686. 37:59a little bit of time. So, if you have
  687. 38:02questions, this is a very good moment to
  688. 38:04ask
  689. 38:10or we're just going to wait.
  690. 38:15[snorts]
  691. 38:27assumptions and execution models.
  692. 38:31Right here it comes.
  693. 38:34Coded codex is writing the code
  694. 38:40based on my hypothesis.
  695. 38:50It's going to be ready very soon and
  696. 38:53we're going to test it in the chart.
  697. 39:00If you want the full code,
  698. 39:03I mean the prompt to generate the code,
  699. 39:08just follow me on Instagram official and
  700. 39:11ask or you follow and subscribe to my
  701. 39:14YouTube channel and you command by
  702. 39:18asking.
  703. 39:22that
  704. 39:34there it is. It's ready. It didn't take
  705. 39:37more than five minutes. Right now
  706. 39:41before copying it into trading view I'm
  707. 39:46going to ask codeex to explain the most
  708. 39:50important parts.
  709. 39:53So
  710. 39:55I'm going to ask this very prompt.
  711. 40:00I'm going to ask this.
  712. 40:03Review the script you just created. Do
  713. 40:06not rewrite the code yet. Explain how
  714. 40:09the session is detected, how the opening
  715. 40:11range begins and ends, how the high and
  716. 40:14lows are stored, etc., etc., etc., etc.
  717. 40:17Identify any possible bug or ambiguity.
  718. 40:21Right? This review is very useful
  719. 40:27because it forces us to understand the
  720. 40:30code before trusting it. So if codeex
  721. 40:35says that the range is being calculated
  722. 40:37using future bars we know there is a
  723. 40:40problem. If it says the that entries are
  724. 40:44generated
  725. 40:46intraar that does not match our
  726. 40:48specification. If it says that the
  727. 40:51strategy can reopen a trade after the
  728. 40:53first one closes we know the sessions
  729. 40:55lock is incomplete. The explanation is
  730. 40:59not a substitute for testing, but it
  731. 41:02help us know what to look for on the
  732. 41:06chart.
  733. 41:07Right? Let's see.
  734. 41:11As you can see, is automatically fixing,
  735. 41:15reviewing possible bugs and ambiguities,
  736. 41:18possible duplicate exit alerts, and it's
  737. 41:21going to fix the code by itself. So just
  738. 41:25be aware that we might have a partially
  739. 41:30working code. It might not be completed.
  740. 41:34Uh
  741. 41:37so if it's not working on the first
  742. 41:39trial, you just keep on asking codeex to
  743. 41:43fix because trading view is going to
  744. 41:44give you what's not working and you got
  745. 41:48to go back and forth maybe a few time.
  746. 41:50I'm not going to do this right now.
  747. 41:53Okay,
  748. 41:55now we're asking now write
  749. 41:59the final fixed code
  750. 42:03ready to copy and paste
  751. 42:08into trading view.
  752. 42:11So I'm going to fix it later if it's not
  753. 42:13working right now. I'm going to just
  754. 42:15show you a version that is already done
  755. 42:19by me.
  756. 42:20It's very similar but with more complex
  757. 42:23rules, more advanced rules just to show
  758. 42:27you guys. [snorts] Let's see.
  759. 43:25Here
  760. 43:29he comes.
  761. 43:41We're going to create a new strategy
  762. 43:48and we're going to copy and paste the
  763. 43:51code inside of Trading View.
  764. 43:54We're going to save with the name save
  765. 43:58script
  766. 44:00New York opening range breakout funer
  767. 44:03pro.
  768. 44:05Save. And we're going to add it to the
  769. 44:07shot.
  770. 44:09Now, as it's um
  771. 44:14compiling, it might find
  772. 44:18some errors. Like, as you can see, it
  773. 44:20just found an error. We're going to go
  774. 44:22back to Codeex, give it the error and
  775. 44:26ask it to fix it and give us back the
  776. 44:29full code. Now, for the purposes of this
  777. 44:31live, we're going to have the full code.
  778. 44:33I'm going to show it to you the next
  779. 44:34time. I don't want to waste your time
  780. 44:37right now. Okay, write the full final
  781. 44:42code. Fix it. Let me see if it can make
  782. 44:45it within the end. But you're going to
  783. 44:48find something that look like this.
  784. 44:52This is one of the the orb strategy that
  785. 44:55I coded and it's going to detect the
  786. 45:00exact range is going to place your
  787. 45:02stop-loss, your entry point and your
  788. 45:04takerit and most importantly
  789. 45:08it's going to give you some
  790. 45:12reports such as key stats like total
  791. 45:16profit and loss into the last April
  792. 45:19July. So it's three month risking 1% per
  793. 45:22trade. It makes 3.51
  794. 45:25with a 3.28 draw down. Uh 58%
  795. 45:31profitable trades. Profit factor 1.2 and
  796. 45:34a lot of um a lot of
  797. 45:39key metrics.
  798. 45:41Okay.
  799. 45:43And we're going to talk about all of
  800. 45:44these in detail in the next sessions as
  801. 45:47well as every trades taken taking in
  802. 45:52consideration
  803. 45:54the best
  804. 45:57the best uh set of
  805. 46:02uh historical
  806. 46:04um data which is more or less 40 ticks
  807. 46:08per bar with high definition.
  808. 46:12uh is going to
  809. 46:14execute the the script on the bar
  810. 46:16clause. We added some I added some
  811. 46:19commission 0.525 per contract. I added
  812. 46:23two ticks of of slippage. I added one
  813. 46:26tick of extra order execution delay with
  814. 46:30it's very similar to what happens in
  815. 46:32reality as well as inputs area where you
  816. 46:35can put all your data. So you're gonna
  817. 46:38find yourself into
  818. 46:41something that look like this. And you
  819. 46:43can go back in time and back test more.
  820. 46:45It's going to take more time. After
  821. 46:47that, we're going to do uh some
  822. 46:50optimization,
  823. 46:52some validation, and then deploy it
  824. 46:55live. Let me see if it picks up the code
  825. 46:57in the meantime. If not, no worries.
  826. 46:59We're going to do it offline.
  827. 47:02[snorts]
  828. 47:04No variables alternative
  829. 47:07on character use the block copy button.
  830. 47:10Let me let me try again.
  831. 47:13Let me try again. But it's just this
  832. 47:16first
  833. 47:20should work.
  834. 47:25Just added few more.
  835. 47:29Here it is. Our opening range script is
  836. 47:32now ready. As you can see it it okay we
  837. 47:37have a problem with impagination.
  838. 47:41Okay. This should move this should stay
  839. 47:44fixed into the chart but no problem we
  840. 47:46can fix that very easily. We have our
  841. 47:48session start time. We have our session
  842. 47:50end time. We have our opening
  843. 47:53uh range duration risk to reward
  844. 47:55position sites in contracts and the bug
  845. 47:57mode to pigs everything else. We can use
  846. 48:01we can choose the sides we can use this
  847. 48:03we can use this
  848. 48:06for example
  849. 48:09commission 0.25 25 per contract
  850. 48:13and one tick more execution delay. One
  851. 48:17tick, [snorts] one tick of sleepage.
  852. 48:20There it goes. Let's see. And you're
  853. 48:22going to have your report.
  854. 48:25Okay, this this is not looking good, but
  855. 48:28we're going to work on that with
  856. 48:30optimization. Okay, you can go even for
  857. 48:34355 and it's going to do exactly it's
  858. 48:38going to tell you exactly what to do and
  859. 48:40when to do it.
  860. 48:44Okay. Uh so we're going to fix it. No
  861. 48:47worries. We're going to fix it and it's
  862. 48:49going to look much better something like
  863. 48:51this. But you just saw how starting from
  864. 48:56an idea and hypothesis we define the orb
  865. 49:01using the XA rules.
  866. 49:04Right? Then we created a detailed prompt
  867. 49:08for codeex that you can use for any
  868. 49:10other hypothesis you might have. We used
  869. 49:13codeex to generate the pine script. We
  870. 49:16copied the script into trading view. We
  871. 49:18inspected the trading range, the
  872. 49:20entries, the stop-loss, the target and
  873. 49:22the session behavior. And we also looked
  874. 49:25how to debug a problem without asking
  875. 49:29codeex to rewrite everything from
  876. 49:32scratch. Just giving back the errors or
  877. 49:34what we're seeing right now. I'm going
  878. 49:35to say, okay, the range stays stuck in
  879. 49:38the chat is not moving with the with the
  880. 49:41candles. Please fix it. We can also
  881. 49:44provide some screenshot. Okay. And
  882. 49:49this is the process that we will
  883. 49:53continue throughout this project. The
  884. 49:56first version is not supposed to answer
  885. 50:00every question. It is supposed to create
  886. 50:03a reliable starting point. Now we have a
  887. 50:07baseline that can generate a list of
  888. 50:10trades. And that list of trade is what
  889. 50:13we need for the next lesson because the
  890. 50:17next question is no longer can we hold
  891. 50:22this idea. The next question is does
  892. 50:25this idea still make sense when we
  893. 50:28analyze the evidence.
  894. 50:31That is where real research begins.
  895. 50:36Thank you guys for being here with me
  896. 50:37today. Uh you can find the full video
  897. 50:41into
  898. 50:44Thunder Pro YouTube channel and on which
  899. 50:48is my channel. You can find the name
  900. 50:50right there. And you're going to find it
  901. 50:52also in
  902. 51:14Challenge instant futures
  903. 51:33trading
  904. 51:35quanti.
  905. 51:40Thank you so much. Have a great day and
  906. 51:42see you soon. Bye.

About this transcript

This page contains the full transcript of CODING TRADING AUTOMATIONS | July 24 | Michele Rossi by FunderPro, generated from the public captions YouTube serves with the video. The transcript has 5,360 words across 906 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.