
Idea from : Vladimir Pastushak .
MQL5 code by : Vladimir Karputov .
The EA trades on the Moving Average indicator and all preparation and trading functions have been located as a moving trading class in a separate file named moving.mqh .
The EA uses the principle of volatility, with the possibility of increasing the lot size; its operation uses a simple strategy:
initialization
Primary initialization - Set the following parameters: get flag | It returns the status of the initialization flag. When called from the base EA, it is used as a helper function for checking the internal state of variables of the m_init CMoving class. | Lot size or risk | Define the type of position lot calculation: manual ( lot parameter is greater than zero) or free margin percentage per trade ( risk parameter is greater than zero). |
Create MA | Create a moving average indicator. |
Take profit | Define take profit parameters. |
multiplier | Define batch addition parameters. |
Distance MA | Defines the indentation of the Moving Average indicator. |
profit plus | Extra indentation to define general profit. |
| Main functions |
|
processing | Main function, where all calculations are performed. |
| Class function with protected access specifier |
|
refresh rate | Update symbol quotes. |
Check volume value | Check that the entered position size is correct (this check is used when defining the position size manually). |
Whether padding type is allowed | Check the order filling pattern. |
iMAGet | Gets the value index of the Moving Average indicator on the bar with index . |
Calculate all positions | Get position information for each call: price | Considering the preset, obtain the distance of the reference price from the moving average for buy and sell positions. |
Batch inspection | Check and normalize the position size (used when defining the position size manually). |
Open for purchase | Open a buy position. |
On sale | Open a sell position. |
Print results | Print the results of opening trade operations. |
Set take profit | Set TakeProfit levels for the position or delete all TakeProfit and StopLoss levels (where DeleteTakeProfit parameter is equal to "true"). |
compare doubles | Compares two real numbers for equality. |
average take profit | Calculate and set a single take profit level position type for a specific type of position. |
GBPUSD, H1, "Every price change is based on a true price change."

Attachment download
📎 vr---moving.mq5 (9.17 KB)
📎 moving.mqh (69.58 KB)
Source: MQL5 #20610