Русский 中文 Español Deutsch 日本語 Português
preview
Automated exchange grid trading using stop pending orders on Moscow Exchange (MOEX)

Automated exchange grid trading using stop pending orders on Moscow Exchange (MOEX)

MetaTrader 5Trading | 19 June 2023, 09:04
2 665 1
Roman Shiredchenko
Roman Shiredchenko

Introduction

The previous article delved into a trading approach based on limit pending orders for trading on the Moscow Exchange. In this article, we will focus on using a grid trading approach on stop pending orders using stop loss and/or take profit. 

The grid trading method is not described in classic books on trading, perhaps due to its relatively recent appearance.  

When trading in the market, one of the simplest strategies is a grid of orders designed to "catch" the market price. Trading systems applying this method usually do not pursue the goal of finding exact entry and exit points - the task is to deploy a grid of positions with deals opening automatically.


1. Grid with stop pending orders (Buy Stop, Sell Stop)

This method is very common in the arsenal of novice traders as it does not require special knowledge regarding the foreign exchange market, and even such common things as technical or fundamental analysis. However, a successful grid strategy requires a rough knowledge of the main trend in the selected time period - up, down, or sideways price movement with a periodic return to the average value.

The general principles of constructing a grid in the market are quite simple:

  • Orders are lined up one after another at an equal distance in points
  • A trade direction is predetermined
  • The grid is set to a specific range

The grid is characterized by the following parameters:

  • grid width
  • grid step
  • take profit
  • stop loss

The grid width is the area covered by the placed orders. Grid step is the distance between orders. Grid width and step are calculated in points. Thus, we have reached the definition of the grid method of trading. A trading method, in which the entry into the market is carried out using many orders usually located at the same distance from each other and on both sides of the current price is called a grid. 

Whatever direction the market price goes, it will still pass through the grid of positions. Profitable trades can accumulate up to a certain amount, but they can also be closed as soon as the price turns the next order placed on the grid into a market position. Placing next orders in the grid (for example, when the price moves up and triggers buy stop orders, as well as accumulates market position volumes with subsequent placing sell market orders closer to the price (updating the grid)) with subsequent small price downward rollbacks triggering sell stop orders performs the role of the so-called partial closing of the position, which is shown in Fig. 1.

placing and executing orders

Fig. 1. Placing an order grid and triggering the orders


At the same time, the balance and equity graphs in the strategy tester looks like this (Fig. 2)

balance graph

Fig. 2. Strategy tester graph

How could the idea of such an approach to trading come into existence? Presumably, the trader's thought worked in the following direction: first, the trader comprehends the process of opening one trade for a symbol and closing it either by take profit (TP) or stop loss (SL). Over time, the trader learns that it is possible to enter the market in a more sophisticated manner, namely, stepwise.

Entering the market in stages, the trader divides the entire volume of the position into several parts and determines the price levels to open trades at. These levels can be both above and below the current price, and then these entries will be called either "adding positions on a rollback" or "adding positions along a trend". Most traders like to close positions by TP, but it often happens that the price does not reach a predetermined level, at which traders have set their TP, and reverses. Traders lose part (if not all) of their accumulated profits. This fact was pretty disturbing for traders, and therefore, perhaps, some traders had the idea of a "step-by-step exit from the market" similarly to the entry.    

This gave way to trading tactics, in which a trader closes part of open positions at predetermined levels. Finally, by combining the step-by-step entry with the step-by-step exit and turning it into a kind of "symmetrical system" that is independent of technical analysis (or only partially dependent on it), the trader’s thought came to the concept of grid trading. I said "symmetrical" because now the entry levels are set at the same distance from each other. The same usually goes for the exit levels.

The grid is characterized by the following parameters: grid width, grid step, TP, SL.

The grid width is the area covered by the placed orders. Grid step is the distance between orders. Grid width and step are calculated in points.

Thus, we have reached the definition of the grid trading method.  A trading method, in which the entry into the market is carried out using many orders usually located at the same distance from each other (grid step) and usually on both sides of the current price is called a grid.

The significant advantage of this approach to trading is that it is now unnecessary to carry out hard (and often thankless) work of market forecasting. In fact, the grid method of trading has joined the theory of the efficient market or the theory of random walk of prices. 

You may ask, why the grid type of trading can be profitable, or how we can be confident that there can be a profit (using this trading approach often involves no technical analysis).

To understand what this confidence is based on, let's look at Fig. 3 depicting the grid of stop orders and the movement of the futures contract price of PJSC Sberbank ordinary shares price.

The grid of orders in the strategy based on stop orders involves opening pending trades in the direction of a trend. If, however, stop orders are placed on both sides of the current price, then no matter which direction the trend goes, a trader will make a profit (Fig. 3 and 4 present testing an EA with a set take profit value):


Triggering and replacing orders according to the trend

Fig. 3  The principle of grid trading profitability with a take profit less than the grid step width

When closing by take profit less than the grid step, the balance and equity graphs look as follows

graph

Fig. 4. Balance and equity graphs when closing by take profit

      

