Class 'C2' expert advisors

Class 'C2' expert advisors

4 April 2024, 11:08
Andrey Minaev
0
87

Description of work

The 'C2' class expert advisor works using martingale. When a signal from the built-in indicator appears, the expert advisor checks whether there is an open position that the expert advisor opened earlier. If there is an open position, the expert advisor accompanies it until it is closed; if there is no open position, the expert advisor analyzes how the previous position was closed with profit or loss. If with a profit, then opens a position with the initial volume, if with a loss, then increases the volume. After opening a position, the expert advisor sets a stoploss and takeprofit, and accompanies it until it is closed.

 

Note: before running the advisor, the settings need to be optimized for a specific instrument and timeframe.

 

Expert advisor settings

General settings

Timeframe

The parameter sets the timeframe on which the expert advisor will work. The parameter is needed if you switch the timeframe while the expert advisor is working, and the expert advisor will work with the timeframe that is set in the settings.

Example: the expert advisor is working on H1, you switch the timeframe to D1 to see the global situation, but the expert advisor continues to work on H1. Although, to evaluate the chart, you can use another chart on which the expert advisor does not work.

Note: if you select the current parameter from the list, the expert advisor will work on the timeframe that is currently active. The parameter is useful when testing on different timeframes, so as not to switch the parameter each time when changing the timeframe for testing.

 

Magic

The parameter sets a unique identifier for each open position. This parameter is needed if in the future you want to look at the history of transactions with a specific magician in order to assess the profitability of the trading strategy. A magic is assigned to an open position and is stored in the trading history.

Example: you have the same expert advisor working, but with different settings, for example, one expert advisor works with breakeven turned on, and another with breakeven turned off, since the expert advisor is the same, the Magic parameter will help distinguish positions opened by the expert advisor with breakeven turned on from positions with breakeven turned off.

Note: for positions opened manually, the terminal automatically sets the magic = 0, so it is better not to use 0 as a magic.

 

Money management settings

Position volume

The parameter sets the position volume with which the expert advisor opens a position. This volume is set for positions after profitable positions.

Example: the expert advisor was trading with losses and the position volume increased to 0.08, the Position volume = 0.01 parameter was set in the settings, after closing the position with a profit, the expert advisor will set the volume for the new position to 0.01.

Note: set the correct volume for the instrument on which the expert advisor will work. It must be greater than or equal to the minimum volume, less than or equal to the maximum volume, and be a multiple of the volume step. To do this, you can look at the specification of the tool, read the instructions.

 

Multiplier after loss

This parameter sets the volume multiplier after a loss. After losses, the expert advisor will increase the volume until a profit is made.

Calculation formula:

Position volume × MathPow(Multiplier after loss, TotalLoss), where

Position volume – position volume (parameter in settings),

Multiplier after loss – volume multiplier (parameter in settings),

TotalLoss – the variable stores the number of losses in a row,

MathPow(val1, val2) – the function returns a value that is multiplied by the initial volume.

Example: the expert advisor is trading with losses and received 3 losses in a row, with each new open position the volume will increase. With parameters (Position volume = 0.01, Multiplier after loss = 1.2) the volume will increase like this:

0.01 × MathPow(1.2, 1) = 0.01 × 1.2 = 0.012, rounded to the correct volume of 0.01;

0.01 × MathPow(1.2, 2) = 0.01 × 1.44 = 0.0144, rounded to the correct volume of 0.01;

0.01 × MathPow(1.2, 3) = 0.01 × 1.7279 = 0.017279, rounded to the correct volume of 0.02.

If losses continue, then this algorithm for increasing volume will continue. When making a profit, the volume will be reset to the initial value – 0.01.

Note: the expert advisor will not be able to open positions if the volume increases significantly and there are not enough funds; it will also not be able to open positions if the increased volume becomes greater than the maximum allowable volume for the instrument. If you set Multiplier after loss = 1.1, then the volume after losses will increase more slowly than if you set Multiplier after loss = 2.0 or more.

 

Position opening settings

This group contains settings for the indicator that supplies signals. The settings can be viewed for the specific indicator the expert advisor works with.

 

Position closing settings

StopLoss

The parameter sets the distance from the opening price to the loss limit price.

Calculation formula:

For a Buy position: opening price – (StopLoss x pip size)

For a Sell position: opening price + (StopLoss x pip size)

Example: StopLoss = 100, position opening price = 1.08000, stop loss for the Buy position will be set at 1.07900 (1.08000 – (100 x 0.00001)), for the Sell position - 1.08100 (1.08000 + (100 x 0.00001)).

Note: the parameter is required and must always be greater than 0.

 

TakeProfit

This parameter sets the distance from the opening price to the profit taking price.

Calculation formula:

For a Buy position: opening price + (TakeProfit x pip size)

For a Sell position: opening price – (TakeProfit x pip size)

Example: TakeProfit = 100, position opening price = 1.08000, take profit for the Buy position will be set at 1.08100 (1.08000 + (100 x 0.00001)), for the Sell position - 1.07900 (1.08000 – (100 x 0.00001)).

Note: the parameter is required and must always be greater than 0.

 

The point size can be viewed in the instrument specification or on the chart itself, for example, for the EURUSD pair the point size is 0.00001 (5th quotes), for the USDJPY pair it is 0.001 (3rd quotes).

 

Class 'C2' expert advisors:

MA7 Flax C2 MT4;

MA7 Flax C2 MT5.


Subscribe to the 'MA7 Trading' channel to receive notifications about new programs, updates and other information.

Ask questions in the profile on the MQL5.

Share it with friends: