Adwizard/Experts/Stage3.mqh

159 lines
14 KiB
MQL5
Raw Permalink Normal View History

2025-04-11 13:28:40 +03:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Stage3.mqh |
//| Copyright 2024-2025, Yuriy Bykov |
//| https://www.mql5.com/ru/users/antekov |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024-2025, Yuriy Bykov"
#property link "https://www.mql5.com/ru/articles/17328"
#property description "!>25B=8:, A>E@0=ONI89 AD>@<8@>20==CN =>@<8@>20==CN 3@C??C AB@0B5389 "
#property description "2 181;8>B5:C 3@C?? A 7040==K< 8<5=5<."
#property version "1.05"
#ifndef __NAME__
#define __NAME__ "EmptyStrategy"
#endif
#include "../Virtual/VirtualAdvisor.mqh"
//+------------------------------------------------------------------+
//| E>4=K5 ?0@0<5B@K |
//+------------------------------------------------------------------+
sinput int idTask_ = 38; // - 45=B8D8:0B>@ 7040G8 >?B8<870F88
sinput string fileName_ = "article.16373.db.sqlite"; // - $09; A >A=>2=>9 107>9 40==KE
input group "::: B1>@ 2 3@C??C"
input string passes_ = ""; // - 45=B8D8:0B>@K ?@>E>4>2 G5@57 70?OBCN
input group "::: !>E@0=5=85 2 181;8>B5:C"
input string groupName_ = "SimpleVolumes_v.1.20_2023.01.01"; // - 0720=85 25@A88 (5A;8 ?CAB>5 - =5 A>E@0=OBL)
input string advFileName_ = "SimpleVolumes-27183.test.db.sqlite"; // - 0720=85 107K 40==KE M:A?5@B0
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double expectedDrawdown_ = 10; // - 0:A8<0;L=K9 @8A: (%)
double fixedBalance_ = 10000; // - A?>;L7C5<K9 45?>78B (0 - 8A?>;L7>20BL 25AL) 2 20;NB5 AG5B0
double scale_ = 1.00; // - 0AHB018@CNI89 <=>68B5;L 4;O 3@C??K
ulong magic_ = 27183; // - Magic
CVirtualAdvisor *expert; // 1J5:B M:A?5@B0
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit() {
// #AB0=02;8205< ?0@0<5B@K 2 :;0AA5 C?@02;5=8O :0?8B0;><
CMoney::DepoPart(expectedDrawdown_ / 10.0);
CMoney::FixedBalance(fixedBalance_);
CVirtualAdvisor::TesterInit(idTask_, fileName_);
// !B@>:0 8=8F80;870F88 A =01>@0<8 ?0@0<5B@>2 AB@0B5389
string strategiesParams = NULL;
// A;8 A>548=5=85 A >A=>2=>9 107>9 40==KE CAB0=>2;5=>, B>
if(DB::Connect(fileName_)) {
// $>@<8@C5< 70?@>A =0 ?>;CG5=85 ?@>E>4>2 A C:070==K<8 845B8D8:0B>@0<8
string query = (passes_ == "" ?
StringFormat("SELECT DISTINCT FIRST_VALUE(p.params) OVER (PARTITION BY p.id_task ORDER BY custom_ontester DESC) AS params "
" FROM passes p "
" WHERE p.id_task IN ("
" SELECT pt.id_task "
" FROM tasks t "
" JOIN "
" jobs j ON j.id_job = t.id_job "
" JOIN "
" stages s ON s.id_stage = j.id_stage "
" JOIN "
" jobs pj ON pj.id_stage = s.id_parent_stage "
" JOIN "
" tasks pt ON pt.id_job = pj.id_job "
" WHERE t.id_task = %d "
" ) ", idTask_)
: StringFormat("SELECT params"
" FROM passes "
" WHERE id_pass IN (%s);", passes_)
);
Print(query);
int request = DatabasePrepare(DB::Id(), query);
if(request != INVALID_HANDLE) {
// !B@C:BC@0 4;O GB5=8O @57C;LB0B>2
struct Row {
string params;
} row;
// ;O 2A5E AB@>: @57C;LB0B0 70?@>A0, A>548=O5< AB@>:8 8=8F80;870F88
while(DatabaseReadBind(request, row)) {
strategiesParams += row.params + ",";
}
}
DB::Close();
}
// A;8 =01>@>2 ?0@0<5B@2 =5 =0945=>, B> ?@5@K205< B5AB8@>20=85
if(strategiesParams == NULL) {
return INIT_FAILED;
}
// >43>B02;8205< AB@>:C 8=8F80;870F88 4;O M:A?5@B0 A 3@C??>9 87 =5A:>;L:8E AB@0B5389
string expertParams = StringFormat(
"class CVirtualAdvisor(\n"
" class CVirtualStrategyGroup(\n"
" [\n"
" %s\n"
" ],%f\n"
" ),\n"
" class CVirtualRiskManager(\n"
" 0,0,0,0,0,0,0,0,0,0,0,0,0"
" )\n"
" ,%d,%s,%d\n"
")",
strategiesParams, scale_,
magic_, __NAME__, true
);
PrintFormat(__FUNCTION__" | Expert Params:\n%s", expertParams);
// !>7405< M:A?5@B0, @01>B0NI53> A 28@BC0;L=K<8 ?>78F8O<8
expert = NEW(expertParams);
// A;8 M:A?5@B =5 A>740=, B> 2>72@0I05< >H81:C
if(!expert) return INIT_FAILED;
// #A?5H=0O 8=8F80;870F8O
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick() {
expert.Tick();
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
if(!!expert) delete expert;
}
//+------------------------------------------------------------------+
//| 57C;LB0B B5AB8@>20=8O |
//+------------------------------------------------------------------+
double OnTester(void) {
// 1@010BK205< 7025@H5=85 ?@>E>40 2 >1J5:B5 M:A?5@B0
double res = expert.Tester();
// A;8 8<O 3@C??K =5 ?CAB>5, B> A>E@0=O5< ?@>E>4 2 181;8>B5:C
if(groupName_ != "") {
expert.Export(groupName_, advFileName_);
}
return res;
}
//+------------------------------------------------------------------+