Tâche terminée
![](https://c.mql5.com/i/avatar/avatar_na2.png)
![](https://c.mql5.com/i/avatar/avatar_na2.png)
Spécifications
Description
I initially need an EA only to backtest just to see if the strategy I thought of is profitable.
The parameters I need to set are:
1. Value X (distance in pip between the orders that will be entered)
2. Hours and days of trading consented for the EA
3. Volume of the initial lot V
In the following I will indicate with P the price of the first order executed, with SL the Stop Loss, with TP the Take Profit, with V the initial volume expressed in lots.
The robot will enter the first buy order at market price with volume V and suppose that P is the price of the executed one.
The order will be entered with TP of X and SL of 2X.
As soon as the first order is executed at price P two stop orders will be entered:
1. the first will be a buy stop order at the P + X price and volume V, with TP of X pips and SL of 2X pips.
2. the second will be a sell stop order with price P-X, volume 3V and also having TP of X and SL of 2X
If the price goes the right way, it will reach the TP level and the executed order will be closed in profit, while at the same time the order referred to, in point 1, above will have been executed
If the price moves in the wrong direction and reaches the value of P-X then the order described in point 2 above will be executed and at the same time two other stop orders will be entered, of which:
3. the first will be a sell stop order at the P-2X price and volume V, with TP of X pips and SL of 2X pips.
4. the second will be a buy stop order with price P, volume 6V and also with TP of X and SL of 2X
Whenever the price retraces X without reaching the TP of the last executed order but reaching the price of the pending order previously entered, the robot will enter a new stop order of opposite sign with increased volume according to the sequence V, 3V, 6V, 12V, 24V, 48V, etc.
Tthe robot will place orders according to a martingale that becomes a winner one when leaving the price range between P + X and P-2X.
When the martingale arrives to Take Profit a new martingale initial order equal to the price of the take profit will be started.
Example
of operation
Taking a graphic example, we have the following.
At point 1 of the graph, the robot will enter the first buy order in the market with volume V that is executed at the P price.
As soon as the order is executed in point 1, the two pending orders are entered
A. buy stop order at the P + X price and volume V, with TP of X pips and that is at the P + 2X level and SL of 2X pips and that is STOP loss at P-X price level.
B. sell stop order with P-X price, 3V volume and also with TP of X and SL of 2X
The price after an initial climb retraces up to the P-X price level (point 2 of the graph), where the pending order is executed at point B.
Also here, as soon as the order referred to in the previous point B is executed, two pending orders will be entered
C. the first will be a sell stop order at the price P-2X and volume V, with TP of X pips and SL of 2X pips.
D. the second will be a buy stop order with price P, volume 6V and also with TP of X and SL of 2X
at this point the price rises reaching point 3 of the graph at price P. Then order D is executed in the previous point and the following new pending order is entered:
E. sell stop order at P-X price with 6V volume, with TP of X pips and SL of 2X pips.
The price goes down again and reaches point 4 of the graph at the P-X price. The pending order E is then executed and a new pending order is entered which is as follows:
F. buy stop order at price P, with volume 12 V, with TP of X pips and SL of 2X pips.
The price starts to rise again and arrives at point 5 of the graph at price P. Then the pending order F is executed and a new pending order is entered which is as follows:
G. sell stop order at P-X price with 12V volume, with TP of X pips and SL of 2X pips.
The price continues to rise and reaches point 6 of the chart at the P + X price. At this price level all the buy stop orders executed are in take profit, all the sell stop orders executed are in stop loss, the pending order in point A is executed and everything is started all over again with an order with volume V equal to the initial lot. The robot will then insert the new orders A and B whose price levels, SL and TP will have been moved up by X pips. The robot will cancel the other pending orders of the previous series just closed and everything will start again as before but with price levels moved.