Lock - MetaTrader 5 Expert | Grid EA Download - MT4/MT5 Resources - MetaTrader 5 Resources


MQL5 code by : Vladimir Karputov .
Suppose a trader enters the market with buy and sell positions on a certain asset, where the currency is at the 100 level. Then the price moves to 200. Here, buying at 100 will result in profit and selling at 100 will result in loss. We close the position and a profit of 100 goes into our account. In this case, selling would result in a loss of 100 units.
When using a grid, you should ensure that you are profitable regardless of the direction of the market. To do this, enter your buy and sell transactions again. Now, for convenience, let's assume that the price moves to the 100 level again.
A repeated sale will result in +100, while a second buy will result in -100. According to the rules, you can close your position and another 100 units will enter your account. As a result, our total profit at this time is 200.
Now, the first still active sell position is moving from the 200 level to the 100 level. Now in breakeven range.
Summarizing the four transactions, the profits we get are as follows: +100 for the first purchase; +100 for the second sale; 0 for the first sale and -100 for the second purchase. The total profit has reached +100. So we can delete all orders and have a glass of champagne. Before each subsequent double opening (simultaneous opening of a buy and sell position), we increase the lot size by the following factor: lot index .
There are many other market moves that can make these seemingly incomprehensible simultaneous buying and selling activities profitable.
However, in this type of trading, there is always the risk of "hanging a position", that is, a position that incurs a relatively high loss and opens at a price far different from the current price. To overcome this "hanging" position, we introduce two parameters: balance over equity (balance over equity) and minimum profit .
In all cases, be careful because two scenarios are possible: Optimism

and pessimistic

Attachment download
📎 lock.mq5 (28.41 KB)
Source: MQL5 #20781
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •