Amazing RSI trading bot in mql5! | MT5 programming — Transcript
Full transcript
- 0:00Hey, this is Toby. Today I will show you
- 0:01how to code a strategy with 100% win
- 0:04rate. Let's go.
- 0:07So, this is the backtest result here for
- 0:09this strategy. If we take a look at the
- 0:12statistic, we can see 100% winning
- 0:14trades, not one losing trade in this
- 0:16backtest. And in this video, I will show
- 0:18you how to code the strategy. It's very
- 0:20simple. And in the end, we will also do
- 0:22additional backtests with the strategy.
- 0:25Okay, so let's jump right into
- 0:26MetaEditor and we start coding. So, here
- 0:28we are in the MetaEditor.
- 0:30Um
- 0:31This is the RSI EA we coded last time
- 0:34here on this channel.
- 0:35We will use this EA and this code here
- 0:38and we will modify it a little bit and
- 0:40add a filter to this RSI indicator.
- 0:43So, if you have not watched the last
- 0:45video where we created this code here,
- 0:48I will link it up here so you can go
- 0:49watch it first.
- 0:50And we will use this code, modify it a
- 0:53little bit, add a filter to get the 100%
- 0:56win trade strategy.
- 0:58Okay, so let's save this file here with
- 1:00a new name.
- 1:03Um let's call it
- 1:05RSI
- 1:06MA
- 1:08filter
- 1:09EA.
- 1:12Save.
- 1:13And now we have a new file where we can
- 1:15create our strategy. So, let's compile
- 1:17first. Okay, no warnings, no errors,
- 1:20perfect. Okay, so let's start here at
- 1:22the top.
- 1:23This comment section here, I don't need
- 1:26this. So, I will just delete it. So, we
- 1:28start with the properties. Um copyright,
- 1:31of course, we have
- 1:3223 now.
- 1:35Um
- 1:36Okay, then we have our include.
- 1:39This will stay the same.
- 1:41Now here we start with the inputs to
- 1:42modify them a little bit. So, we will
- 1:44just add here after the RSI level
- 1:48um a input for a moving average period.
- 1:52So, also of type integer. And let's call
- 1:55it input
- 1:58MI
- 2:01period.
- 2:02Um default value maybe also 21. One.
- 2:08And a comment
- 2:13moving average period. So,
- 2:15uh you already know the filter will be a
- 2:17simple moving average um
- 2:20indicator
- 2:21that we add to the RSI signal here.
- 2:24And another input we want for the moving
- 2:27average um indicator
- 2:29is the time frame that it is running on.
- 2:32So, input this type of enum
- 2:38time frames. This is the type.
- 2:40And the name is input
- 2:43MA
- 2:46time frame.
- 2:47And let's set it the default value to
- 2:51I don't know, period
- 2:53H1.
- 2:56Also a comment here.
- 3:01Okay.
- 3:03Now, we also need a stop loss take
- 3:04profit. This all stays the same and we
- 3:07also have the
- 3:08option to close our trades with a
- 3:10opposite signal of the RSI.
- 3:14Okay, so let's compile.
- 3:17And that's it for the inputs.
- 3:19Uh now we can take a look at the global
- 3:20variables. Okay, so now here in the
- 3:22global variables section um
- 3:25of course we need another handle for the
- 3:27moving average and also another buffer
- 3:29for the moving average.
- 3:31But first of all, we want to rename this
- 3:34handle here to handle RSI for example
- 3:36and buffer RSI.
- 3:38So, to do this, um if we just
- 3:41add here RSI and then we compile, we get
- 3:44a lot of a lot of errors.
- 3:46So, because down uh in the on tick
- 3:48function and so, the handle is still
- 3:50called just handle. So, we can use
- 3:54the um search and replace function. So,
- 3:57we just select the handle, press control
- 4:00F,
- 4:01and now here we can just
- 4:04replace
- 4:05the name handle with handle
- 4:08RSI.
- 4:10Uh make sure to select only this one
- 4:12here, match whole word only, and now we
- 4:16can click on replace all,
- 4:18and this will replace all handles with
- 4:21handle RSI.
- 4:23Okay, and we do the same for the buffer.
- 4:25Control F.
- 4:27Um
- 4:28buffer RSI,
- 4:31and replace all.
- 4:34Okay, so now if we compile,
- 4:36we should be fine and have no errors.
- 4:40Okay, now we want to add the handle for
- 4:42the moving average
- 4:44um indicator. So, handle
- 4:48MA for moving average,
- 4:50and a buffer for the moving average. So,
- 4:53buffer
- 4:54MA.
- 4:56Okay, we also need the current tick. We
- 4:58also need the CTrade um class and the
- 5:01trade object here.
- 5:03For this EA, we don't need the open time
- 5:05buy and open time sell variables, but uh
- 5:08we will delete them in the end because
- 5:09if we delete them now, we will have
- 5:12uh we cannot compile without a error,
- 5:15basically. So, I will just make sure
- 5:17that we don't forget about this to
- 5:18delete them.
- 5:21And write a
- 5:23comment here.
- 5:26Okay.
- 5:27Let's compile. So, that's it for the
- 5:29global variables, and now we can take a
- 5:31look at the on init function. Okay, so
- 5:33let's scroll down to the on init
- 5:35function here, and
- 5:38of course,
- 5:39here we check for the user inputs. Um
- 5:40this will all stay the same,
- 5:43but we want to add
- 5:44um another check for the moving average
- 5:46period. So, let's just copy this
- 5:49RSI period check here, paste it
- 5:52right here.
- 5:54Uh let's rename it input MA period. This
- 5:58should not be less or equal to one
- 6:00because a moving average period
- 6:02of one
- 6:04um doesn't really make sense or less.
- 6:06So, let's also rename the alert function
- 6:08here MA period less or equal to one.
- 6:12Okay, so that's for the user check here,
- 6:14user input check.
- 6:16Now, here we still create the
- 6:20sets the magic number.
- 6:21And here we create the RSI handle. Now,
- 6:23here of course we need to add
- 6:25to to also create the moving average
- 6:27handle. So, let's rename this comment
- 6:29here create um indicator
- 6:33handles.
- 6:34And for the RSI handle,
- 6:37we now want to use the price open, not
- 6:40the price close. So, here we will change
- 6:43this to price open
- 6:45mode.
- 6:46Um
- 6:49yeah, this is still the same. So, let's
- 6:51just copy
- 6:53this, paste it down here to create the
- 6:55moving average um handle.
- 6:57So, handle
- 6:59MA.
- 7:01Now, the function is I
- 7:04MA.
- 7:05And I think for the parameters, they are
- 7:08pretty much the same.
- 7:10Um but for the period, of course, now we
- 7:12will have our input
- 7:15MA time frame period we want to use.
- 7:19The moving average period is our input
- 7:22MA period.
- 7:24Um the shift will be zero.
- 7:27Um mode, we will just use a simple
- 7:29moving average here.
- 7:31And applied price or handle, we will
- 7:34just Yeah, we will also use the price
- 7:36open
- 7:38for this moving average.
- 7:42Okay, now we also change this here to
- 7:45handle MA.
- 7:47Um, failed to create indicator.
- 7:50Handle MA.
- 7:54Okay, and also we want to
- 7:57set the buffer here.
- 7:59Set
- 8:02We just
- 8:03set buffer as series here and we will
- 8:04just add
- 8:07another line
- 8:08for the buffer
- 8:11moving average.
- 8:12Okay.
- 8:13I think that's it for the on
- 8:15init function here.
- 8:17Let's compile.
- 8:19And
- 8:20yeah, we can take a look at the on the
- 8:22init function next. So, let's scroll
- 8:24down a little bit. So, in the on deinit
- 8:25function here, uh, we just need
- 8:28to add, of course, another line for the
- 8:30moving average period, uh, moving
- 8:32average indicator. So, release indicator
- 8:36handles.
- 8:38Um,
- 8:39let's copy and paste this.
- 8:42Handle moving average and also here
- 8:46handle MA.
- 8:48Okay, let's compile. That's all we need
- 8:50to edit here for the on deinit function.
- 8:52Uh, now let's take a look at the on tick
- 8:54function. Okay, so here, first of all,
- 8:56in the on tick, um,
- 8:58we want to check if the current tick is
- 9:00a new bar open tick because we only want
- 9:03to
- 9:05um, work with our EA on open ticks of
- 9:08new bars.
- 9:09So, we will write a comment here.
- 9:13Check if
- 9:14current tick is a
- 9:17new bar open tick.
- 9:20And
- 9:21now we write a if statement here and we
- 9:23will call a custom function we will code
- 9:25in a a few seconds. So,
- 9:28um, the function is called is
- 9:31new bar.
- 9:34And if this function here returns false,
- 9:37so it's not a new um, bar open tick. We
- 9:40will also just return here.
- 9:42And we will wait for the next bar open
- 9:44tick basically.
- 9:47Okay, now this function here
- 9:49we already coded this in a few other
- 9:52EAs, so I will just copy and paste it.
- 9:55But I will explain
- 9:57the function for you. So, I think we
- 10:00used this function here in the Bollinger
- 10:02Bands EA.
- 10:04And yeah, down here it is. So, I will
- 10:06just copy this from here.
- 10:09Now let's go down to the custom function
- 10:13function section here.
- 10:15And we will just add this function here
- 10:17at the top.
- 10:20So,
- 10:21this function just returns true or false
- 10:23whenever the tick
- 10:25is a bar open tick or not.
- 10:28So, we will just have a static variable
- 10:30here of type date time previous time set
- 10:32to zero at the start.
- 10:35Uh another variable here current time.
- 10:37This is the current time of the bar
- 10:39open.
- 10:41And then we just check if the previous
- 10:43time is not equal to the current time.
- 10:45We set the previous time to the current
- 10:47time and return true. And otherwise, we
- 10:49return false.
- 10:51So, that's it for the function and I
- 10:52just copy and paste it here because
- 10:55yeah, I'm lazy.
- 10:57Okay, but you can code it.
- 10:59Just pause for a second and code it.
- 11:02Okay, now we can go up
- 11:04to the on tick function again and we
- 11:06should be able to compile.
- 11:09Yes, everything works fine.
- 11:12And now the next step in the on tick
- 11:14function will be to get the values for
- 11:17the moving average. Okay, so we will
- 11:19just
- 11:20copy the section here get RSI values.
- 11:24And we will use the same code to get
- 11:27our moving average values.
- 11:30Or just value because we only need one
- 11:32value for the moving average.
- 11:34Um so
- 11:36here of course we don't need to declare
- 11:40um this variable again because we
- 11:42already have declared here. So we just
- 11:45use it here. Copy buffer
- 11:47handle of course now is the handle
- 11:49moving average.
- 11:51Um
- 11:52so this will be also zero for the main.
- 11:54You can also write here main main line
- 11:57for example.
- 11:59Um for the moving average, but I will
- 12:02just use zero zero and one here because
- 12:05we only want one the latest value.
- 12:08And of course we will store this value
- 12:10here in our buffer moving average.
- 12:14Okay, now here we need to change this
- 12:15values
- 12:17not equal to one. Then we want to print
- 12:19a error message failed to get indicator
- 12:21values.
- 12:22Uh maybe we change this print statement
- 12:24here failed to get
- 12:27MA
- 12:29value and also here failed to get
- 12:32RSI values.
- 12:35Okay.
- 12:36So let's compile.
- 12:38And in order to be able to check if the
- 12:41values are correct, um
- 12:43we use the comment function here. So
- 12:46here is the value for the first RSI
- 12:49buffer.
- 12:51Um
- 12:52of course for the RSI we have two
- 12:53values, so we will add another line
- 12:56here.
- 12:57\n
- 12:58RSI one
- 13:01RSI one
- 13:02and here the next line will be for
- 13:05buffer MA.
- 13:09The latest value.
- 13:10So also here buffer MA
- 13:13and index zero.
- 13:17Okay, let's compile. Okay, now we can
- 13:20start a quick visual test here to check
- 13:22if the values we're getting here from
- 13:24the copy buffer functions um are
- 13:27correct.
- 13:28So, we will just
- 13:30switch to the tester here.
- 13:32We will select our
- 13:34RSI MA filter EA here.
- 13:37And we'll just start a visual test.
- 13:42Um,
- 13:44yeah, now you can see
- 13:47the values up here, top left corner.
- 13:50And
- 13:52if you
- 13:54choose the crosshair here, you can see
- 13:56the current value, um,
- 13:58of the RSI here in this data window.
- 14:01So, if we just
- 14:05um,
- 14:07let it run a little bit. And now let's
- 14:09take a look at the latest value.
- 14:12This is 47.64
- 14:15in the data window.
- 14:16And up
- 14:18left corner is also 47.64.
- 14:22So, the first RSI value is correct. Now,
- 14:24the previous RSI value is 50.39
- 14:28in the data window and up in the top
- 14:30left corner it's also 50.389.
- 14:33Of course, it's rounded, so that's
- 14:35correct. Now, the moving average value
- 14:37here here is 77.17.
- 14:42And we can
- 14:43take a look at this here at the second
- 14:44chart
- 14:45because this is now the time frame
- 14:48H1.
- 14:49Um,
- 14:51take a look at the latest value here, we
- 14:54can see in the data window it's also 70
- 14:577.17.
- 14:59Okay, so the values we are getting here
- 15:01uh, for our RSI and moving average
- 15:04um, are correct and we can close this
- 15:08tester window again and go back to the
- 15:10editor.
- 15:11Okay. So, the last, um, step we need to
- 15:13do here in the on tick function is to
- 15:16add
- 15:17our moving average filter to the
- 15:20condition where we check for a new buy
- 15:22position and a new sell position.
- 15:25So, this count open position here stays
- 15:26the same.
- 15:28And now here for the check for a buy
- 15:30position,
- 15:31the RSI condition is also the same.
- 15:33And now as I said in the beginning, we
- 15:35don't need this open time buy variable
- 15:37here anymore.
- 15:39Uh so, we delete it and add the
- 15:41condition for the moving average filter.
- 15:43So, we only want to take a buy position
- 15:46when the price is above the current
- 15:48moving average value and a sell position
- 15:51when we are below the moving average.
- 15:53So, we can just use our current tick
- 15:55variable here {dot} ask and this has to
- 15:58be greater than our current moving
- 16:01average
- 16:03value.
- 16:05And now here, of course, we don't need
- 16:07to set the time open time buy variable
- 16:09here. So, we delete this line.
- 16:12Uh we still have the option to close the
- 16:15sell positions here.
- 16:16We calculate stop loss take profit,
- 16:18normalize the stop loss take profit. And
- 16:20we open a buy position here.
- 16:22Um maybe we also want to change the
- 16:24comment here
- 16:26RSI MA
- 16:28filter or something like this. Okay.
- 16:31And we do the same for the sell
- 16:33condition here.
- 16:35The RSI condition stays the same. Open
- 16:38time is sell.
- 16:41Uh we will delete this condition and we
- 16:43add current tick {dot} bid has
- 16:47to be below
- 16:48our buffer
- 16:51MA value.
- 16:53And we also delete this line here.
- 16:57Um yeah, everything else um stays the
- 17:00same. And we just change the comment
- 17:02here.
- 17:05MA filter EA.
- 17:06Okay.
- 17:09And now we want to go or let's compile
- 17:12first.
- 17:13And now we go up and delete
- 17:17here the two global variables. We don't
- 17:19need them anymore.
- 17:21And let's compile again and this should
- 17:23be it for our EA.
- 17:26Now I will scroll through the code again
- 17:29from top to bottom just so you don't
- 17:31need the previous RSI tutorial and just
- 17:35code everything from this video here.
- 17:41So this is the on tick function.
- 17:44And down here we have our custom
- 17:46functions.
- 17:47The count open positions function, the
- 17:50normalized price and the close positions
- 17:52function.
- 17:53Okay, so let's switch to MetaTrader
- 17:55platform and we can do a few back tests.
- 17:58Okay, so here we are in the strategy
- 17:59tester. Just make sure to select the RSI
- 18:02MA filter EA we just
- 18:05created.
- 18:06I will use the US dollar Japanese yen.
- 18:09It's a custom symbol for this test and
- 18:11the time frame is 5 minutes.
- 18:14We will start in 2012
- 18:18to today.
- 18:19No delay here.
- 18:22Now the modeling mode, of course we
- 18:24select the open price only mode because
- 18:26we only react on open ticks anyways.
- 18:29So it's just much faster.
- 18:32Maybe we start with with a visual test
- 18:35here to see a few trades.
- 18:37And now let's take a look at the inputs
- 18:39here. So the inputs for this test
- 18:43um
- 18:44will be 25 for the RSI period, 70 for
- 18:47the RSI level, 25 for the moving average
- 18:51period.
- 18:52Time frame for the moving average is 1
- 18:54hour
- 18:55and no stop loss, take profit of 100
- 18:57points.
- 18:58And we also
- 19:00have the option to close the trades on a
- 19:02opposite signal.
- 19:04Okay.
- 19:05So let's do a
- 19:08visual test
- 19:10and we will take a look at the few
- 19:11trades of the strategy.
- 19:17Um, of course you can see the moving
- 19:18average, um,
- 19:20here on the second chart on the 1-hour
- 19:23time frame.
- 19:24This is our filter.
- 19:26And this here the RSI is our signal.
- 19:28So, let's take a look at the few trades
- 19:30here. We can see this was a
- 19:32sell trade
- 19:33here and we closed in profit at the take
- 19:35profit.
- 19:38Um, here was a short buy trade.
- 19:42Here
- 19:43we opened the buy trade here where we
- 19:47crossed into the oversold region with
- 19:48the RSI indicator. And then we closed
- 19:51the position here at the take profit.
- 19:54Okay, so
- 19:56the trades, um, are working correctly.
- 19:59And now we can deselect here this visual
- 20:02mode and we can do a
- 20:04back test
- 20:07for the last 10 years. Okay, you can see
- 20:10this is the equity graph of the
- 20:11strategy. Um,
- 20:14yeah, it's looking very nice. And as I
- 20:16said at the beginning, um, 100% winning
- 20:19trades, not one losing trade for the
- 20:21strategy.
- 20:23Okay, but I have to make a quick and
- 20:25important note here. Um, of course the
- 20:27strategy looks very nice and the back
- 20:28test result is amazing. No losing
- 20:31trades.
- 20:32Um, amazing equity. But would I trade
- 20:35something like this on a live account?
- 20:37No, I would never trade something like
- 20:38this on a live account. First of all, we
- 20:40don't have a stop loss uh, with the
- 20:42strategy.
- 20:44And second of all, this is just a
- 20:45optimization result. So, this
- 20:47combination
- 20:49is very likely to just be lucky on the
- 20:51period we tested.
- 20:53And it will not perform like this in the
- 20:55future.
- 20:56Um, but I think the combination of
- 21:00RSI and moving average filter has a lot
- 21:03of potential. Um, we We take a look at
- 21:06another combination. I would
- 21:08um trade maybe on a live account. So,
- 21:11the RSI period of 15.
- 21:15Um MA period of 10.
- 21:18Stop loss of 150 points and take profit
- 21:22of 400.
- 21:25Now, if you take a look at this um back
- 21:27test
- 21:28result here, we can see it's also a very
- 21:31nice equity graph, but we also have
- 21:33losing trades because we have a stop
- 21:35loss and this is much more likely to
- 21:38perform in the future because I also
- 21:40optimized the strategy up until here, I
- 21:42think, and all this other stuff here is
- 21:45out of sample, basically.
- 21:47But, of course, I would
- 21:49um do a lot more testing, stability
- 21:52testing, and so on before I would trade
- 21:54a strategy in the live market.
- 21:56Okay, but there you have it. This was
- 21:59our RSI
- 22:00um strategy with a moving average
- 22:02filter. And of course, now you can
- 22:04add other indicators as a filter, other
- 22:06indicators as a signal.
- 22:08Um just uh
- 22:10test everything you want. And
- 22:14yeah, I hope this video was helpful for
- 22:15you. If it was, it would be nice if you
- 22:17just leave a like. Um and also, if you
- 22:20have questions about automatic trading,
- 22:21about this tutorial, coding, and stuff,
- 22:24you can write a comment, write me um via
- 22:26Telegram or through my website.
- 22:29And yeah, I will see you in one of the
- 22:30next videos where I will tell you why I
- 22:33don't like to exit my trades with a stop
- 22:36loss.
- 22:37Um this will not be a coding video, but
- 22:40something for the strategy development
- 22:41um
- 22:42and playlist.
- 22:43Okay, so if you don't want to miss that,
- 22:45subscribe, and I will see you in one of
- 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.