Adwizard/Experts/Optimization.mqh

104 lines
6.9 KiB
MQL5
Raw Permalink Normal View History

2025-04-11 13:28:40 +03:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| Optimization.mqh |
//| Copyright 2024, Yuriy Bykov |
//| https://www.mql5.com/ru/users/antekov |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, Yuriy Bykov"
#property link "https://www.mql5.com/ru/users/antekov"
#property description "!>25B=8: 4;O 02B><0B8G5A:>9 >?B8<870F88 ?@>5:B>2"
#property version "1.06"
2025-04-11 13:28:40 +03:00
2025-04-11 15:16:52 +03:00
#include "../Optimization/Optimizer.mqh"
2025-07-08 19:36:43 +03:00
#include "../Utils/ConsoleDialog.mqh"
2025-04-11 13:28:40 +03:00
// !>740Q< :>=AB0=BK 4;O ?0@0<5B@>2 ?> C<>;G0=8N,
// 5A;8 >=8 =5 >?@545;5=K 2 ?@>5:B=>9 G0AB8
#ifndef OPT_FILEMNAME
#define OPT_FILEMNAME ""
#endif
2025-04-11 13:28:40 +03:00
#ifndef OPT_PYTHONPATH
#define OPT_PYTHONPATH ""
#endif
sinput string fileName_ = OPT_FILEMNAME; // - $09; A >A=>2=>9 107>9 40==KE
sinput string pythonPath_ = OPT_PYTHONPATH; // - CBL : 8=B5@?@5B0B>@C Python
COptimizer *optimizer; // #:070B5;L =0 >1J5:B >?B8<870B>@0
2025-04-11 13:28:40 +03:00
2025-07-08 19:36:43 +03:00
CConsoleDialog *dialog; // 80;>3 4;O 2K2>40 B5:AB0 A 8=D>@<0F859
2025-04-11 13:28:40 +03:00
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit() {
// A;8 D09; 107K 40==KE =5 C:070=, B> 2KE>48<
if(fileName_ == "") {
PrintFormat(__FUNCTION__" | ERROR: Set const OPT_FILEMNAME with filename of DB in project", 0);
return INIT_FAILED;
}
// !>740Q< >?B8<870B>@
2025-04-11 13:28:40 +03:00
optimizer = new COptimizer(fileName_, pythonPath_);
2025-07-08 19:36:43 +03:00
// !>740Q< 8 70?CA:05< 480;>3 4;O 2K2>40 8=D>@<0F88
dialog = new CConsoleDialog();
dialog.Create(__FILE__);
dialog.Run();
// !>740Q< B09<5@ 8 70?CA:05< 53> >1@01>BG8:
2025-07-12 22:25:09 +03:00
EventSetTimer(2);
2025-04-11 13:28:40 +03:00
OnTimer();
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert timer function |
//+------------------------------------------------------------------+
void OnTimer() {
2025-07-22 21:12:06 +03:00
if(IsStopped()) return;
// 0?CA:05< >1@01>B:C >?B8<870B>@0
2025-04-11 13:28:40 +03:00
optimizer.Process();
2025-07-12 22:25:09 +03:00
2025-07-08 19:36:43 +03:00
dialog.Text(optimizer.Text());
2025-04-11 13:28:40 +03:00
}
//+------------------------------------------------------------------+
2025-07-12 22:25:09 +03:00
//| 1@01>B:0 A>1KB89 |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, // event ID
const long & lparam, // event parameter of the long type
const double & dparam, // event parameter of the double type
const string & sparam) { // event parameter of the string type
2025-07-22 21:12:06 +03:00
if(!!dialog && !IsStopped()) {
2025-07-12 22:25:09 +03:00
dialog.ChartEvent(id, lparam, dparam, sparam);
}
}
//+------------------------------------------------------------------+
2025-04-11 13:28:40 +03:00
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
2025-07-22 21:12:06 +03:00
PrintFormat(__FUNCTION__);
2025-04-11 13:28:40 +03:00
EventKillTimer();
// #40;O5< >?B8<870B>@
2025-04-11 13:28:40 +03:00
if(!!optimizer) {
delete optimizer;
}
2025-07-12 22:25:09 +03:00
2025-07-08 19:36:43 +03:00
// #40;O5< 480;>3
if(!!dialog) {
2025-07-12 22:25:09 +03:00
dialog.Destroy();
2025-07-08 19:36:43 +03:00
delete dialog;
2025-07-22 21:12:06 +03:00
ChartRedraw();
2025-07-08 19:36:43 +03:00
}
2025-07-12 22:25:09 +03:00
2025-07-22 21:12:06 +03:00
2025-04-11 13:28:40 +03:00
}
//+------------------------------------------------------------------+