欢迎光临散文网 会员登陆 & 注册

赫兹股票交易软件:监视多币种的交易信号2---应用程序可视部分的实现

2023-07-13 13:26 作者:大牛啊呢  | 我要投稿


设置步骤 1:品种

根据应用程序结构,在首次启动期间应用程序设置的第一步即创建一个选择品种的界面,之后会搜索依此创建的交易信号。 在上一篇文章的末尾,我们创建了一个应用程序框架,现继续在此基础上操作。 我们继续开发应用程序。 首先,我们将定义实现此应用程序部分所需的主要元素组:

赫兹股票交易软件

  • 应用程序窗口。

  • 快速选择品种。

  • 输入字段分组。

  • 品种分组的“保存”和“加载”按钮。

  • 所有可用品种的完整列表呈现为复选框,文本标签表示品种名称。

  • “Next” 按钮将切换到设置的第二步:时间帧选择。

早前创建的文件结构如下所示:


编辑


图例 1 应用程序文件结构。


首先,打开 SignalMonitor.mq5 应用程序文件,并在其中添加输入参数。 在 MetaTrader 5 终端中直接运行该应用程序时,您能够设置参数。 另外,声明先前所创建 CProgram 类的实例,并初始化一些变量。 如下编辑文件:赫兹股票交易软件

//+------------------------------------------------------------------+ //|                                                SignalMonitor.mq5 | //|                                Copyright 2019, Alexander Fedosov | //|                           https://www.mql5.com/en/users/alex2356 | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, Alexander Fedosov" #property link      "https://www.mql5.com/en/users/alex2356" #property version   "1.00" //--- Include application class #include "Program.mqh" //+------------------------------------------------------------------+ //| Expert Advisor input parameters                                  | //+------------------------------------------------------------------+ input int                  Inp_BaseFont      =  10;                  // Basic font input color                Caption           =  C'0,130,225';        // Caption color input color                Background        =  clrWhiteSmoke;       // Background color //--- CProgram program; ulong tick_counter; //+------------------------------------------------------------------+ //| Expert initialization function                                   | //+------------------------------------------------------------------+ int OnInit(void) { //---   tick_counter=GetTickCount(); //--- Initialize class variables   program.OnInitEvent();   program.m_base_font_size=Inp_BaseFont;   program.m_background=Background;   program.m_caption=Caption; //--- Set up the trading panel   if(!program.CreateGUI())   {      Print(__FUNCTION__," > Failed to create graphical interface!");      return(INIT_FAILED);   } //--- Initialization completed successfully   return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function                                 | //+------------------------------------------------------------------+ void OnDeinit(const int reason) {   program.OnDeinitEvent(reason); } //+------------------------------------------------------------------+ //| Timer function                                                   | //+------------------------------------------------------------------+ void OnTimer(void) {   program.OnTimerEvent(); } //+------------------------------------------------------------------+ //| ChartEvent function                                              | //+------------------------------------------------------------------+ void OnChartEvent(const int    id,                  const long   &lparam,                  const double &dparam,                  const string &sparam) {   program.ChartEvent(id,lparam,dparam,sparam);   //---   if(id==CHARTEVENT_CUSTOM+ON_END_CREATE_GUI)   {      Print("End in ",GetTickCount()-tick_counter," ms");   } } //+------------------------------------------------------------------+

从代码中可以看出,加入了三个输入参数:


  • 字号。

  • 应用程序窗口的标头颜色。

  • 应用程序窗口和元素的背景色。

接着,声明 CProgram 的类实例,并命名为 program,和变量 tick_counter(仅用于显示有关应用程序启动时间的信息)。 进而,在 OnInit() 方法中,我们初始化类变量,把应用程序输入参数赋值给它们。 此外还要调用 CreateGUI() 基础方法,它将启动应用程序。

赫兹股票交易软件

