Download MetaTrader 5

Modelling Requotes in Tester and Expert Advisor Stability Analysis

22 May 2007, 09:54
Murashov Anton
0
1 044

Introduction

The Strategy Tester embedded in the Meta Trader 4 Client Terminal is a very good verification/quality evaluation tool for a trading strategy realized in the Expert Advisor. But at the current moment, it has two quite critical (to my mind) features. First, it does not use the real tick history for a symbol and models ticks on the basis of one-minute bars. Second, it does not consider the phenomenon that brokers requote rather often, especially on small trade volumes or on very large ones, and also on the "thin", low-liquid market. Under the conditions of possible requotes, no opportunity to check up the EA leads to appearance of "grails", trading on “spikes”, leaps and non-market quotes. It was explained and proved many times that such a strategy could not be effective on a real account but, unfortunately, quite often it is difficult to realize whether your Expert Advisor plays on “spikes” or not. On a history chart with trades imposed on it, it is sometimes possible to see that the Tester opens trades on leaps, but not every time. It is also difficult to predict whether it will whittle the requote strategy during these moments or just lower the profitability. In this article, I am going to state my own method to solve this problem.



Assumptions and Definitions

Requote is the broker’s response to the order you sent to the trade server. This broker’s response informs about that the price (at which you try to open a trade) is not actual any more. It often happens on low-liquid or volatile markets where the price can change strongly during your request processing by the terminal. Also requotes are very frequent when trying to open at blowouts and non-market quotes.

Let us consider that the Expert Advisor opens and closes only orders like OP_SELL and OP_BUY. It does not change an essence, but makes some functions easier.



Requotes’ Modeling in the Strategy Tester

Let us aim to simulate requotes with beforehand set probability at the opening and closing of orders. First of all let us enter a special external variable which will set the occurrence probability of our artificial requote. According to my investigation/monitoring, the probability of the requotation on low-liquid pairs blowouts comes nearer to 90 % - therefore let us take this value at the Expert Advisor analysis.

extern int RQF_TEST = 90;

As we will use the function MathRand returning an arbitrary value, it is better to initialize the sequence of pseudo-random numbers. For this purpose the function MathSrand will be carried out in the beginning of the Expert Advisor's work. For more detailed information concerning random value generation and the purpose of this function you can learn in the reference book on MQL language. It should be said that if we will not use MathSrand, despite of the numbers " randomness" from MathRand function, at any run of the strategy we will receive the same result. And, generally speaking, it does not suit us:

