Self Optimizing RSI or MFI Trader - MetaTrader 4 Expert - MT4/MT5 Resources
My dream is to have a robot that optimizes itself so I know it is always working at optimal values. This is my humble attempt to turn my dream into reality. Additional expert advisors optimize overbought and oversold levels for placing trades. I hope others can take this concept and expand on it to create something greater, if you do please let me know. Also, don't forget to rate my bot using the stars above. This strategy works on any currency pair using any time frame, provided of course with the correct settings.
The bot lists quite a few inputs. I've added a few extra features that I enjoy using, please enjoy.
How does this robot optimize itself? The secret is that the robot tests each variable in the index indicator twice, so if the indicator has a hundred possible values, it takes each value and tries to execute a trade with that value, returning a certain number of bars ( optimization cycles) . It then rates that value based on how much money you would win or lose by trading at that value. It's a little more complicated than that, but you're reading this for more details, so here it is.
The hypothesis is that when the indicator crosses the overbought value from the top, a sell order is issued, and when the indicator crosses from below the oversold value to above the oversold value, a buy order is issued. For example, if overbought is set to 80 and the indicator value on the previous bar is 85 and the indicator value on the last bar is 79, a sell order will be issued. 85→79 crosses 80 downwards, and a sell order is issued. If oversold = 23, then 19 → 27 up will create a buy order.
Therefore, the robot takes the indicator top value - and the indicator bottom value - and runs one test, more specifically two tests. It runs buy and sell tests on each value. For example, if the top value is 100, then it will take the top value and optimize for cycles , let's say 144 cycles. So it will see if it was profitable to buy at 100 and sell at 100 over the past 144 periods. If it's profitable, it keeps that amount.
Considering how many periods you backtest, it may be possible to buy multiple times during the backtest. If TakeProfit is hit before StopLoss is hit, then it will give a profitable result; if StopLoss is hit before TakeProfit, it will give a negative result. Optimize the cycle after testing all cycles - it adds all profit results with all losses to preserve monetary value. The indicator then moves to the next lower indicator value and tests its profitability.
When it has tested all the values, it selects the one with the highest monetary amount and selects it as the best value to buy. Next, it performs a similar check on the sales value. Once it's done, it compares the best buy value to the best sell value and looks for the best deal. For example, after running this optimization, it determines that the best buy price is 65, because buying at 65 generates the most profit on buys, let's say it is $329 in the backtest, it will check its best sell value, and if the best sell price is 32 and the profit is $530, the robot will look for sell trades where the indicator crosses the 32 level, because selling is better than buying based on the profits generated in the backtest.
Please leave your suggestions and comments and don't forget to rate!
Now available on MetaTrader market: https://www.mql5.com/en/market/product/26332
Updated missing brackets in lines 137-142 to resolve error noted in comments.
Attachment download
📎 selfoptimizingrsiormfitrader_v3.mq4 (21.19 KB)
Source: MQL5 #19392
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •