diff --git a/MtApi5/MtApi5.csproj b/MtApi5/MtApi5.csproj
index e836a6c3..f10e46e9 100755
--- a/MtApi5/MtApi5.csproj
+++ b/MtApi5/MtApi5.csproj
@@ -3,7 +3,7 @@
net8.0
enable
enable
- 2.0.0
+ 2.0.1
$(SolutionDir)build\products
true
diff --git a/mq5/MtApi5.ex5 b/mq5/MtApi5.ex5
index e5cb3a8f..966f8aae 100755
Binary files a/mq5/MtApi5.ex5 and b/mq5/MtApi5.ex5 differ
diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5
index d4cd9ac9..5b7a1c06 100644
--- a/mq5/MtApi5.mq5
+++ b/mq5/MtApi5.mq5
@@ -32,6 +32,7 @@ enum LockTickType
};
input int Port = 8228;
+input int CommandPollingIntervalMs = 100; // command polling interval in live trading, ms (10-1000)
input LockTickType BacktestingLockTicks = NO_LOCK;
input group "Disable Events "
input bool Enable_OnBookEvent = true;
@@ -106,13 +107,14 @@ void OnTick()
(BacktestingLockTicks == LOCK_EVERY_CANDLE && lastbar_time_changed))
{
_is_ticks_locked = true;
-
+
MtLockTickEvent lock_tick_event(symbol);
SendMtEvent(ON_LOCK_TICKS_EVENT, lock_tick_event);
}
-
- OnTimer();
}
+
+ //--- Process pending commands on every tick (supplements timer in live mode)
+ OnTimer();
}
void OnTradeTransaction(
@@ -446,31 +448,44 @@ int init()
//--- Backtesting mode
if (IsTesting())
- {
+ {
Print("Waiting on remote client...");
//wait for command (BacktestingReady) from remote side to be ready for work
while(!IsRemoteReadyForTesting)
{
executeCommand();
-
+
//This section uses a while loop to simulate Sleep() during Backtest.
unsigned int viSleepUntilTick = GetTickCount() + 100; //100 milliseconds
- while(GetTickCount() < viSleepUntilTick)
+ while(GetTickCount() < viSleepUntilTick)
{
//Do absolutely nothing. Just loop until the desired tick is reached.
}
}
}
- //---
+ else
+ {
+ //--- In live trading, poll for commands via timer (configurable interval)
+ int polling_interval = CommandPollingIntervalMs;
+ if (polling_interval < 10) polling_interval = 10;
+ if (polling_interval > 1000) polling_interval = 1000;
+ if (polling_interval != CommandPollingIntervalMs)
+ PrintFormat("[WARNING] CommandPollingIntervalMs=%d out of range, clamped to %d", CommandPollingIntervalMs, polling_interval);
+ if (!EventSetMillisecondTimer(polling_interval))
+ Print("[WARNING] Failed to set millisecond timer for command polling");
+ }
+ //---
return (0);
}
-int deinit()
+int deinit()
{
- if (isCrashed == 0)
+ EventKillTimer();
+
+ if (isCrashed == 0)
{
- if (!deinitExpert(ExpertHandle, _error))
+ if (!deinitExpert(ExpertHandle, _error))
{
MessageBox(_error, "MtApi", 0);
isCrashed = true;