int start()
  {
    //----
    MathSrand(TimeCurrent());

After that we should write the own functions OrderSend and OrderClose. Let us name them MyOrderSend and MyOrderClose:

int MyOrderSend(int req_prob, string symbol, int cmd, double volume, double price, 
                int slippage, double stoploss, double takeprofit, 

                string comment="", int magic=0, datetime expiration=0, 
                color arrow_color=CLR_NONE)
  {
    if(IsTesting() && (MathRand() % 100) < req_prob && (cmd == OP_SELL || cmd == OP_BUY))
        return (-1); //modelling requote
    return(OrderSend(symbol, cmd, volume, price, slippage, stoploss, takeprofit, 
           comment, magic, expiration, arrow_color));
  }
 
bool MyOrderClose(int req_prob, int ticket, double lots, double price, int slippage,
                  color Color=CLR_NONE)
  {
    if(IsTesting() && (MathRand() % 100) < req_prob)
        return (false); //modelling requote
    return (OrderClose(ticket, lots, price, slippage, Color));
  }

Now we should replace all OrderSend and OrderClose functions in the EA by MyOrderSend and MyOrderClose with the indication of the entered before external variable RQF_TEST as the first argument. Below there is an example from my own EA.

OrderClose -> MyOrderClose:

if(MyOrderClose(RQF_TEST, ticket, amount, Bid, 0, Blue)) 
// PREV: if(OrderClose(ticket, amount, Bid, 0, Blue))
  {
    Print("Skalpel: Order #" + ticket + " closed! (BUY, " + Bid + ")");
            //... Something
  }
else
  {
    // Requote or something like this
    Print("Skalpel: Error while closing order #" + ticket + " (BUY)!");
    // ... Something
  }

OrderSend -> MyOrderSend:

ticket = MyOrderSend(RQF_TEST, Symbol(), OP_BUY, amount, Ask, 0, 
                     Bid-StopLoss*Point, Bid+TakeProfit*Point, 
                     NULL, EXPERT_MAGIC, 0, Blue);
// PREV: OrderSend(Symbol(), OP_BUY, amount, Ask, 0, Bid - StopLoss*Point, 
// Bid+TakeProfit*Point, NULL, EXPERT_MAGIC, 0, Blue);
 
if(ticket > 0)
    Print("Skalpel: Order #" + ticket + " opened! (BUY)");
else
    Print("Skalpel: Error while placing order."); 
    // ... Requote or something like this

Conclusions And the Analysis of Results

First of all the value of variable RQF_TEST should be explained. It sets the quantity of requotes for 100 trades and, accordingly, can take on a value from 0, when there is no requotes at all, up to 100, when it is absolutely impossible to open or to close the order. If RQF_TEST is equal 90, as in an example, it means that approximately 90 attempts to open or close the transaction of 100 will end in failure, i.e. the requote will be simulated.

Actually, the results, which were received at various values of RQF_TEST, show the stability of your strategy to requotes and to differences in tick flow from the tester and the broker.


If results deteriorate when RQF_TEST growing, it is necessary to check expediency of such a strategy, since the sensitiveness to requotes means that you play on sharp, temporary blowouts or you pip. It was said a lot about the consequences of such advisers’ usage.

As an example let us consider a chart of the classical EA's balance working on blowouts, with various values of RQF_TEST. The Expert Advisor is taken from the article "My first Grail" ().And it was slightly transformed for visualization. All orders of limit type are realized by usual market ones, and also parameters are gleaned so that charts show parameters’ deterioration when requoting most evidently.


No reqoutes (RQF_TEST = 0):


In 90 cases of 100 there is a requote (RQF_TEST = 90):



Obviously, the situation is extremely deplorable. Especially on the stipulation that testing EURCHF is the extremely illiquid pair and requotes are very frequent even on the quiet markets, much less on blowouts ones. Therefore, the expediency of our EA usage is vanishing despite of the very beautiful chart when requotation is absenting.



Remarks And Additions

Actually, it is rather difficult to find the adviser which could become from profitable to unprofitable because of requotes. I was searching such an Expert Advisor, that its quality cutback could be clearly demonstrated at the balance chart, for a long time. Usually requotation (even at the level of 50 %) axes the quantity of transactions and the profit, when the chart outwardly is the same (constant). There is a simple explanation to it: if the broker does not allow you to open the order on the “stake” in 90 cases from 100, then in the residual 10 % of the situations you’ll receive some pips of profits, and until you aren’t forbidden to use EAs. Such situations were described in the article "My first Grail ". But even if we assume, that the broker will not encumber (it is scarcely), 10 times reduced profit (and it is exactly such figure when requoting at the level of 90 % - the adviser simply "misses" 90 “stakes” from 100) will rob of all "Grail" advantages – it will be less profitable, rather than the bank deposit.

Translated from Russian by MetaQuotes Software Corp.
Original article: https://www.mql5.com/ru/articles/1442

Attached files |
Graal2.mq4 (11.1 KB)
Ten "Errors" of a Newcomer in Trading? Ten "Errors" of a Newcomer in Trading?

The article substantiates approach to building a trading system as a sequence of opening and closing the interrelated orders regarding the existing conditions - prices and the current values of each order's profit/loss, not only and not so much the conventional "alerts". We are giving an exemplary realization of such an elementary trading system.

Alternative Log File with the Use of HTML and CSS Alternative Log File with the Use of HTML and CSS

In this article we will describe the process of writing a simple but a very powerful library for making the html files, will learn to adjust their displaying and will see how they can be easily implemented and used in your expert or the script.

How to Develop a Reliable and Safe Trade Robot in MQL 4 How to Develop a Reliable and Safe Trade Robot in MQL 4

The article deals with the most common errors that occur in developing and using of an Expert Advisor. An exemplary safe automated trading system is described, as well.

MQL4 Language for Newbies. Introduction MQL4 Language for Newbies. Introduction

This sequence of articles is intended for traders, who know nothing about programming, but have a desire to learn MQL4 language as quick as possible with minimal time and effort inputs. If you are afraid of such phrases as "object orientation" or "three dimensional arrays", this article is what you need. The lessons are designed for the maximally quick result. Moreover, the information is delivered in a comprehensible manner. We shall not go too deep into the theory, but you will gain the practical benefit already from the first lesson.