System Trading 게시글

Self-Optimizing RSI and MFI Trading System for MetaTrader 4

첨부파일
19392.zip (4.86 KB, 다운로드 0회)

As traders, we all dream of having a trading robot that optimizes itself, ensuring it's always using the best parameters. Well, I'm excited to share my own humble attempt at making that dream a reality! The Expert Advisor (EA) I've developed optimizes the overbought and oversold levels it utilizes for trades. I hope others can take this concept and run with it to create something even more impressive. If you do, please let me know! And don't forget to rate my EA using the stars above. This strategy can be applied to any currency pair and time frame, provided you have the right settings.

There are a variety of inputs available for this EA. I've included some extra features for you to experiment with, so have fun!

Key Inputs

  • magic = 4376 - Unique identifier for this EA.
  • optimizingPeriods = 144 - The number of bars for optimization. For instance, if you’re using an hourly chart and choose 144, the EA will look back over the last 144 hours, which equals six days.
  • inAggressive = false - Activate aggressive trading mode? This is riskier. In aggressive mode, the EA will enter trades based on recent profitability rather than waiting for crosses of overbought or oversold levels.
  • inTradeReverse = false - Enable reverse trading. This will flip the direction of your trades.
  • inOneOrderAtATime = true - Limit to one order at a time? If true, the EA will only hold one open order at a time; if false, it can open multiple orders based on entry conditions.
  • Lot_sizing_dynamic_invalidates_static - A separator for Lot sizing mechanics.
  • Lots = 0.01 - Static lot size. Specify your order size here.
  • inUseDynamicLotSize = true - Enable dynamic lot sizing. This will override static lot sizing unless it’s found to be invalid, in which case the static size applies.
  • inPercentageOfRisk = 2 - Percentage of your balance to risk on each trade (e.g., 2 = 2%). When using dynamic sizing, this sets your lot size as a percentage of your balance, with a maximum of 10%.
  • Index_Indicator_Values - A spacer for index indicator parameters.
  • indicator index = _RSI_ - Select the index indicator to use: either the Relative Strength Index (RSI) or the Money Flow Index (MFI).
  • IndicatorTopValue = 100 - The highest value for trading based on your indicator. Keep it at 100 to consider all potential values.
  • IndicatorBottomValue = 0 - The lowest value for trading. Keep it at 0 to consider all potential values.
  • IndyTimeframe = PERIOD_CURRENT - Timeframe for the index. This will use the timeframe of the chart the EA is attached to, but you can select a different timeframe if desired.
  • inIndyPeriods = 14 - Averaging period for index and ATR calculations. The Average True Range (ATR) helps set dynamic stop-loss or take-profit levels.
  • IndyAppPrice = PRICE_CLOSE - The price applied for the index, if necessary.
  • SL_TP_Dynamic_invalidates_static_values - A separator for stop loss and take profit parameters.
  • iStoploss = 1000 - Static stop loss value in points (the smallest unit of movement in your terminal).
  • iTakeprofit = 2000 - Static take profit value in points.
  • input inDynamic = true - Enable dynamic stop loss and take profit based on ATR multiples? This setting allows stop loss and take profit levels to adjust according to market conditions.
  • inStoplossMultiple = 2 - Dynamic SL = X * ATR (Averaging Period). This sets the stop loss at a multiple of the ATR.
  • inTakeProfitMultiple = 7 - Dynamic TP = X * ATR (Averaging Period). This sets the take profit at a multiple of the ATR.
  • Break_Even_Settings - A section for break-even settings. When in profit, the stop loss can be moved to break even plus padding to lock in profits.
  • bUseBreakEven = true - Enable break-even functionality.
  • inTrigger = 200 - Points in profit to trigger break-even. If the trade reaches this level, the stop loss will be moved to break even.
  • inPadding = 100 - Points to lock in as padding when moving to break even. This must be lower than the trigger.

So, how does this EA self-optimize? The key is that it tests each variable in the index indicator twice. For example, if an indicator has one hundred possible values, it evaluates each one to determine how profitable it would have been during the specified optimization period (optimizingPeriods). This process is a bit complex, but let me break it down:

The EA issues a sell order when the indicator crosses the overbought level downwards and a buy order when it crosses the oversold level upwards. For instance, if the overbought level is set at 80 and the indicator value changes from 85 to 79, a sell order is triggered.

The EA evaluates every potential indicator value between IndicatorTopValue and IndicatorBottomValue, conducting a buy and sell test for each. If the value indicates a profitable trade based on historical data from optimizingPeriods, it retains that profit amount. Once all values are tested, the EA selects the one with the highest profitability as the optimal value for trading.

After determining the best buy and sell values, it seeks the best trading opportunity based on historical performance. For example, if the best buy was at 65 (with a profit of $329) and the best sell was at 32 (with a profit of $530), the EA would prioritize the sell trade when the indicator crosses the 32 level.

Future Expansion Ideas

  • Trade multiple currency pairs simultaneously, possibly filtered by spread size.
  • Implement self-learning capabilities, allowing the EA to learn from its trades.
  • Include forward testing components in backtesting.
  • Offer more indicators to choose from.

Your feedback and suggestions are always welcome! And don't forget to rate!

Check it out now on the MetaTrader marketplace: https://www.mql5.com/en/market/product/26332

Updated with the missing brackets in lines 137-142 to resolve errors identified in comments.

연관 포스트

댓글 (0)