add switchable Events

The function SendMtEvent requires a lot of computing time. To improve the speed of the tester, the events can now be switched off individually
This commit is contained in:
Christian_X3
2020-06-18 05:57:05 +02:00
parent abfe1a281a
commit 3997b6df74
+21 -3
View File
@@ -50,6 +50,12 @@ enum LockTickType
input int Port = 8228; input int Port = 8228;
input LockTickType BacktestingLockTicks = NO_LOCK; input LockTickType BacktestingLockTicks = NO_LOCK;
input group "Disable Events "
input bool Enable_OnBookEvent = true;
input bool Enable_OnTickEvent = true;
input bool Enable_OnTradeTransactionEvent = true;
input bool Enable_OnLastBarEvent = true;
int ExpertHandle; int ExpertHandle;
@@ -90,6 +96,8 @@ void OnTick()
if (_last_bar_open_time != lastbar_time) if (_last_bar_open_time != lastbar_time)
{ {
if (_last_bar_open_time != 0 ) if (_last_bar_open_time != 0 )
{
if(Enable_OnLastBarEvent)
{ {
MqlRates rates_array[]; MqlRates rates_array[];
CopyRates(symbol, Period(), 1, 1, rates_array); CopyRates(symbol, Period(), 1, 1, rates_array);
@@ -97,19 +105,21 @@ void OnTick()
MtTimeBarEvent* time_bar = new MtTimeBarEvent(symbol, rates_array[0]); MtTimeBarEvent* time_bar = new MtTimeBarEvent(symbol, rates_array[0]);
SendMtEvent(ON_LAST_TIME_BAR_EVENT, time_bar); SendMtEvent(ON_LAST_TIME_BAR_EVENT, time_bar);
delete time_bar; delete time_bar;
}
lastbar_time_changed = true; lastbar_time_changed = true;
} }
_last_bar_open_time = lastbar_time; _last_bar_open_time = lastbar_time;
} }
if (Enable_OnTickEvent)
{
MqlTick last_tick; MqlTick last_tick;
SymbolInfoTick(Symbol(),last_tick); SymbolInfoTick(Symbol(),last_tick);
MtOnTickEvent * tick_event = new MtOnTickEvent(symbol, last_tick); MtOnTickEvent * tick_event = new MtOnTickEvent(symbol, last_tick);
SendMtEvent(ON_TICK_EVENT, tick_event); SendMtEvent(ON_TICK_EVENT, tick_event);
delete tick_event; delete tick_event;
}
if (IsTesting()) if (IsTesting())
{ {
@@ -133,17 +143,23 @@ void OnTradeTransaction(
const MqlTradeResult& result // result structure const MqlTradeResult& result // result structure
) )
{ {
if(!Enable_OnTradeTransactionEvent) return;
#ifdef __DEBUG_LOG__ #ifdef __DEBUG_LOG__
PrintFormat("%s:", __FUNCTION__); PrintFormat("%s:", __FUNCTION__);
#endif #endif
MtOnTradeTransactionEvent* trans_event = new MtOnTradeTransactionEvent(trans, request, result); MtOnTradeTransactionEvent* trans_event = new MtOnTradeTransactionEvent(trans, request, result);
SendMtEvent(ON_TRADE_TRANSACTION_EVENT, trans_event); SendMtEvent(ON_TRADE_TRANSACTION_EVENT, trans_event);
delete trans_event; delete trans_event;
}
}
void OnBookEvent(const string& symbol) void OnBookEvent(const string& symbol)
{ {
if(!Enable_OnBookEvent) return;
#ifdef __DEBUG_LOG__ #ifdef __DEBUG_LOG__
PrintFormat("%s: %s", __FUNCTION__, symbol); PrintFormat("%s: %s", __FUNCTION__, symbol);
#endif #endif
@@ -151,6 +167,7 @@ void OnBookEvent(const string& symbol)
MtOnBookEvent * book_event = new MtOnBookEvent(symbol); MtOnBookEvent * book_event = new MtOnBookEvent(symbol);
SendMtEvent(ON_BOOK_EVENT, book_event); SendMtEvent(ON_BOOK_EVENT, book_event);
delete book_event; delete book_event;
} }
int preinit() int preinit()
@@ -7521,6 +7538,7 @@ void SendMtEvent(MtEventTypes eventType, MtEvent* mtEvent)
if (sendEvent(ExpertHandle, (int)eventType, json.toString(), _error)) if (sendEvent(ExpertHandle, (int)eventType, json.toString(), _error))
{ {
#ifdef __DEBUG_LOG__ #ifdef __DEBUG_LOG__
PrintFormat("%s: event = %s", __FUNCTION__, EnumToString(eventType));
PrintFormat("%s: payload = %s", __FUNCTION__, json.toString()); PrintFormat("%s: payload = %s", __FUNCTION__, json.toString());
#endif #endif
} }