Harnessing AI for Trading: Expert Advisor for MetaTrader 5

Mike 2012.11.30 20:13 23 0 0
Attachments

The Expert Advisor (EA) we're discussing today has been expertly rewritten from MQL4 by Reshetov. You can find the original source here.

How It Works

This EA utilizes the Accelerator Oscillator indicator, pulling four bar values: Shift, Shift+7, Shift+14, and Shift+21. Each of these values is multiplied by a weight derived from the formula (100-x(n)), where x(n) represents optimized variables x1, x2, x3, and x4. After this calculation, we sum up the multiplied values to get the perceptron’s exit value. If this value exceeds 0, a buy position is triggered; if it falls below 0, a sell position is initiated.

Positions are opened with a Stop Loss (which is mandatory) and no Take Profit set. When a position achieves a profit that exceeds the Stop Loss value adjusted for spread, and an opposite signal arises, the position is reversed with a larger volume. If no opposite signal occurs, the Stop Loss is adjusted to match the level at which the position was opened, ensuring the trade remains profitable based on the spread value.

In the event that a position cannot be reversed due to the proximity of the Stop Loss, the EA will close the position and attempt to open a new one on the next tick.

Having a Stop Loss is crucial, as it allows for a position to be closed and its Stop Loss adjusted only when the trade is in profit. This provides a safety net in case the trade goes south.

You can check out the results of this Expert Advisor using default settings on the EURUSD M15 timeframe over the last year displayed in the chart below.

Parameters

  • Lots: Lot size.
  • StopLoss: Stop Loss in points.
  • Shift: Bar on which indicators are checked: 0 for the current bar, 1 for the first completed bar.
  • x1, x2, x3, x4: Input weights for the perceptron ranging from 0 to 200. It’s advisable to use a Generic Algorithm for optimization.
List
Comments 0