Virtual_by_fxsaber/Include/fxsaber/Virtual/VirtualTester_Script.mqh

101 lines
No EOL
7.5 KiB
MQL5

#define VIRTUAL_NOCHECK_NULL // Не проверять (VIRTUAL::SelectOrders != NULL) - ускорение.
#include "VirtualTester.mqh" // https://www.mql5.com/ru/code/22577
input group "[Tester]"
input string inSymbols = "EURGBP, EURUSD"; // Symbols
input datetime inFrom = D'2024.01.01'; // From
input datetime inTo = D'2025.01.01'; // To
input double inBalance = 10000; // Deposit
input group "[Tester - options]"
input uint inBenchmark = 5; // Benchmark
input bool inStop = true; // Close All by End
input bool inNetting = false; // Netting
input ENUM_VIRTUALTESTER_TYPE inVirtualTester_Type = VIRTUALTESTER_APART; // VirtualTester's type
#ifdef REPORT_TESTER
#undef REPORT_TESTER
input bool inReport = true; // Report
#include <Report.mqh> // https://www.mql5.com/ru/code/18801
#define REPORT_ENABLE
#endif // #ifdef REPORT_TESTER
void OnStart2()
{
VIRTUAL_TESTER VirtualTester(inSymbols, inBalance);
if (inBenchmark)
{
bool Res = VirtualTester.SetInterval(inFrom, inTo);
if (Res)
{
Print("Benchmark mode.");
double Performance = 0;
ulong Length = 0;
for (uint i = 0; (i < inBenchmark) && Res && !IsStopped(); i++)
if (Res = (VirtualTester.Run(OnTickMulti, inStop, inNetting, inVirtualTester_Type) != -1) && !IsStopped())
{
const double NewPerformance = VirtualTester.GetPerformance();
if (NewPerformance > Performance)
{
Performance = NewPerformance;
Length = VirtualTester.GetLength();
}
Print((string)(i + 1) + "/" + (string)inBenchmark +
": Performance = " + VIRTUAL_TESTER::NumToString(NewPerformance, 3) +
" [" + VIRTUAL_TESTER::LengthToString(VirtualTester.GetLength() / 1000) +
"](" + DoubleToString(100 * NewPerformance / Performance, 2) +
"%), Best = " + VIRTUAL_TESTER::NumToString(Performance, 3) + " ticks/sec [" +
VIRTUAL_TESTER::LengthToString(Length / 1000) + "]");
VIRTUAL::Delete();
}
Print("-----------------\nBestPerformance = " + VIRTUAL_TESTER::NumToString(Performance, 3) + " ticks/sec [" +
VIRTUAL_TESTER::LengthToString(Length / 1000) + "]");
Print("\nCompiler Version: " + (string)__MQLBUILD__ + " " + __CPU_ARCHITECTURE__);
Print(VIRTUAL::GetMode());
}
if (!Res)
Print("Error: " + (string)_LastError);
}
else
{
if (VirtualTester.SetInterval(inFrom, inTo) && (VirtualTester.Run(OnTickMulti, inStop, inNetting, inVirtualTester_Type) != -1))
{
Print(VirtualTester.ToString());
#ifdef REPORT_ENABLE
if (inReport)
REPORT::ToFile();
#endif // #ifdef REPORT_ENABLE
}
else
Print("Error: " + (string)_LastError);
}
}
#ifdef REPORT_ENABLE
#undef REPORT_ENABLE
#endif // #ifdef REPORT_ENABLE
// https://www.mql5.com/ru/forum/464362/page3#comment_52854154
// Для эффекта нужно вырубить VIRTUAL_NOCHECK_NULL.
void OnStart() { OnStart2(); } // BestPerformance = 13 688 465.0 ticks/sec [00:00:01.083]
//void OnInit() { OnStart2(); } // BestPerformance = 13 661 990.1 ticks/sec [00:00:01.085]
//void OnInit() { OnStart2(); ExpertRemove(); } // BestPerformance = 12 972 229.3 ticks/sec [00:00:01.143]
//int OnInit() { OnStart2(); return(INIT_FAILED); } // BestPerformance = 12 385 010.1 ticks/sec [00:00:01.197]
//int OnInit() { OnStart2(); ExpertRemove(); return(INIT_FAILED); } // BestPerformance = 12 985 129.2 ticks/sec [00:00:01.142]
input group "[TesterInputs]"