Issue #16: implemented backtesting functionality into MtApi5

This commit is contained in:
vdemydiuk
2016-10-07 17:08:16 +03:00
parent 0b3d686f05
commit d4ee2cfada
6 changed files with 221 additions and 143 deletions
BIN
View File
Binary file not shown.
+58 -1
View File
@@ -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);