股票量化软件:扩充策略构建器功能
新功能实现阶段
我们来定义主要元素和实现方法,类似于
策略构建器初期时所做的工作。 在创建界面的 CreateGUI() 主要方法中,添加了两个方法。 我们看一下这些方法,以及针对现有方法的补充。//+------------------------------------------------------------------+ //| Creates the graphical interface of the program | //+------------------------------------------------------------------+ bool CProgram::CreateGUI(void) { //--- Create a panel if(!CreateWindow("Merrill Constructor")) return(false); //--- Create a dialog window if(!CreateDateSetting()) return(false); //--- Create a chart window if(!CreateGraphWindow()) return(false); //--- Create a load window if(!CreateLoading()) return(false); //--- Finish the creation of GUI CWndEvents::CompletedGUI(); return(true); }
我们观察主窗口创建方法 CreateWindow() 中的更改:为实现新的测试工具,添加了如图例 1 所示的新界面元素。赫兹股票量化交易软件
//---- CONSTRUCTOR tab .... //--- if(!CreateProfitType(int(0.35*(m_window[0].XSize()-150)-120),50+35*6+ygap)) return(false); if(!CreateLotType(int(0.6*(m_window[0].XSize()-150)-120),50+35*6+ygap)) return(false); if(!CreateBaseLotValue(int(0.85*(m_window[0].XSize()-150)-120),50+35*6+ygap)) return(false); if(!CreateInitialDeposit(int(0.35*(m_window[0].XSize()-150)-120),50+35*7+ygap)) return(false); //--- if(!CreateReportFrame(m_frame[2],int(0.35*(m_window[0].XSize()-150)-120),110+35*7+ygap)) return(false); //--- Graph opening button if(!CreateIconButton(int(0.35*(m_window[0].XSize()-150)-50),100+35*7+ygap)) return(false); //--- Report lines for(int i=0; i<11; i++) { if(i<5) if(!CreateTextLabel(m_report_text[i],int(0.37*(m_window[0].XSize()-150)-120),380+25*i+ygap,"",0)) return(false); if(i>=5 && i<9) if(!CreateTextLabel(m_report_text[i],int(0.63*(m_window[0].XSize()-150)-120),380+25*(i-5)+ygap,"",0)) return(false); if(i>=9) if(!CreateTextLabel(m_report_text[i],int(0.89*(m_window[0].XSize()-150)-120),380+25*(i-9)+ygap,"",0)) return(false); m_report_text[i].IsCenterText(false); m_report_text[i].FontSize(10); } ....
视觉更改仅在“构造器”选项卡中实现。 附件和上一篇文章中提供了完整的选项卡实现代码,而此处仅展示新的方法。 我们来逐一研究它们。 赫兹股票量化交易软件
CreateProfitType(). 该方法为测试中用到的利润类型创建一个下拉列表:存款币种,或点数。
//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CProgram::CreateProfitType(const int x_gap,const int y_gap) { //--- Pass the object to the panel m_profit_type.MainPointer(m_tabs1); //--- Attach to tab m_tabs1.AddToElementsArray(0,m_profit_type); //--- Array of the item values in the list view string pattern_names[2]= { "Pips","Currency" }; //--- Set properties before creation m_profit_type.XSize(200); m_profit_type.YSize(25); m_profit_type.ItemsTotal(2); m_profit_type.FontSize(12); m_profit_type.LabelColor(C'0,100,255'); m_profit_type.GetButtonPointer().FontSize(10); m_profit_type.GetButtonPointer().XGap(80); m_profit_type.GetButtonPointer().XSize(100); m_profit_type.GetButtonPointer().BackColor(clrAliceBlue); m_profit_type.GetListViewPointer().FontSize(10); m_profit_type.GetListViewPointer().YSize(44); //--- Save the item values in the combobox list view for(int i=0; i<2; i++) m_profit_type.SetValue(i,pattern_names[i]); //--- Get the list view pointer CListView *lv=m_profit_type.GetListViewPointer(); //--- Set the list view properties lv.LightsHover(true); m_profit_type.SelectItem(1); //--- Create a control if(!m_profit_type.CreateComboBox("Profit Type",x_gap,y_gap)) return(false); //--- Add the object to the common array of object groups CWndContainer::AddToElementsArray(0,m_profit_type); return(true); }
CreateLotType(). 该方法为手数类型创建一个下拉列表,常量,或依据余额。
//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CProgram::CreateLotType(const int x_gap,const int y_gap) { //--- Pass the object to the panel m_lot_type.MainPointer(m_tabs1); //--- Attach to tab m_tabs1.AddToElementsArray(0,m_lot_type); //--- Array of the item values in the list view string pattern_names[2]= { "Balance","Constant" }; //--- Set properties before creation m_lot_type.XSize(200); m_lot_type.YSize(25); m_lot_type.ItemsTotal(2); m_lot_type.FontSize(12); m_lot_type.LabelColor(C'0,100,255'); m_lot_type.GetButtonPointer().FontSize(10); m_lot_type.GetButtonPointer().XGap(65); m_lot_type.GetButtonPointer().XSize(100); m_lot_type.GetButtonPointer().BackColor(clrAliceBlue); m_lot_type.GetListViewPointer().FontSize(10); m_lot_type.GetListViewPointer().YSize(44); //--- Save the item values in the combobox list view for(int i=0; i<2; i++) m_lot_type.SetValue(i,pattern_names[i]); //--- Get the list view pointer CListView *lv=m_lot_type.GetListViewPointer(); //--- Set the list view properties lv.LightsHover(true); m_lot_type.SelectItem(1); //--- Create a control if(!m_lot_type.CreateComboBox("Lot Type",x_gap,y_gap)) return(false); //--- Add the object to the common array of object groups CWndContainer::AddToElementsArray(0,m_lot_type); return(true); }
CreateBaseLotValue(). 该方法为手数值创建输入字段。
/+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CProgram::CreateBaseLotValue(const int x_gap,const int y_gap) { //--- Save the pointer to the main control m_base_lot.MainPointer(m_tabs1); //--- Attach to tab m_tabs1.AddToElementsArray(0,m_base_lot); //--- Properties m_base_lot.XSize(210); m_base_lot.YSize(24); m_base_lot.LabelColor(C'0,100,255'); m_base_lot.FontSize(12); m_base_lot.MaxValue(SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX)); m_base_lot.MinValue(SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN)); m_base_lot.StepValue(SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP)); m_base_lot.SetDigits(2); m_base_lot.SpinEditMode(true); m_base_lot.GetTextBoxPointer().AutoSelectionMode(true); m_base_lot.GetTextBoxPointer().XGap(100); //--- Create a control if(!m_base_lot.CreateTextEdit("Base Lot Size",x_gap,y_gap)) return(false); m_base_lot.SetValue((string)SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN)); //--- Add the object to the common array of object groups CWndContainer::AddToElementsArray(0,m_base_lot); return(true); }
CreateInitialDeposit(). 在“利润 —币种”模式下进行测试时,为初始存款创建一个输入字段。
//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CProgram::CreateInitialDeposit(const int x_gap,const int y_gap) { //--- Save the pointer to the main control m_init_deposit.MainPointer(m_tabs1); //--- Attach to tab m_tabs1.AddToElementsArray(0,m_init_deposit); //--- Properties m_init_deposit.XSize(210); m_init_deposit.YSize(24); m_init_deposit.LabelColor(C'0,100,255'); m_init_deposit.FontSize(12); m_init_deposit.MinValue(10); m_init_deposit.SetDigits(2); m_init_deposit.GetTextBoxPointer().AutoSelectionMode(true); m_init_deposit.GetTextBoxPointer().XGap(125); //--- Create a control if(!m_init_deposit.CreateTextEdit("Initial Deposit",x_gap,y_gap)) return(false); m_init_deposit.SetValue((string)1000); //--- Add the object to the common array of object groups CWndContainer::AddToElementsArray(0,m_init_deposit); return(true); }
CreateIconButton(). 创建一个按钮,点击后会打开图表窗口。
//+------------------------------------------------------------------+ //| Creates a button with an image | //+------------------------------------------------------------------+ #resource "\\Images\\EasyAndFastGUI\\Icons\\bmp16\\bar_chart.bmp" #resource "\\Images\\EasyAndFastGUI\\Icons\\bmp16\\bar_chart_gray.bmp" //--- bool CProgram::CreateIconButton(const int x_gap,const int y_gap) { //--- Save the pointer to the main control m_graph_button.MainPointer(m_tabs1); //--- Attach to tab m_tabs1.AddToElementsArray(0,m_graph_button); //--- Properties m_graph_button.XSize(150); m_graph_button.YSize(22); m_graph_button.FontSize(11); m_graph_button.IconXGap(3); m_graph_button.IconYGap(3); m_graph_button.IsHighlighted(false); m_graph_button.IsCenterText(true); m_graph_button.IconFile("Images\\EasyAndFastGUI\\Icons\\bmp16\\bar_chart.bmp"); m_graph_button.IconFileLocked("Images\\EasyAndFastGUI\\Icons\\bmp16\\bar_chart_gray.bmp"); m_graph_button.IconFilePressed("Images\\EasyAndFastGUI\\Icons\\bmp16\\bar_chart.bmp"); m_graph_button.IconFilePressedLocked("Images\\EasyAndFastGUI\\Icons\\bmp16\\bar_chart_gray.bmp"); m_graph_button.BorderColor(C'0,100,255'); m_graph_button.BackColor(clrAliceBlue); //--- Create a control if(!m_graph_button.CreateButton("",x_gap,y_gap)) return(false); //--- Add the element pointer to the data base CWndContainer::AddToElementsArray(0,m_graph_button); return(true); }
在 CreateWindow() 中修改了报告特征的输出结构。 它追加并实现为三列,取代了原先的两列。 所有这些就是在主窗口创建方法 CreateWindow() 中进行的修改。赫兹股票量化交易软件
接下来,我们继续实现图表窗口和报表图形的方法 — CreateGraphWindow()。
//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CProgram::CreateGraphWindow(void) { //--- Add the pointer to the window array CWndContainer::AddWindow(m_window[2]); //--- Properties m_window[2].XSize(750); m_window[2].YSize(450); m_window[2].FontSize(9); m_window[2].WindowType(W_DIALOG); m_window[2].IsMovable(true); //--- Create the form if(!m_window[2].CreateWindow(m_chart_id,m_subwin,"",75,75)) return(false); //--- Charts if(!CreateGraph(22,22)) return(false); //--- return(true); }
创建方法很小巧。 请注意其中包含的 CreateGraph() 方法。赫兹股票量化交易软件
//+------------------------------------------------------------------+ //| Create a chart | //+------------------------------------------------------------------+ bool CProgram::CreateGraph(const int x_gap,const int y_gap) { //--- Save the pointer to the main control m_graph1.MainPointer(m_window[2]); //--- Properties m_graph1.AutoXResizeMode(true); m_graph1.AutoYResizeMode(true); m_graph1.AutoXResizeRightOffset(10); m_graph1.AutoYResizeBottomOffset(10); //--- Create element if(!m_graph1.CreateGraph(x_gap,y_gap)) return(false); //--- Chart properties CGraphic *graph=m_graph1.GetGraphicPointer(); graph.BackgroundColor(::ColorToARGB(clrWhiteSmoke)); graph.XAxis().Min(0); graph.BackgroundMainSize(20); graph.HistoryNameSize(0); graph.HistorySymbolSize(0); graph.HistoryNameWidth(0); //--- Add the element pointer to the data base CWndContainer::AddToElementsArray(2,m_graph1); return(true); }
它创建一个空图形,并设置其视觉特征。 图形数据将在以后添加。
在主要的 CreateGUI() 中的另一个方法是 CreateLoading(),其会创建加载窗口。 它以指标形式负责加载应用程序、更改语言设置、以及处理数据和测试。赫兹股票量化交易软件
//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #resource "\\Images\\EasyAndFastGUI\\Icons\\bmp16\\sandglass.bmp" bool CProgram::CreateLoading(void) { //--- Add the pointer to the window array CWndContainer::AddWindow(m_window[3]); //--- Properties m_window[3].XSize(100); m_window[3].YSize(50); m_window[3].LabelYGap(50/2-16/2); m_window[3].IconYGap(50/2-16/2); m_window[3].FontSize(9); m_window[3].WindowType(W_DIALOG); m_window[3].IsMovable(false); m_window[3].CloseButtonIsUsed(false); m_window[3].CaptionColorLocked(C'0,130,225'); m_window[3].LabelColor(clrWhite); m_window[3].LabelColorLocked(clrWhite); m_window[3].CaptionHeight(51); m_window[3].IconFile("Images\\EasyAndFastGUI\\Icons\\bmp16\\sandglass.bmp"); m_window[3].IconFileLocked("Images\\EasyAndFastGUI\\Icons\\bmp16\\sandglass.bmp"); m_window[3].IconFilePressed("Images\\EasyAndFastGUI\\Icons\\bmp16\\sandglass.bmp"); m_window[3].IconFilePressedLocked("Images\\EasyAndFastGUI\\Icons\\bmp16\\sandglass.bmp"); int x=int(m_window[0].XSize()/2); int y=int(m_window[0].YSize()/2); //--- Create the form if(!m_window[3].CreateWindow(m_chart_id,m_subwin,"Working...",x,y)) return(false); return(true); }
我们已研究了策略构建器的视觉元素。 我们进入测试算法,并观察如何利用新的视觉控件在其中显示信息。