YouTube2Text

Amazing RSI trading bot in mql5! | MT5 programming — Transcript

by Antovis Analytics · 3,241 words · 590 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hey, this is Toby. Today I will show you
  2. 0:01how to code a strategy with 100% win
  3. 0:04rate. Let's go.
  4. 0:07So, this is the backtest result here for
  5. 0:09this strategy. If we take a look at the
  6. 0:12statistic, we can see 100% winning
  7. 0:14trades, not one losing trade in this
  8. 0:16backtest. And in this video, I will show
  9. 0:18you how to code the strategy. It's very
  10. 0:20simple. And in the end, we will also do
  11. 0:22additional backtests with the strategy.
  12. 0:25Okay, so let's jump right into
  13. 0:26MetaEditor and we start coding. So, here
  14. 0:28we are in the MetaEditor.
  15. 0:30Um
  16. 0:31This is the RSI EA we coded last time
  17. 0:34here on this channel.
  18. 0:35We will use this EA and this code here
  19. 0:38and we will modify it a little bit and
  20. 0:40add a filter to this RSI indicator.
  21. 0:43So, if you have not watched the last
  22. 0:45video where we created this code here,
  23. 0:48I will link it up here so you can go
  24. 0:49watch it first.
  25. 0:50And we will use this code, modify it a
  26. 0:53little bit, add a filter to get the 100%
  27. 0:56win trade strategy.
  28. 0:58Okay, so let's save this file here with
  29. 1:00a new name.
  30. 1:03Um let's call it
  31. 1:05RSI
  32. 1:06MA
  33. 1:08filter
  34. 1:09EA.
  35. 1:12Save.
  36. 1:13And now we have a new file where we can
  37. 1:15create our strategy. So, let's compile
  38. 1:17first. Okay, no warnings, no errors,
  39. 1:20perfect. Okay, so let's start here at
  40. 1:22the top.
  41. 1:23This comment section here, I don't need
  42. 1:26this. So, I will just delete it. So, we
  43. 1:28start with the properties. Um copyright,
  44. 1:31of course, we have
  45. 1:3223 now.
  46. 1:35Um
  47. 1:36Okay, then we have our include.
  48. 1:39This will stay the same.
  49. 1:41Now here we start with the inputs to
  50. 1:42modify them a little bit. So, we will
  51. 1:44just add here after the RSI level
  52. 1:48um a input for a moving average period.
  53. 1:52So, also of type integer. And let's call
  54. 1:55it input
  55. 1:58MI
  56. 2:01period.
  57. 2:02Um default value maybe also 21. One.
  58. 2:08And a comment
  59. 2:13moving average period. So,
  60. 2:15uh you already know the filter will be a
  61. 2:17simple moving average um
  62. 2:20indicator
  63. 2:21that we add to the RSI signal here.
  64. 2:24And another input we want for the moving
  65. 2:27average um indicator
  66. 2:29is the time frame that it is running on.
  67. 2:32So, input this type of enum
  68. 2:38time frames. This is the type.
  69. 2:40And the name is input
  70. 2:43MA
  71. 2:46time frame.
  72. 2:47And let's set it the default value to
  73. 2:51I don't know, period
  74. 2:53H1.
  75. 2:56Also a comment here.
  76. 3:01Okay.
  77. 3:03Now, we also need a stop loss take
  78. 3:04profit. This all stays the same and we
  79. 3:07also have the
  80. 3:08option to close our trades with a
  81. 3:10opposite signal of the RSI.
  82. 3:14Okay, so let's compile.
  83. 3:17And that's it for the inputs.
  84. 3:19Uh now we can take a look at the global
  85. 3:20variables. Okay, so now here in the
  86. 3:22global variables section um
  87. 3:25of course we need another handle for the
  88. 3:27moving average and also another buffer
  89. 3:29for the moving average.
  90. 3:31But first of all, we want to rename this
  91. 3:34handle here to handle RSI for example
  92. 3:36and buffer RSI.
  93. 3:38So, to do this, um if we just
  94. 3:41add here RSI and then we compile, we get
  95. 3:44a lot of a lot of errors.
  96. 3:46So, because down uh in the on tick
  97. 3:48function and so, the handle is still
  98. 3:50called just handle. So, we can use
  99. 3:54the um search and replace function. So,
  100. 3:57we just select the handle, press control
  101. 4:00F,
  102. 4:01and now here we can just
  103. 4:04replace
  104. 4:05the name handle with handle
  105. 4:08RSI.
  106. 4:10Uh make sure to select only this one
  107. 4:12here, match whole word only, and now we
  108. 4:16can click on replace all,
  109. 4:18and this will replace all handles with
  110. 4:21handle RSI.
  111. 4:23Okay, and we do the same for the buffer.
  112. 4:25Control F.
  113. 4:27Um
  114. 4:28buffer RSI,
  115. 4:31and replace all.
  116. 4:34Okay, so now if we compile,
  117. 4:36we should be fine and have no errors.
  118. 4:40Okay, now we want to add the handle for
  119. 4:42the moving average
  120. 4:44um indicator. So, handle
  121. 4:48MA for moving average,
  122. 4:50and a buffer for the moving average. So,
  123. 4:53buffer
  124. 4:54MA.
  125. 4:56Okay, we also need the current tick. We
  126. 4:58also need the CTrade um class and the
  127. 5:01trade object here.
  128. 5:03For this EA, we don't need the open time
  129. 5:05buy and open time sell variables, but uh
  130. 5:08we will delete them in the end because
  131. 5:09if we delete them now, we will have
  132. 5:12uh we cannot compile without a error,
  133. 5:15basically. So, I will just make sure
  134. 5:17that we don't forget about this to
  135. 5:18delete them.
  136. 5:21And write a
  137. 5:23comment here.
  138. 5:26Okay.
  139. 5:27Let's compile. So, that's it for the
  140. 5:29global variables, and now we can take a
  141. 5:31look at the on init function. Okay, so
  142. 5:33let's scroll down to the on init
  143. 5:35function here, and
  144. 5:38of course,
  145. 5:39here we check for the user inputs. Um
  146. 5:40this will all stay the same,
  147. 5:43but we want to add
  148. 5:44um another check for the moving average
  149. 5:46period. So, let's just copy this
  150. 5:49RSI period check here, paste it
  151. 5:52right here.
  152. 5:54Uh let's rename it input MA period. This
  153. 5:58should not be less or equal to one
  154. 6:00because a moving average period
  155. 6:02of one
  156. 6:04um doesn't really make sense or less.
  157. 6:06So, let's also rename the alert function
  158. 6:08here MA period less or equal to one.
  159. 6:12Okay, so that's for the user check here,
  160. 6:14user input check.
  161. 6:16Now, here we still create the
  162. 6:20sets the magic number.
  163. 6:21And here we create the RSI handle. Now,
  164. 6:23here of course we need to add
  165. 6:25to to also create the moving average
  166. 6:27handle. So, let's rename this comment
  167. 6:29here create um indicator
  168. 6:33handles.
  169. 6:34And for the RSI handle,
  170. 6:37we now want to use the price open, not
  171. 6:40the price close. So, here we will change
  172. 6:43this to price open
  173. 6:45mode.
  174. 6:46Um
  175. 6:49yeah, this is still the same. So, let's
  176. 6:51just copy
  177. 6:53this, paste it down here to create the
  178. 6:55moving average um handle.
  179. 6:57So, handle
  180. 6:59MA.
  181. 7:01Now, the function is I
  182. 7:04MA.
  183. 7:05And I think for the parameters, they are
  184. 7:08pretty much the same.
  185. 7:10Um but for the period, of course, now we
  186. 7:12will have our input
  187. 7:15MA time frame period we want to use.
  188. 7:19The moving average period is our input
  189. 7:22MA period.
  190. 7:24Um the shift will be zero.
  191. 7:27Um mode, we will just use a simple
  192. 7:29moving average here.
  193. 7:31And applied price or handle, we will
  194. 7:34just Yeah, we will also use the price
  195. 7:36open
  196. 7:38for this moving average.
  197. 7:42Okay, now we also change this here to
  198. 7:45handle MA.
  199. 7:47Um, failed to create indicator.
  200. 7:50Handle MA.
  201. 7:54Okay, and also we want to
  202. 7:57set the buffer here.
  203. 7:59Set
  204. 8:02We just
  205. 8:03set buffer as series here and we will
  206. 8:04just add
  207. 8:07another line
  208. 8:08for the buffer
  209. 8:11moving average.
  210. 8:12Okay.
  211. 8:13I think that's it for the on
  212. 8:15init function here.
  213. 8:17Let's compile.
  214. 8:19And
  215. 8:20yeah, we can take a look at the on the
  216. 8:22init function next. So, let's scroll
  217. 8:24down a little bit. So, in the on deinit
  218. 8:25function here, uh, we just need
  219. 8:28to add, of course, another line for the
  220. 8:30moving average period, uh, moving
  221. 8:32average indicator. So, release indicator
  222. 8:36handles.
  223. 8:38Um,
  224. 8:39let's copy and paste this.
  225. 8:42Handle moving average and also here
  226. 8:46handle MA.
  227. 8:48Okay, let's compile. That's all we need
  228. 8:50to edit here for the on deinit function.
  229. 8:52Uh, now let's take a look at the on tick
  230. 8:54function. Okay, so here, first of all,
  231. 8:56in the on tick, um,
  232. 8:58we want to check if the current tick is
  233. 9:00a new bar open tick because we only want
  234. 9:03to
  235. 9:05um, work with our EA on open ticks of
  236. 9:08new bars.
  237. 9:09So, we will write a comment here.
  238. 9:13Check if
  239. 9:14current tick is a
  240. 9:17new bar open tick.
  241. 9:20And
  242. 9:21now we write a if statement here and we
  243. 9:23will call a custom function we will code
  244. 9:25in a a few seconds. So,
  245. 9:28um, the function is called is
  246. 9:31new bar.
  247. 9:34And if this function here returns false,
  248. 9:37so it's not a new um, bar open tick. We
  249. 9:40will also just return here.
  250. 9:42And we will wait for the next bar open
  251. 9:44tick basically.
  252. 9:47Okay, now this function here
  253. 9:49we already coded this in a few other
  254. 9:52EAs, so I will just copy and paste it.
  255. 9:55But I will explain
  256. 9:57the function for you. So, I think we
  257. 10:00used this function here in the Bollinger
  258. 10:02Bands EA.
  259. 10:04And yeah, down here it is. So, I will
  260. 10:06just copy this from here.
  261. 10:09Now let's go down to the custom function
  262. 10:13function section here.
  263. 10:15And we will just add this function here
  264. 10:17at the top.
  265. 10:20So,
  266. 10:21this function just returns true or false
  267. 10:23whenever the tick
  268. 10:25is a bar open tick or not.
  269. 10:28So, we will just have a static variable
  270. 10:30here of type date time previous time set
  271. 10:32to zero at the start.
  272. 10:35Uh another variable here current time.
  273. 10:37This is the current time of the bar
  274. 10:39open.
  275. 10:41And then we just check if the previous
  276. 10:43time is not equal to the current time.
  277. 10:45We set the previous time to the current
  278. 10:47time and return true. And otherwise, we
  279. 10:49return false.
  280. 10:51So, that's it for the function and I
  281. 10:52just copy and paste it here because
  282. 10:55yeah, I'm lazy.
  283. 10:57Okay, but you can code it.
  284. 10:59Just pause for a second and code it.
  285. 11:02Okay, now we can go up
  286. 11:04to the on tick function again and we
  287. 11:06should be able to compile.
  288. 11:09Yes, everything works fine.
  289. 11:12And now the next step in the on tick
  290. 11:14function will be to get the values for
  291. 11:17the moving average. Okay, so we will
  292. 11:19just
  293. 11:20copy the section here get RSI values.
  294. 11:24And we will use the same code to get
  295. 11:27our moving average values.
  296. 11:30Or just value because we only need one
  297. 11:32value for the moving average.
  298. 11:34Um so
  299. 11:36here of course we don't need to declare
  300. 11:40um this variable again because we
  301. 11:42already have declared here. So we just
  302. 11:45use it here. Copy buffer
  303. 11:47handle of course now is the handle
  304. 11:49moving average.
  305. 11:51Um
  306. 11:52so this will be also zero for the main.
  307. 11:54You can also write here main main line
  308. 11:57for example.
  309. 11:59Um for the moving average, but I will
  310. 12:02just use zero zero and one here because
  311. 12:05we only want one the latest value.
  312. 12:08And of course we will store this value
  313. 12:10here in our buffer moving average.
  314. 12:14Okay, now here we need to change this
  315. 12:15values
  316. 12:17not equal to one. Then we want to print
  317. 12:19a error message failed to get indicator
  318. 12:21values.
  319. 12:22Uh maybe we change this print statement
  320. 12:24here failed to get
  321. 12:27MA
  322. 12:29value and also here failed to get
  323. 12:32RSI values.
  324. 12:35Okay.
  325. 12:36So let's compile.
  326. 12:38And in order to be able to check if the
  327. 12:41values are correct, um
  328. 12:43we use the comment function here. So
  329. 12:46here is the value for the first RSI
  330. 12:49buffer.
  331. 12:51Um
  332. 12:52of course for the RSI we have two
  333. 12:53values, so we will add another line
  334. 12:56here.
  335. 12:57\n
  336. 12:58RSI one
  337. 13:01RSI one
  338. 13:02and here the next line will be for
  339. 13:05buffer MA.
  340. 13:09The latest value.
  341. 13:10So also here buffer MA
  342. 13:13and index zero.
  343. 13:17Okay, let's compile. Okay, now we can
  344. 13:20start a quick visual test here to check
  345. 13:22if the values we're getting here from
  346. 13:24the copy buffer functions um are
  347. 13:27correct.
  348. 13:28So, we will just
  349. 13:30switch to the tester here.
  350. 13:32We will select our
  351. 13:34RSI MA filter EA here.
  352. 13:37And we'll just start a visual test.
  353. 13:42Um,
  354. 13:44yeah, now you can see
  355. 13:47the values up here, top left corner.
  356. 13:50And
  357. 13:52if you
  358. 13:54choose the crosshair here, you can see
  359. 13:56the current value, um,
  360. 13:58of the RSI here in this data window.
  361. 14:01So, if we just
  362. 14:05um,
  363. 14:07let it run a little bit. And now let's
  364. 14:09take a look at the latest value.
  365. 14:12This is 47.64
  366. 14:15in the data window.
  367. 14:16And up
  368. 14:18left corner is also 47.64.
  369. 14:22So, the first RSI value is correct. Now,
  370. 14:24the previous RSI value is 50.39
  371. 14:28in the data window and up in the top
  372. 14:30left corner it's also 50.389.
  373. 14:33Of course, it's rounded, so that's
  374. 14:35correct. Now, the moving average value
  375. 14:37here here is 77.17.
  376. 14:42And we can
  377. 14:43take a look at this here at the second
  378. 14:44chart
  379. 14:45because this is now the time frame
  380. 14:48H1.
  381. 14:49Um,
  382. 14:51take a look at the latest value here, we
  383. 14:54can see in the data window it's also 70
  384. 14:577.17.
  385. 14:59Okay, so the values we are getting here
  386. 15:01uh, for our RSI and moving average
  387. 15:04um, are correct and we can close this
  388. 15:08tester window again and go back to the
  389. 15:10editor.
  390. 15:11Okay. So, the last, um, step we need to
  391. 15:13do here in the on tick function is to
  392. 15:16add
  393. 15:17our moving average filter to the
  394. 15:20condition where we check for a new buy
  395. 15:22position and a new sell position.
  396. 15:25So, this count open position here stays
  397. 15:26the same.
  398. 15:28And now here for the check for a buy
  399. 15:30position,
  400. 15:31the RSI condition is also the same.
  401. 15:33And now as I said in the beginning, we
  402. 15:35don't need this open time buy variable
  403. 15:37here anymore.
  404. 15:39Uh so, we delete it and add the
  405. 15:41condition for the moving average filter.
  406. 15:43So, we only want to take a buy position
  407. 15:46when the price is above the current
  408. 15:48moving average value and a sell position
  409. 15:51when we are below the moving average.
  410. 15:53So, we can just use our current tick
  411. 15:55variable here {dot} ask and this has to
  412. 15:58be greater than our current moving
  413. 16:01average
  414. 16:03value.
  415. 16:05And now here, of course, we don't need
  416. 16:07to set the time open time buy variable
  417. 16:09here. So, we delete this line.
  418. 16:12Uh we still have the option to close the
  419. 16:15sell positions here.
  420. 16:16We calculate stop loss take profit,
  421. 16:18normalize the stop loss take profit. And
  422. 16:20we open a buy position here.
  423. 16:22Um maybe we also want to change the
  424. 16:24comment here
  425. 16:26RSI MA
  426. 16:28filter or something like this. Okay.
  427. 16:31And we do the same for the sell
  428. 16:33condition here.
  429. 16:35The RSI condition stays the same. Open
  430. 16:38time is sell.
  431. 16:41Uh we will delete this condition and we
  432. 16:43add current tick {dot} bid has
  433. 16:47to be below
  434. 16:48our buffer
  435. 16:51MA value.
  436. 16:53And we also delete this line here.
  437. 16:57Um yeah, everything else um stays the
  438. 17:00same. And we just change the comment
  439. 17:02here.
  440. 17:05MA filter EA.
  441. 17:06Okay.
  442. 17:09And now we want to go or let's compile
  443. 17:12first.
  444. 17:13And now we go up and delete
  445. 17:17here the two global variables. We don't
  446. 17:19need them anymore.
  447. 17:21And let's compile again and this should
  448. 17:23be it for our EA.
  449. 17:26Now I will scroll through the code again
  450. 17:29from top to bottom just so you don't
  451. 17:31need the previous RSI tutorial and just
  452. 17:35code everything from this video here.
  453. 17:41So this is the on tick function.
  454. 17:44And down here we have our custom
  455. 17:46functions.
  456. 17:47The count open positions function, the
  457. 17:50normalized price and the close positions
  458. 17:52function.
  459. 17:53Okay, so let's switch to MetaTrader
  460. 17:55platform and we can do a few back tests.
  461. 17:58Okay, so here we are in the strategy
  462. 17:59tester. Just make sure to select the RSI
  463. 18:02MA filter EA we just
  464. 18:05created.
  465. 18:06I will use the US dollar Japanese yen.
  466. 18:09It's a custom symbol for this test and
  467. 18:11the time frame is 5 minutes.
  468. 18:14We will start in 2012
  469. 18:18to today.
  470. 18:19No delay here.
  471. 18:22Now the modeling mode, of course we
  472. 18:24select the open price only mode because
  473. 18:26we only react on open ticks anyways.
  474. 18:29So it's just much faster.
  475. 18:32Maybe we start with with a visual test
  476. 18:35here to see a few trades.
  477. 18:37And now let's take a look at the inputs
  478. 18:39here. So the inputs for this test
  479. 18:43um
  480. 18:44will be 25 for the RSI period, 70 for
  481. 18:47the RSI level, 25 for the moving average
  482. 18:51period.
  483. 18:52Time frame for the moving average is 1
  484. 18:54hour
  485. 18:55and no stop loss, take profit of 100
  486. 18:57points.
  487. 18:58And we also
  488. 19:00have the option to close the trades on a
  489. 19:02opposite signal.
  490. 19:04Okay.
  491. 19:05So let's do a
  492. 19:08visual test
  493. 19:10and we will take a look at the few
  494. 19:11trades of the strategy.
  495. 19:17Um, of course you can see the moving
  496. 19:18average, um,
  497. 19:20here on the second chart on the 1-hour
  498. 19:23time frame.
  499. 19:24This is our filter.
  500. 19:26And this here the RSI is our signal.
  501. 19:28So, let's take a look at the few trades
  502. 19:30here. We can see this was a
  503. 19:32sell trade
  504. 19:33here and we closed in profit at the take
  505. 19:35profit.
  506. 19:38Um, here was a short buy trade.
  507. 19:42Here
  508. 19:43we opened the buy trade here where we
  509. 19:47crossed into the oversold region with
  510. 19:48the RSI indicator. And then we closed
  511. 19:51the position here at the take profit.
  512. 19:54Okay, so
  513. 19:56the trades, um, are working correctly.
  514. 19:59And now we can deselect here this visual
  515. 20:02mode and we can do a
  516. 20:04back test
  517. 20:07for the last 10 years. Okay, you can see
  518. 20:10this is the equity graph of the
  519. 20:11strategy. Um,
  520. 20:14yeah, it's looking very nice. And as I
  521. 20:16said at the beginning, um, 100% winning
  522. 20:19trades, not one losing trade for the
  523. 20:21strategy.
  524. 20:23Okay, but I have to make a quick and
  525. 20:25important note here. Um, of course the
  526. 20:27strategy looks very nice and the back
  527. 20:28test result is amazing. No losing
  528. 20:31trades.
  529. 20:32Um, amazing equity. But would I trade
  530. 20:35something like this on a live account?
  531. 20:37No, I would never trade something like
  532. 20:38this on a live account. First of all, we
  533. 20:40don't have a stop loss uh, with the
  534. 20:42strategy.
  535. 20:44And second of all, this is just a
  536. 20:45optimization result. So, this
  537. 20:47combination
  538. 20:49is very likely to just be lucky on the
  539. 20:51period we tested.
  540. 20:53And it will not perform like this in the
  541. 20:55future.
  542. 20:56Um, but I think the combination of
  543. 21:00RSI and moving average filter has a lot
  544. 21:03of potential. Um, we We take a look at
  545. 21:06another combination. I would
  546. 21:08um trade maybe on a live account. So,
  547. 21:11the RSI period of 15.
  548. 21:15Um MA period of 10.
  549. 21:18Stop loss of 150 points and take profit
  550. 21:22of 400.
  551. 21:25Now, if you take a look at this um back
  552. 21:27test
  553. 21:28result here, we can see it's also a very
  554. 21:31nice equity graph, but we also have
  555. 21:33losing trades because we have a stop
  556. 21:35loss and this is much more likely to
  557. 21:38perform in the future because I also
  558. 21:40optimized the strategy up until here, I
  559. 21:42think, and all this other stuff here is
  560. 21:45out of sample, basically.
  561. 21:47But, of course, I would
  562. 21:49um do a lot more testing, stability
  563. 21:52testing, and so on before I would trade
  564. 21:54a strategy in the live market.
  565. 21:56Okay, but there you have it. This was
  566. 21:59our RSI
  567. 22:00um strategy with a moving average
  568. 22:02filter. And of course, now you can
  569. 22:04add other indicators as a filter, other
  570. 22:06indicators as a signal.
  571. 22:08Um just uh
  572. 22:10test everything you want. And
  573. 22:14yeah, I hope this video was helpful for
  574. 22:15you. If it was, it would be nice if you
  575. 22:17just leave a like. Um and also, if you
  576. 22:20have questions about automatic trading,
  577. 22:21about this tutorial, coding, and stuff,
  578. 22:24you can write a comment, write me um via
  579. 22:26Telegram or through my website.
  580. 22:29And yeah, I will see you in one of the
  581. 22:30next videos where I will tell you why I
  582. 22:33don't like to exit my trades with a stop
  583. 22:36loss.
  584. 22:37Um this will not be a coding video, but
  585. 22:40something for the strategy development
  586. 22:41um
  587. 22:42and playlist.
  588. 22:43Okay, so if you don't want to miss that,
  589. 22:45subscribe, and I will see you in one of
  590. 22:47the next videos. Bye.

About this transcript

This page contains the full transcript of Amazing RSI trading bot in mql5! | MT5 programming by Antovis Analytics, generated from the public captions YouTube serves with the video. The transcript has 3,241 words across 590 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.