Download MetaTrader 5

Modelling Requotes in Tester and Expert Advisor Stability Analysis

22 May 2007, 09:54
Murashov Anton
0
832

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)
Step on New Rails: Custom Indicators in MQL5 Step on New Rails: Custom Indicators in MQL5

I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.

Here Comes the New MetaTrader 5 and MQL5 Here Comes the New MetaTrader 5 and MQL5

This is just a brief review of MetaTrader 5. I can't describe all the system's new features for such a short time period - the testing started on 2009.09.09. This is a symbolical date, and I am sure it will be a lucky number. A few days have passed since I got the beta version of the MetaTrader 5 terminal and MQL5. I haven't managed to try all its features, but I am already impressed.

False trigger protection for Trading Robot False trigger protection for Trading Robot

Profitability of trading systems is defined not only by logic and precision of analyzing the financial instrument dynamics, but also by the quality of the performance algorithm of this logic. False trigger is typical for low quality performance of the main logic of a trading robot. Ways of solving the specified problem are considered in this article.

Using text files for storing input parameters of Expert Advisors, indicators and scripts Using text files for storing input parameters of Expert Advisors, indicators and scripts

The article describes the application of text files for storing dynamic objects, arrays and other variables used as properties of Expert Advisors, indicators and scripts. The files serve as a convenient addition to the functionality of standard tools offered by MQL languages.