test_script
Download scriptThis script serves as a diagnostic tool designed to test how the trading platform handles various common errors and edge cases when managing orders. Rather than executing a specific trading strategy, it systematically triggers different scenarios to observe how the system responds to "problematic" instructions.
The logic is divided into four distinct testing phases:
Phase 1: Handling Invalid Identifiers The script attempts to scan through a massive list of order IDs. It purposefully seeks out an order that does not exist and tries to delete it. This tests how the platform reports errors when you try to perform an action on a "ghost" ticket—essentially checking if the system correctly identifies and logs an invalid request.
Phase 2: Lifecycle of a Live Trade In this section, the script simulates a standard trading workflow. It opens a new buy position at the current market price and immediately attempts to close it. Once the trade is closed, it tries to remove the record from the active list. This validates that the transition from an "Open Trade" to a "Closed Trade" is handled smoothly by the software.
Phase 3: Handling Extreme Price Data This test pushes the boundaries of the system by attempting to open a trade at an unrealistic price point (an extremely high value). Because this price is far outside of normal market limits, the order will fail to be placed. The script then tries to delete that failed request to see how the platform manages "non-existent" orders created by invalid price data.
Phase 4: Market Order Restrictions Finally, the script tests the rules regarding "Market Orders." In many trading environments, certain types of orders cannot be deleted while they are still active; they must be closed first. The script attempts to delete an open order directly. If the platform prevents this (which is standard behavior), the script is designed to recognize that failure and automatically switch to a "Close" command instead.
Summary for Users Think of this script as a "stress test." It intentionally creates various types of mistakes—such as trying to delete things that aren't there, using impossible prices, or ignoring standard closing procedures—to ensure the platform logs these errors correctly and remains stable under irregular conditions.
//+------------------------------------------------------------------+
//| test.mq4 |
//| Copyright © 2005, Serega Lykov |
//| http://mtexperts.narod.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Serega Lykov"
#property link "http://mtexperts.narod.ru/"
int start()
{
//---- OrderSelect() = false -----------------------------------------
// return error: 4051 (ERR_INVALID_FUNCTION_PARAMVALUE)
// message at logs: invalid ticket for OrderDelete function
Print("1. ------------------------------------------------------");
for(int i=1; i<100000; i++)
{
if(OrderSelect(i,SELECT_BY_TICKET) == true) continue;
bool error = OrderDelete(OrderTicket(),CLR_NONE);
if(error == false) Print("Error = ",GetLastError());
break;
}
//---- delete order from history -------------------------------------
// return error: 4108 (ERR_INVALID_TICKET)
// message at logs: unknown ticket 24858529 for OrderDelete function
Print("2. ------------------------------------------------------");
int ticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"",0,0,CLR_NONE);
OrderClose(ticket,0.01,Bid,10,CLR_NONE);
if(OrderSelect(ticket,SELECT_BY_TICKET) == true)
{
error = OrderDelete(OrderTicket(),CLR_NONE);
if(error == false) Print("Error = ",GetLastError());
}
//---- OrderSend() < 0 ----------------------------------------------
// return error: 4051 (ERR_INVALID_FUNCTION_PARAMVALUE)
// message at logs: invalid ticket for OrderDelete function
Print("3. ------------------------------------------------------");
ticket = OrderSend(Symbol(),OP_BUY,0.01,100000,3,0,0,"",0,0,CLR_NONE);
error = OrderDelete(ticket,CLR_NONE);
if(error == false) Print("Error = ",GetLastError());
//---- delete market order -------------------------------------------
// return error: 4108 (ERR_INVALID_TICKET)
// message at logs: market order #24859072 cannot be deleted
Print("4. ------------------------------------------------------");
ticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"",0,0,CLR_NONE);
error = OrderDelete(ticket,CLR_NONE);
if(error == false)
{
Print("Error = ",GetLastError());
OrderClose(ticket,0.01,Bid,10,CLR_NONE);
}
return(0);
}
//+------------------------------------------------------------------+
Profitability Reports
Expected payoff
Average expected payoff across the available backtests for each symbol.
Comments