mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-16 12:18:09 +00:00
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:
+48
-30
@@ -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;
|
||||||
|
|
||||||
@@ -89,27 +95,31 @@ void OnTick()
|
|||||||
long lastbar_time = SeriesInfoInteger(symbol, Period(), SERIES_LASTBAR_DATE);
|
long lastbar_time = SeriesInfoInteger(symbol, Period(), SERIES_LASTBAR_DATE);
|
||||||
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 )
|
||||||
{
|
{
|
||||||
MqlRates rates_array[];
|
if(Enable_OnLastBarEvent)
|
||||||
CopyRates(symbol, Period(), 1, 1, rates_array);
|
{
|
||||||
|
MqlRates rates_array[];
|
||||||
|
CopyRates(symbol, Period(), 1, 1, rates_array);
|
||||||
|
|
||||||
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;
|
||||||
|
SymbolInfoTick(Symbol(),last_tick);
|
||||||
|
|
||||||
MqlTick last_tick;
|
MtOnTickEvent * tick_event = new MtOnTickEvent(symbol, last_tick);
|
||||||
SymbolInfoTick(Symbol(),last_tick);
|
SendMtEvent(ON_TICK_EVENT, tick_event);
|
||||||
|
delete tick_event;
|
||||||
MtOnTickEvent * tick_event = new MtOnTickEvent(symbol, last_tick);
|
}
|
||||||
SendMtEvent(ON_TICK_EVENT, tick_event);
|
|
||||||
delete tick_event;
|
|
||||||
|
|
||||||
if (IsTesting())
|
if (IsTesting())
|
||||||
{
|
{
|
||||||
@@ -132,26 +142,33 @@ void OnTradeTransaction(
|
|||||||
const MqlTradeRequest& request, // request structure
|
const MqlTradeRequest& request, // request structure
|
||||||
const MqlTradeResult& result // result structure
|
const MqlTradeResult& result // result structure
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
#ifdef __DEBUG_LOG__
|
if(!Enable_OnTradeTransactionEvent) return;
|
||||||
PrintFormat("%s:", __FUNCTION__);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MtOnTradeTransactionEvent* trans_event = new MtOnTradeTransactionEvent(trans, request, result);
|
#ifdef __DEBUG_LOG__
|
||||||
SendMtEvent(ON_TRADE_TRANSACTION_EVENT, trans_event);
|
PrintFormat("%s:", __FUNCTION__);
|
||||||
delete trans_event;
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
MtOnTradeTransactionEvent* trans_event = new MtOnTradeTransactionEvent(trans, request, result);
|
||||||
|
SendMtEvent(ON_TRADE_TRANSACTION_EVENT, trans_event);
|
||||||
|
delete trans_event;
|
||||||
|
|
||||||
|
}
|
||||||
void OnBookEvent(const string& symbol)
|
void OnBookEvent(const string& symbol)
|
||||||
{
|
{
|
||||||
#ifdef __DEBUG_LOG__
|
|
||||||
PrintFormat("%s: %s", __FUNCTION__, symbol);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MtOnBookEvent * book_event = new MtOnBookEvent(symbol);
|
if(!Enable_OnBookEvent) return;
|
||||||
SendMtEvent(ON_BOOK_EVENT, book_event);
|
|
||||||
delete book_event;
|
#ifdef __DEBUG_LOG__
|
||||||
}
|
PrintFormat("%s: %s", __FUNCTION__, symbol);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
MtOnBookEvent * book_event = new MtOnBookEvent(symbol);
|
||||||
|
SendMtEvent(ON_BOOK_EVENT, 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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user