mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-15 03:38:09 +00:00
Issue #16: implemented backtesting functionality into MtApi5
This commit is contained in:
Binary file not shown.
+58
-1
@@ -43,6 +43,8 @@ int ExpertHandle;
|
||||
string message;
|
||||
bool isCrashed = false;
|
||||
|
||||
bool IsRemoteReadyForTesting = false;
|
||||
|
||||
string symbolValue;
|
||||
string commentValue;
|
||||
|
||||
@@ -54,6 +56,12 @@ int OnInit()
|
||||
return (result);
|
||||
}
|
||||
|
||||
double OnTester()
|
||||
{
|
||||
Print("OnTester");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
deinit();
|
||||
@@ -81,6 +89,12 @@ bool IsDemo()
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool IsTesting()
|
||||
{
|
||||
bool isTesting = MQLInfoInteger(MQL_TESTER);
|
||||
return isTesting;
|
||||
}
|
||||
|
||||
int init()
|
||||
{
|
||||
preinit();
|
||||
@@ -125,6 +139,27 @@ int init()
|
||||
isCrashed = true;
|
||||
return (1);
|
||||
}
|
||||
|
||||
PrintFormat("Expert Handle = %d", ExpertHandle);
|
||||
|
||||
//--- 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)
|
||||
{
|
||||
//Do absolutely nothing. Just loop until the desired tick is reached.
|
||||
}
|
||||
}
|
||||
}
|
||||
//---
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -139,6 +174,7 @@ int deinit()
|
||||
isCrashed = true;
|
||||
return (1);
|
||||
}
|
||||
Print("Wxpert was deinitialized.");
|
||||
}
|
||||
|
||||
return (0);
|
||||
@@ -1631,7 +1667,28 @@ int executeCommand()
|
||||
sendBooleanResponse(ExpertHandle, result);
|
||||
Print("command PositionOpen: result = ", result);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case 66: //BacktestingReady
|
||||
{
|
||||
if (IsTesting())
|
||||
{
|
||||
Print("Remote client is ready for backteting");
|
||||
IsRemoteReadyForTesting = true;
|
||||
sendBooleanResponse(ExpertHandle, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendBooleanResponse(ExpertHandle, false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 67: //IsTesting
|
||||
{
|
||||
sendBooleanResponse(ExpertHandle, IsTesting());
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
Print("Unknown command type = ", commandType);
|
||||
|
||||
Reference in New Issue
Block a user