In order to increase the speed during testing, it makes sense to make the events individually switchable. Below is an example of how I use it myself. Or a better solution.
`
input bool Enable_OnBookEvent = false; // for faster testing
input bool Enable_OnTickEvent = false; // for faster testing
input bool Enable_OnTradeTransaction = false; // for faster testing
void OnTick()
{
string symbol = Symbol();
bool lastbar_time_changed = false;
long lastbar_time = SeriesInfoInteger(symbol, Period(), SERIES_LASTBAR_DATE);
if (_last_bar_open_time != lastbar_time)
{
if (_last_bar_open_time != 0)
{
MqlRates rates_array[];
CopyRates(symbol, Period(), 1, 1, rates_array);
In order to increase the speed during testing, it makes sense to make the events individually switchable. Below is an example of how I use it myself. Or a better solution. `
input bool Enable_OnBookEvent = false; // for faster testing input bool Enable_OnTickEvent = false; // for faster testing input bool Enable_OnTradeTransaction = false; // for faster testing
void OnTick() { string symbol = Symbol();
bool lastbar_time_changed = false; long lastbar_time = SeriesInfoInteger(symbol, Period(), SERIES_LASTBAR_DATE); if (_last_bar_open_time != lastbar_time) { if (_last_bar_open_time != 0) { MqlRates rates_array[]; CopyRates(symbol, Period(), 1, 1, rates_array);
} if (Enable_OnTickEvent) { MqlTick last_tick; SymbolInfoTick(Symbol(),last_tick);
}
if (IsTesting()) { if (BacktestingLockTicks == LOCK_EVERY_TICK || (BacktestingLockTicks == LOCK_EVERY_CANDLE && lastbar_time_changed)) { _is_ticks_locked = true;
} }
void OnTradeTransaction( const MqlTradeTransaction& trans, // trade transaction structure const MqlTradeRequest& request, // request structure const MqlTradeResult& result // result structure
) {
ifdef __DEBUG_LOG__
PrintFormat("%s:", FUNCTION);
endif
if(Enable_OnTradeTransaction) { MtOnTradeTransactionEvent* trans_event = new MtOnTradeTransactionEvent(trans, request, result); SendMtEvent(ON_TRADE_TRANSACTION_EVENT, trans_event); delete trans_event;}
}
void OnBookEvent(const string& symbol) {
ifdef __DEBUG_LOG__
endif
if(Enable_OnBookEvent) { MtOnBookEvent * book_event = new MtOnBookEvent(symbol); SendMtEvent(ON_BOOK_EVENT, book_event); delete book_event; } } `