The type of this grid is based on the fact that the trader has no preference in the further direction of price movement due to the fact that he or she does not do any analysis at all or believes that further price changes, both upward and downward, are equally likely.

The grid is built from the selected level, which is close to the current price, according to the following principle:

- Buy Stop orders are placed above the selected level;

- Sell Stop orders are placed below the selected level;

The grid step is determined by the trader, but usually ranges from a few pips (above the spread) to the average daily true value of the traded symbol. This value can be determined by the Average True Range (ATR) indicator, which shows how much the price of a symbol has changed over a certain period of time (a measure of volatility). The choice of the step size determines the intensity of grid trading. Naturally, the smaller the grid step, the more aggressive it is and has an increased possible profitability. Therefore, when setting up and maintaining the grid, scripts and Expert Advisors are often used.

A stop loss in this type of grid trading approach is often not set on stop orders (visually controlled by the chart), and a take profit is also determined by the user's preferences (it is also possible to use a value smaller than the grid step).

Images 5 and 5.1 show a test with preset parameters:

    - grid width 3,500 points;
    - grid step 184 points;
    - take profit 100 points (less than the grid step).

    parameter value

    Fig. 5. Values of external variables 

    TP 100 points step 184

    Fig. 5.1. Test with take profit of 100 points, step 184 points  

    In the presented grid trading approach, it is possible to adjust the grid parameters, its frequency (with a different number of orders in the external parameters of the EA) and set the upper and lower boundaries. Next, the system automatically places orders at an equal distance from each other based on the specified criteria, above and below the specific price of the traded symbol.

    Using this grid trading strategy on stop orders involves the following steps:

    • setting the starting grid structure. It implies defining price levels in external variables, setting and placing stop orders with a rate above and below the market rate, according to the number of stop orders specified by the user.
    • opening positions. The grid is activated by a market position when the market price triggers the nearest stop order after the start (above the buy stop price, below the sell stop price).
    • updating the grid. The structure is updated every time after reaching one of the set price levels within the price range specified by the user. In other words, after the next stop order is triggered, the stop order is re-placed depending on the direction of orders triggering (price movement). When the price moves down, sell stop orders are triggered, and within the price range specified by the user, additional buy stop orders are placed closer to price.

    For example, the following trading principle is presented in the strategy tester - two orders on the far right (buy stop) turn into market positions after being triggered and close by take profit when the symbol price moves up. New sell stop grid orders are placed closer to the price of the tested symbol (Fig. 6):

    stop grid trading principle

    Fig. 6. The principle of triggering and placing new orders according to trading criteria  


    2. Using a trading strategy based on stop pending orders

    Let's consider the principle of working with this type of grid. After closing deals by take profit, new orders are placed instead according to the rule:

    • if the current price position is higher than the level of the closed deal, then a pending Sell Stop order is placed;
    • if the current price position is lower than the level of the closed deal, then a pending Buy Stop order is placed;

    As the grid functions, when the price of the symbol moves, the position is exited by take profit if the take profit is set less than the width of the grid step. This happens both with buy and sell positions. If the take profit is not set or exceeds the grid step, then with the unidirectional movement of the traded symbol, a market position is set when pending orders are triggered. The so-called unloading of the market position occurs during rollbacks from the previous main movement by an amount equal to or greater than the grid step causing opposite pending orders to trigger and increasing the account balance.   

    Thus, no matter in which direction the price moves, profit is obtained due to the prevalence of trading positions in the direction of the trend.

    The advantage of BuyStop and Sell Stop order grids are:

    1. The ability to trade with minimal skills.
    2. Trading is always carried out in the direction of the main trend.

    The disadvantage of Buy Stop and Sell Stop order grids is:

    1. In case of a wide flat channel, quotes can immediately activate 5-6 or more stop orders in both directions, and it will take a lot of time and resource of the trading account to get out of the drawdown.

    There is no need for careful market forecasting. But in order to increase profits, it is important to consider many factors. As a rule, a good choice for this type of trading is a symbol (the traded rate of which is characterized by frequent and significant, preferably unidirectional rises or falls with no drawdowns).

    Why automated grid trading is so popular:

    It is convenient. You can figure it out quickly and there are no too complicated calculations that require a lot of experience.
    This is effective in terms of risk management.
    It is safe. The trading approach has been proven over the years and many traders practice it in a wide variety of markets.
    Flexible tactic. It easily adapts to different market conditions.
    Finally, grid trading is perfect for automation. It is extremely logical, has a clear structure and does not depend on the market behavior.

    This is a grid trading method in which the trader must take the liberty of deciding that some trend will prevail in the traded area. The stronger the trend, the more profit the trader will receive. Stop orders are used here, which are opened in the direction of the trend, i.e. Buy Stop is opened for buying, and Sell Stop for selling. Stop orders are also used in a situation where the price has been in a range for a long time, upon exiting which, in any direction, the so-called additional loading (with stop orders co-directed to the movement) and unloading (with price rollbacks and triggering of pending orders of the opposite direction) will also occur.

    For this type of grid trading, strong reverse fluctuations are unprofitable: extreme Buy Stop and Sell Stop orders may require a significant amount of funds on the account when the price returns to its original value. 

    3. Setting the EA parameter values and selecting trading symbols on the Moscow Exchange

    In the code, part of the external variables looks like this:

    //+------------------------------------------------------------------+
    //|                          EXTERNAL GRID VARIABLES
    //+------------------------------------------------------------------+
    input int Volume = 1;                          //Contract/lot volume
    input double HIGH_PRICE_BuyStop = 5500.00;     //HIGH_PRICE_BuyStop (the upper price of the last BuyStop grid order)
    input double LOW_PRICE_SellStop = 4000.00;     //LOW_PRICE_SellStop (the lower price of the last SellStop grid order) 
    input double HIGH_PRICE_TP  = 100.00;          // HIGH_PRICE_TP: TP in points from HIGH_PRICE_BuyStop 
    input double LOW_PRICE_TP = 100.00;            // LOW_PRICE_TP:  TP in points from LOW_PRICE_SellStop
    input double TakeProfit  = 0;                  // TakeProfit from the setting price in order points
    input double StopLoss  = 0;                    // StopLoss from the setting price in order points
    
    

    The figure below shows an example from the Settings tab for testing trading by an Expert Advisor in Fig. 7:

    test settings

    Fig. 7. Example of setting parameter values for testing 


    Ways to improve your trading strategy

    In addition to a partial exit from the total market position by using opposite pending orders (on price rollbacks from the main movement, which is embedded in the logic of the trading system based on a grid of pending orders) or by stop losses, you can also look at the implementation of the exit through the trailing option.

    For example, the Moscow Exchange offers the following options for a futures contract for ordinary shares of PJSC Sberbank (these are the assets the preliminary testing of the grid trading approach was performed on). See Fig. 8 and the link:

    https://www.moex.com/en/contract.aspx?code=SBRF-6.23


    PJSC Sberbank specification

    Fig. 8. Parameters of a futures contract for ordinary shares of PJSC Sberbank for placing new orders according to trading criteria


    Also, when trading with the grid method, one should not forget about the calculation of the necessary and sufficient margin for the total number of orders and positions in the total volume of contracts.

    Figures 9 and 9.1 demonstrate quite good unidirectional movements of futures contract for ordinary shares of PJSC VTB Bank with a relatively small value of margin.

    chart

    Fig. 9. Futures contract for ordinary shares of PJSC VTB Bank

    parameters

    symbol parameters

    Fig. 9.1. Parameters of futures contract for ordinary shares of PJSC VTB Bank



    Conclusion

    In this article, we got acquainted with grid trading and types of trading orders - Buy Stop and Sell Stop. The material presented in the article implies and carries information for the user solely for educational purposes and a general understanding of the functioning and capabilities of the grid method of trading based on stop orders using the EA (attached below). I am also attaching a report on using the strategy on a futures contract for ordinary shares of PJSC Sberbank. Grid trading has capital risks, just like any other margin trading strategy.

    Disclaimer: The article is not a trading recommendation. The ideas outlined in the article should only be considered as a possible trading opportunity.

    Translated from Russian by MetaQuotes Ltd.
    Original article: https://www.mql5.com/ru/articles/10671

    Last comments | Go to discussion (1)
    stuartfbs
    stuartfbs | 2 Oct 2023 at 07:32
    Добрый день. Очень интересная и информативная статья. Спасибо! Good day, a very interesting and informative article.Thank you.
    Improve Your Trading Charts With Interactive GUI's in MQL5 (Part I): Movable GUI (I) Improve Your Trading Charts With Interactive GUI's in MQL5 (Part I): Movable GUI (I)
    Unleash the power of dynamic data representation in your trading strategies or utilities with our comprehensive guide on creating movable GUI in MQL5. Dive into the core concept of chart events and learn how to design and implement simple and multiple movable GUI on the same chart. This article also explores the process of adding elements to your GUI, enhancing their functionality and aesthetic appeal.
    Creating an EA that works automatically (Part 13): Automation (V) Creating an EA that works automatically (Part 13): Automation (V)
    Do you know what a flowchart is? Can you use it? Do you think flowcharts are for beginners? I suggest that we proceed to this new article and learn how to work with flowcharts.
    Multilayer perceptron and backpropagation algorithm (Part 3): Integration with the Strategy Tester - Overview (I). Multilayer perceptron and backpropagation algorithm (Part 3): Integration with the Strategy Tester - Overview (I).
    The multilayer perceptron is an evolution of the simple perceptron which can solve non-linear separable problems. Together with the backpropagation algorithm, this neural network can be effectively trained. In Part 3 of the Multilayer Perceptron and Backpropagation series, we'll see how to integrate this technique into the Strategy Tester. This integration will allow the use of complex data analysis aimed at making better decisions to optimize your trading strategies. In this article, we will discuss the advantages and problems of this technique.
    Rebuy algorithm: Math model for increasing efficiency Rebuy algorithm: Math model for increasing efficiency
    In this article, we will use the rebuy algorithm for a deeper understanding of the efficiency of trading systems and start working on the general principles of improving trading efficiency using mathematics and logic, as well as apply the most non-standard methods of increasing efficiency in terms of using absolutely any trading system.