Self-Optimizing RSI/MFI Trader
Info
The Self-Optimizing RSI/MFI Trader is a Expert Advisor for MetaTrader 4 that it is my dream to create a robot that optimizes itself, ensuring it always operates with the best settings. This expert advisor optimizes the overbought and oversold levels for trading.
Usage
This tool is typically used for automated trading on major forex pairs and gold.
Platform
This Expert Advisor works exclusively on MetaTrader 4 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL4/Experts folder via File ? Open Data Folder in MetaTrader 4.
How to Install and Use Self-Optimizing RSI/MFI Trader
1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.
2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.
3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.
4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.
Frequently Asked Questions
Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.
Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.
Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.
What this tool does
It is my dream to create a robot that optimizes itself, ensuring it always operates with the best settings.
Typical Use Case
This Expert Advisor excels in automated trading and technical analysis on MetaTrader 4.
Compatible Platform & Setup
This Expert Advisor works on MetaTrader 4. Place the file in the MQL4/Experts folder and restart the terminal.
Description & Settings
Related: last kiss breakout - another powerful expert for MetaTrader 4 traders.
It is my dream to create a robot that optimizes itself, ensuring it always operates with the best settings. This expert advisor optimizes the overbought and oversold levels for trading. I encourage others to build upon this concept and create something even more remarkable. Please share your ideas and provide feedback.Also recommended: MA Cross Sample EA - Updated for Modern Trading - similar expert with strong performance on MetaTrader 4.
This strategy is applicable to any currency pair and time frame with the appropriate settings.
Inputs
magic = 4376
- Unique identifier for the EA.
optomizingperiods = 144
- Optimization periods (bars). This is the number of bars used for optimization. For instance, on an hourly chart with 144 periods, the robot looks back 144 hours, equivalent to six days.
inaggressive = false
- Enable aggressive mode? Aggressive mode increases risk by taking trades based on recent profitability rather than waiting for a cross of the overbought or oversold level.
intradereverse = false
- Reverse trading direction.
inoneorderatatime = true
- Limit to one order at a time. If true, the robot manages only one order; if false, it opens unlimited orders based on entry conditions.
lot_sizing_dynamic_invalidates_static
- Separator for lot sizing inputs.
lots = 0.01
- Static lot size for orders.
inusedynamiclotsize = true
- Enable dynamic lot sizing. If dynamic lot sizing is invalid, the robot defaults to the static lot size.
inpercentageofrisk = 2
- Balance percentage to risk per trade (2 = 2%). Dynamic lot sizing allows specifying the lot size as a percentage of the balance.
index_indicator_values
- Separator for index indicator parameters.
indicator index = _rsi_
- Select the index indicator: Relative Strength Index (RSI) or Money Flow Index (MFI).
indicatortopvalue = 100
- Topmost value for trading. Leave at 100 to consider all index indicator values.
indicatorbottomvalue = 0
- Bottommost value for trading. Leave at 0 to consider all index indicator values.
indytimeframe = period_current
- Timeframe for the index. Choose the timeframe for indicator calculations, which can differ from the chart's timeframe.
inindyperiods = 14
- Averaging period for index and ATR calculations. Average True Range (ATR) is used for dynamic stop-loss and take-profit settings.
indyappprice = price_close
- Applied price for the index if needed.
sl_tp_dynamic_invalidates_static_values
- Separator for stop-loss and take-profit parameters.
istoploss = 1000
- Static stop-loss value in points.
itakeprofit = 2000
- Static take-profit value in points.
input indynamic = true
- Enable dynamic stop-loss and take-profit based on ATR multiple. Dynamic settings adjust according to market conditions, using larger values when the market is more volatile.
instoplossmultiple = 2
- Dynamic stop-loss = x * ATR (averaging period). The stop-loss is calculated by multiplying the ATR (using the specified periods) by the value provided.
intakeprofitmultiple = 7
- Dynamic take-profit = x * ATR (averaging period). The take-profit is calculated similarly to the stop-loss.
break_even_settings
- Padding must be lower than the trigger. Separator for break-even settings.
busebreakeven = true
- Enable break-even (BE) feature.
intrigger = 200
- Points in profit to trigger break-even.
inpadding = 100
- Padding points to add to break-even, must be lower than the trigger. This locks in a certain amount of profit when moving to break-even.
How does this robot self-optimize? It tests each indicator value twice. For an indicator with 100 possible values, it tests each value for potential trades over a certain number of bars (optomizingperiods). It evaluates the profitability of each trade and assigns a monetary value. The process is more intricate, but here's a simplified explanation:
The robot follows these rules: when an indicator crosses the overbought value from the top, it issues a sell order, and when it crosses from below an oversold value to above, it issues a buy order. For instance, if overbought is set to 80 and the indicator value changes from 85 to 79, a sell order is issued (85 → 79 crosses 80 downwards).
The robot tests every indicator value between indicatortopvalue and indicatorbottomvalue. For example, if the top value is 100, it backtests buying and selling at 100 over the specified optomizingperiods. If the trade is profitable, it records the profit. It considers multiple trades within the backtesting period and calculates the total profit or loss. After testing all periods, it selects the indicator value with the highest profit for buys and sells separately. Finally, it compares the best buy and sell values to determine the most profitable trade.
Future Expansion Ideas:
- Trade multiple currency pairs simultaneously, filtered by spread size.
- Implement self-learning capabilities to improve performance based on past trades.
- Incorporate forward testing in addition to backtesting.
- Add more indicators for enhanced analysis.
Please provide your valuable feedback and suggestions.
You may also like: SmartAssTrade Expert Advisor - excellent alternative for expert users on MetaTrader 4.
Source Code
#property copyright "robotfx"
#property link "https://robotfx.org"
#property version "1.02"
#property description "this code is educational. feel free to use, modify and upgrade as you wish. visit robotfx.org for professional trading tools"
#property description "this code is educational. feel free to use, modify and upgrade as you wish. visit robotfx.org for professional trading tools"
#property description "this code is educational. feel free to use, modify and upgrade as you wish. visit robotfx.org for professional trading tools"
#property strict
#define max_percent 10 // maximum balance % used in money management
enum indicator
{
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.