YouTube2Text

Optimize TradingView Strategies in Seconds (Free & Open-Source) — Transcript

by Justin Dehorty · 2,650 words · 398 segments · language en · Watch on YouTube

Full transcript

  1. 0:00If you've ever tried tuning a
  2. 0:01TradingView strategy by hand one setting
  3. 0:03[music] at a time like this, you know
  4. 0:05that it's not exactly a fun process.
  5. 0:07Very manual, extremely [music] tedious.
  6. 0:10But check this out.
  7. 0:12Every dot you see on this screen is a
  8. 0:14complete backtest. [music] In this case,
  9. 0:16literally thousands of them running in
  10. 0:18just a span of seconds.
  11. 0:20The entire [music] search is guided by a
  12. 0:22machine learning algorithm that's
  13. 0:23intelligently exploring all the
  14. 0:25different settings combinations [music]
  15. 0:26in your strategy. And the coolest part
  16. 0:28is it's all running in your browser and
  17. 0:31your laptop.
  18. 0:33I've made the technology behind it
  19. 0:34completely [music] open source and
  20. 0:35because it runs on your hardware,
  21. 0:37it's free.
  22. 0:38In this video, I'm going to do a deep
  23. 0:41dive on how it all [music] works and
  24. 0:42show you how it makes your TradingView
  25. 0:44strategies that much more powerful.
  26. 0:49Hey guys, this is Justin here and today
  27. 0:50I'm really excited to go over with you a
  28. 0:52new open source project that I've been
  29. 0:54working on as well as strategy
  30. 0:56optimization platform that is now freely
  31. 0:58available for everyone. It has been a
  32. 1:01couple years in the making. A lot of you
  33. 1:03actually on Discord and on Patreon have
  34. 1:05helped me with this in various ways and
  35. 1:07beta tested it over the past couple of
  36. 1:09years and I'm really grateful for your
  37. 1:11help on that. And today I wanted to talk
  38. 1:13specifically about a piece of technology
  39. 1:15that I'm also open sourcing that makes
  40. 1:17it all possible. And that is the Pine
  41. 1:19Wisom compiler. So it's very different
  42. 1:21than others projects out there that
  43. 1:22transform Pine Script into other
  44. 1:24language is because what this does is it
  45. 1:26takes Pine Script and directly targets
  46. 1:27WebAssembly, which gets you really high
  47. 1:30throughput near native
  48. 1:32performance for essentially testing
  49. 1:34thousands of different settings for your
  50. 1:36indicator
  51. 1:37and doing that in a matter of seconds.
  52. 1:40So right here, if you scroll down on
  53. 1:42this new website that I've built out,
  54. 1:44you'll see that right away the first
  55. 1:46section is all about how one back test
  56. 1:48is not enough. And it's interesting
  57. 1:49because when you think about back
  58. 1:51testing especially on TradingView,
  59. 1:53it tends to assume that you know what
  60. 1:55the best settings are to begin with. And
  61. 1:57that's not always true. A lot of the
  62. 1:58time you to guess with your own
  63. 2:00intuition and your own playing around.
  64. 2:03And you can see as I'm changing this for
  65. 2:05each setting, I'm arriving at different
  66. 2:07parts in this overall sort of geography,
  67. 2:10this topography down here that you see.
  68. 2:12And what's neat is you can actually
  69. 2:14change this. This is a full-fledged
  70. 2:16compiler running directly on your
  71. 2:17browser. And if I change the EMA to an
  72. 2:20SMA, for example, it is near
  73. 2:22instantaneous. It will re-backtest all
  74. 2:25225 of these configurations and show you
  75. 2:28precisely what that topography looks
  76. 2:30like. So with that said, I'm going to go
  77. 2:33through a couple of slides here to show
  78. 2:35you just how this is possible. So under
  79. 2:37the hood, I'm calling this Pine Wasm. It
  80. 2:39is going to be completely open source
  81. 2:41for you guys to take a look at. This is
  82. 2:43a preview of the GitHub page. It's 100%
  83. 2:46in Rust. And it's actually really cool
  84. 2:49how it works. So under the hood, what's
  85. 2:51happening? Again, this is 100
  86. 2:53milliseconds flat, 225 backtests to give
  87. 2:56you a sense for how this scales. It's
  88. 2:58actually scales really nicely. A lot of
  89. 3:00the time it finishes before I'm even
  90. 3:03able to render it to the screen. But you
  91. 3:05can see this was less than a second. You
  92. 3:07cranked out a couple thousand backtests
  93. 3:09for such a simple strategy. And it's
  94. 3:12really neat because it gives you a few
  95. 3:13go back here, you can see how it
  96. 3:15definitely adds in this level of
  97. 3:17granularity to the overall topography
  98. 3:19and it gives you a sense for what
  99. 3:21settings are really working well and
  100. 3:23which areas you have to watch out for.
  101. 3:25And this will definitely change as you
  102. 3:27go through time. Markets are definitely
  103. 3:30not static. They are constantly
  104. 3:31evolving. So it's really important to be
  105. 3:33able to optimize at scale very
  106. 3:36frequently. And I wanted to build a tool
  107. 3:37to help you guys do that. If you look at
  108. 3:40a lot of the other projects out there,
  109. 3:41Pine Script is famously closed source.
  110. 3:43It only works on TradingView servers,
  111. 3:45but the language itself and the spec for
  112. 3:47it is very open. You can read about it,
  113. 3:50understand at a surface level what
  114. 3:52everything does. That's called a clean
  115. 3:54room implementation.
  116. 3:56And really everything that you see out
  117. 3:58there, this is just a sampling of the
  118. 4:00top three, but there's a lot of them.
  119. 4:02Pine Forge, Pine TS, Pine Core, these
  120. 4:04are all basically acting as transpilars.
  121. 4:07So taking PineScript as a scripting
  122. 4:09language and transpiling that into
  123. 4:12another general purpose coding language.
  124. 4:15And a lot of what makes PineScript so
  125. 4:17elegant, so readable, so efficient
  126. 4:20is really lost whenever you go from
  127. 4:23PineScript into another totally
  128. 4:25different language.
  129. 4:26This is just an example of JavaScript.
  130. 4:29So what you would have to do so you
  131. 4:30would take PineScript, use the abstract
  132. 4:32syntax tree to parse out all of that
  133. 4:34semantic meaning
  134. 4:35and then of course target JavaScript. So
  135. 4:38it's quite involved, whereas this is so
  136. 4:41much faster. You can see that
  137. 4:43intermediate language is what
  138. 4:46allows me to very easily go into
  139. 4:48something like WebAssembly for instance.
  140. 4:50And the process of going from an IO into
  141. 4:52WebAssembly is very well understood.
  142. 4:54That's something that a lot of big
  143. 4:56companies have invested a lot of
  144. 4:57resources into doing. So there was a lot
  145. 5:00of precedent for this type of thing. And
  146. 5:02of course the V8 engine itself has had
  147. 5:04billions of dollars worth of R&D and
  148. 5:06it's very good at optimizing the
  149. 5:07WebAssembly thereafter. So that's part
  150. 5:09of the reason why I'm able to get such
  151. 5:11incredible speeds.
  152. 5:13So what's really cool is I'm just like
  153. 5:15the Pine TS project and others like it,
  154. 5:17it runs in your browser except this time
  155. 5:19it will compile every strategy into a
  156. 5:21standalone zero import WebAssembly
  157. 5:25module. And I've done videos on this in
  158. 5:27the past where I discussed Lean Four,
  159. 5:29but I've been absolutely obsessed with
  160. 5:31it for the past year and a half and
  161. 5:33trying it out in various projects and
  162. 5:34this being one of them.
  163. 5:36And it's incredibly powerful because
  164. 5:38just like how it does in math proofs, it
  165. 5:40tests the underlying logic of your
  166. 5:42system. So in this case the underlying
  167. 5:44logic of my compiler. Because you could
  168. 5:47quickly see how this is not exactly
  169. 5:49human readable. When you take PineScript
  170. 5:51he translated down into that bytecode
  171. 5:53representation.
  172. 5:54This is just a very small example,
  173. 5:56right? Imagine tens of millions of these
  174. 5:58essentially unrolled. Sure maybe an
  175. 5:59agent could go through and understand
  176. 6:01it, but it's actually quite difficult to
  177. 6:03prove that it's doing what you believe
  178. 6:05it's doing.
  179. 6:06And that's where formal verification
  180. 6:07comes in.
  181. 6:08So, with formal verification, again, you
  182. 6:11end up with this nice web assembly
  183. 6:13module, zero imports, so it can run at
  184. 6:16scale. You can spin it off into
  185. 6:17different V8 isolates all in
  186. 6:19simultaneously.
  187. 6:21So, it's really powerful. You compile it
  188. 6:23once and any changes you do, it just
  189. 6:25recompiles extremely quickly because,
  190. 6:28again, the entire pipeline is written in
  191. 6:29Rust.
  192. 6:30So, you can see this is really why it
  193. 6:33all works. I mentioned I've been
  194. 6:34thinking about this for a couple of
  195. 6:36years in the sense of how I would design
  196. 6:37all of the opcodes, but what really made
  197. 6:39it feasible was this formal verification
  198. 6:42workflow.
  199. 6:43As you can see, I have 38,000 plus
  200. 6:45theorems and lemmas at this point that
  201. 6:47kind of targets certain functionality
  202. 6:49and it does a lot of checks on the logic
  203. 6:52of the compiler to make sure it's
  204. 6:53working as spec.
  205. 6:55And I know of at least 10 plus really
  206. 6:58like major bugs that it found after the
  207. 6:59initial implementation of the compiler,
  208. 7:01probably dozens. But for the most part,
  209. 7:04after the first few thousand theorems
  210. 7:05and lemmas, it did catch the vast
  211. 7:07majority of them. Nowadays, it becomes
  212. 7:09very difficult to even find anything
  213. 7:11wrong with it, so it's actually quite
  214. 7:13strong. And that's part of the reason
  215. 7:14why I'm so excited to open source it. I
  216. 7:16will open source all of these theorems
  217. 7:17and lemmas as well because this was
  218. 7:20definitely not cheap to generate. I'd
  219. 7:21say I was calculating the other day how
  220. 7:23much this actually cost and it was
  221. 7:25equivalent to around $40,000 of API
  222. 7:28credits in terms of just the sheer
  223. 7:30amount of volume and inference required
  224. 7:34to actually produce the amount of
  225. 7:35theorems at this scale.
  226. 7:37So, I do want that to be open source in
  227. 7:38case anyone else wants to help
  228. 7:39contribute and prove various things
  229. 7:41about the compiler itself.
  230. 7:43But this is just a a fun example of the
  231. 7:45type of things that it's catching these
  232. 7:46days. So, there's no chart out there
  233. 7:48that's 292 million years in length. But
  234. 7:52assuming there was and the week of the
  235. 7:54year variable here that's in Pine
  236. 7:56Script, after 292 million years, it was
  237. 7:59returning this insane negative integer
  238. 8:01just due to the mechanics of the
  239. 8:03bytecode that was being generated. And I
  240. 8:05found that quite funny because there was
  241. 8:07a proof and it it and I was able to
  242. 8:09patch it very easily, of course, but it
  243. 8:11shows just how powerful formal
  244. 8:13verification is as a school of thought.
  245. 8:15It's in a lot of ways like the ultimate
  246. 8:17form of unit testing. So with that said,
  247. 8:19I did want to run through an example
  248. 8:21right now over on the optimizer main
  249. 8:24site. Okay, so here we are over at
  250. 8:27optimizer.aihedge.io/studio
  251. 8:30and I have again just very simple, a
  252. 8:33very mundane simple strategy. It's not
  253. 8:36meant to be anything serious. I have it
  254. 8:38loaded right now on 4-hour Bitcoin, I
  255. 8:41believe. Bitcoin it's almost 15,000 bars
  256. 8:44in total of 4-hour bars.
  257. 8:47And you can get this from anywhere. You
  258. 8:48can get it from Yahoo Finance. Even
  259. 8:50TradingView has their own export
  260. 8:51feature. And really it's quite easy to
  261. 8:55import it. Maybe in the future one day
  262. 8:57I'll have the ability to support live
  263. 8:59streams streaming it in. That would be
  264. 9:00really cool. But for now you do bring
  265. 9:02your own data and once that's in you can
  266. 9:04pretty much use it pretty seamlessly.
  267. 9:07So here you can see it supports version
  268. 9:086. I have this really cool tab that
  269. 9:10shows you the entire process of how it
  270. 9:12gets lowered. And it's interesting
  271. 9:14because most people stop after the AST
  272. 9:16and target a different language. But of
  273. 9:18course with us we have to go through the
  274. 9:20whole best practice process of lowering
  275. 9:22it down to an IR, an intermediate
  276. 9:24representation, and then of course the
  277. 9:26IL, which is pretty much as close to
  278. 9:28bytecode as you can possibly get, and
  279. 9:30then of course WebAssembly. But this is
  280. 9:32how the main flow would go. I have this
  281. 9:35exact same copy of this over here so you
  282. 9:38can see I have this little back testing
  283. 9:41area here that's very similar to how
  284. 9:43TradingView conceptually works.
  285. 9:46And you can see that overall the
  286. 9:48drawdown's quite terrible, but the P&L
  287. 9:51it's not bad. I do notice that the buy
  288. 9:53and hold for this very simplistic
  289. 9:54strategy is actually better than the
  290. 9:56strategy itself in a lot of cases. And
  291. 9:58of course the drawdown is not great. So
  292. 10:00the way I would do this is after you are
  293. 10:02happy with the initial settings you can
  294. 10:04simply click optimize and this will
  295. 10:06bundle it into a WebAssembly module and
  296. 10:09bring you to this
  297. 10:11And here you can see that it's written
  298. 10:13all as one sentence. You can change the
  299. 10:15data set that you're operating on, but
  300. 10:17in general just take whatever that you
  301. 10:19were just on over there.
  302. 10:21you can specify the amount of trials
  303. 10:23that you want to run, of course in the
  304. 10:24browser or if you're on one of the plans
  305. 10:27you can run it in the cloud where you
  306. 10:28can spin up a lot of different
  307. 10:29concurrent instances. So the run
  308. 10:32settings itself, I want to say like a
  309. 10:35minimum trades of 10 tends to make
  310. 10:37sense. This is a very important one. If
  311. 10:40you ever want to do this, sometimes it's
  312. 10:42useful also to throw in drawdown as a
  313. 10:45concurrent objective function.
  314. 10:47So that will make sure that you're not
  315. 10:49only optimizing for profit, but also
  316. 10:51staying reasonable in the drawdown. And
  317. 10:54there's a lot of different settings for
  318. 10:55that. I can get into that in a different
  319. 10:57video. But that's pretty much it. Once
  320. 10:59you compile it into that web assembly
  321. 11:01module, you can just start running this
  322. 11:04in the browser. And it's pretty neat.
  323. 11:06You'll see it loading up and it's very
  324. 11:09fast. It'll map out the entire
  325. 11:11topography for you. You can see it's
  326. 11:13trying every possible slow length and
  327. 11:15fast length combination here.
  328. 11:17And what's cool is that you can actually
  329. 11:20see it. So this one has a third one with
  330. 11:22exit ATR buffer. And you can see that as
  331. 11:25well evolving concurrently. So it looks
  332. 11:27like it just finished here and it brings
  333. 11:31me to this screen. So you can see this
  334. 11:33is pretty much the frontier of the
  335. 11:35tradeoffs between smaller drawdown and
  336. 11:37higher profit factor.
  337. 11:39And looking through here, this is
  338. 11:40already much better I think than the
  339. 11:42default. Even up here it's actually not
  340. 11:44too bad. To a certain point you're just
  341. 11:46going to have to change the strategy if
  342. 11:47you want to see better ones than this.
  343. 11:50But it's interesting because if you look
  344. 11:52at this, you can see the topography is
  345. 11:54quite consistent here and this confirmed
  346. 11:56that it wasn't just a fluke, that there
  347. 11:58really is a sort of mountain range here
  348. 12:00where it leads to much more stable
  349. 12:02profit factor score and also drawdown.
  350. 12:06So anytime you want to examine a part of
  351. 12:08this little mountain range, for example
  352. 12:10that one, you click that and you can
  353. 12:12just look at these settings directly in
  354. 12:13Studio. So now we're going to compare it
  355. 12:16to the original reference that we have
  356. 12:17over here.
  357. 12:19So this is the original again for
  358. 12:20comparison. So 767,000
  359. 12:24PnL
  360. 12:25and it was 1.7 profit factor with a
  361. 12:28drawdown of 46.42%
  362. 12:31and just by changing the settings and
  363. 12:34nothing else, I didn't change any code,
  364. 12:36we were able to improve this to 1.5
  365. 12:39million of PnL
  366. 12:42and a 29% drawdown with a much higher
  367. 12:45profit factor as well. Increased there
  368. 12:48almost more than doubled it. So that is
  369. 12:51a good example of how the optimizer can
  370. 12:53be used to just improve your existing
  371. 12:56strategies and find for your market and
  372. 12:58your chart that you're trading
  373. 13:00over in TradingView what the best
  374. 13:02settings are. And again, I'm not trying
  375. 13:04to replace TradingView. If anything, I
  376. 13:05want to make it easier for people to
  377. 13:08optimize their TradingView indicators
  378. 13:10and to help you get more out of the
  379. 13:12strategies that you have over there.
  380. 13:14So hopefully this was useful for you
  381. 13:15guys. Feel free to go ahead and make a
  382. 13:18free account and try it out in your
  383. 13:19browser.
  384. 13:20There are lots of things you can do for
  385. 13:22free and that is by design. I wanted
  386. 13:24this to be a tool that can really help
  387. 13:26everyone regardless of what your means
  388. 13:29and circumstances are.
  389. 13:30So let me know what you think. Pine
  390. 13:32Wizem itself is open source. I'll be
  391. 13:34open sourcing those lean proofs as well
  392. 13:37and the benchmarks as well as this
  393. 13:40repository. It'll all be public once I
  394. 13:42finish cleaning it up for you guys.
  395. 13:44So if you have any [music] questions or
  396. 13:46comments, as always, feel free to leave
  397. 13:48those down below and subscribe for
  398. 13:49future updates.

About this transcript

This page contains the full transcript of Optimize TradingView Strategies in Seconds (Free & Open-Source) by Justin Dehorty, generated from the public captions YouTube serves with the video. The transcript has 2,650 words across 398 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 choose a caption track available on the video.

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, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.