Modelling Requotes in Tester and Expert Advisor Stability Analysis
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 Ltd.
Original article: https://www.mql5.com/ru/articles/1442
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use