不过,若您尝试立即编译打开的文件,会收到编译错误,示意在 CProgram 类中找不到变量 赫兹股票交易软件m_base_font_size、m_background、m_caption 和 CreateGUI() 方法。 故此,打开 Program.mqh 文件,在 CProgram 类里实现它们。 首先,加入上述变量和方法,以及应用程序正确初始操作所需的其他方法。 所需元素加入后,CProgram 将会如下所示:赫兹股票交易软件

//+------------------------------------------------------------------+ //| Class for creating an application                                | //+------------------------------------------------------------------+ class CProgram : public CWndEvents { public: //---   int               m_base_font_size; //---   string            m_base_font; //---   color             m_background;   color             m_caption; public:   CProgram(void);   ~CProgram(void);   //--- Initialization/deinitialization   void              OnInitEvent(void);   void              OnDeinitEvent(const int reason);   //--- Timer   void              OnTimerEvent(void);   //--- Chart event handler   virtual void      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);   //--- Create the graphical interface of the program   bool              CreateGUI(void); };

创建界面的方法实现仍然为空:

//+------------------------------------------------------------------+ //| Creates the graphical interface of the program                   | //+------------------------------------------------------------------+ bool CProgram::CreateGUI(void) { //--- //--- Finish the creation of GUI   CWndEvents::CompletedGUI();   return(true); } //+------------------------------------------------------------------+

请注意,我们还添加了 m_base_font 字符串型变量,该变量负责应用程序中的字体名称。 它是在我们的类构造函数中初始化:

//+------------------------------------------------------------------+ //| Constructor                                                      | //+------------------------------------------------------------------+ CProgram::CProgram(void) {   m_base_font="Trebuchet MS"; }

现在,我们继续创建应用程序的第一个窗口。 为此目的,在类中声明新的 m_step_window 变量,该变量是 CWindow 类的实例。 还要声明创建第一个窗口的方法,并命名为 CreateStepWindow()。 这是它在类代码中的样子:赫兹股票交易软件

class CProgram : public CWndEvents { public: //--- Application windows   CWindow           m_step_window; ... protected:   //--- forms   bool              CreateStepWindow(const string caption_text);

早前我们已经决定,赫兹股票交易软件初始启动时负责逐一配置的界面部分,其实现应位于 StepWindow.mqh 包含文件之中。 因此,打开它,并着手实现 CreateStepWindow() 方法:

#include "Program.mqh" //+------------------------------------------------------------------+ //| Creates a form for the selection of symbols                      | //+------------------------------------------------------------------+ bool CProgram::CreateStepWindow(const string text) { //--- Add the pointer to the window array   CWndContainer::AddWindow(m_step_window); //--- Properties   m_step_window.XSize(600);   m_step_window.YSize(200); //--- Coordinates   int x=int(ChartGetInteger(m_chart_id,CHART_WIDTH_IN_PIXELS)-m_step_window.XSize())/2;   int y=10;   m_step_window.CaptionHeight(22);   m_step_window.IsMovable(true);   m_step_window.CaptionColor(m_caption);   m_step_window.CaptionColorLocked(m_caption);   m_step_window.CaptionColorHover(m_caption);   m_step_window.BackColor(m_background);   m_step_window.FontSize(m_base_font_size);   m_step_window.Font(m_base_font); //--- Creating a form   if(!m_step_window.CreateWindow(m_chart_id,m_subwin,text,x,y))      return(false);   //---   return(true); } //+------------------------------------------------------------------+

不要忘了在 CreateGUI() 方法中添加以下内容:

//+------------------------------------------------------------------+ //| Creates the graphical interface of the program                   | //+------------------------------------------------------------------+ bool CProgram::CreateGUI(void) { //--- Step 1-3   if(!CreateStepWindow("Signal Monitor Step 1: Choose Symbols"))      return(false); //--- Finish the creation of GUI   CWndEvents::CompletedGUI();   return(true); } //+------------------------------------------------------------------+


赫兹股票交易软件:监视多币种的交易信号2---应用程序可视部分的实现的评论 (共 条)

分享到微博请遵守国家法律