加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

【MQL4编程模版】4  界面函数

(2016-05-19 13:17:11)
标签:

ea编程

mql4教程

模板

指标编程

ea

分类: MQL4教程

友好界面是优良客户体验的基础,打造界面函数也是为程序员提供过程调试的必备模块。

实践中发现,界面友好是必须的,但程序代码简洁也很有必要,为了缩减编码量和简洁的源码书写,就定制了一批常用的界面函数。

MT4采用图形对象的方式实现各种文字、图形、图片、按钮的显示。每一个对象都有其对应的属性。用ObjectCreate命令创建对象,用ObjectSet设置修改对象属性。使用界面函数后,在编写源码时就不需要翻来覆去写ObjectCreate、ObjectSet这类命令了。

对象属性包括但不限于内容、锚点(屏幕定位)、大小、类型、颜色等等。

图形对象的输出定位(锚点)坐标有两种方式,一是按像素,二是按时间价格。在实际调用中需要特别注意。

函数声明文件egUIFunctions.mqh保存在\MQL4\Include\EasyGo中。

函数库文件egUIFunctions.ex4保存在\MQL4\ Include \EasyGo中。

用MetaEditor打开egUIFunctions.mqh,能看到详细的调用说明:

http://s7/mw690/001WpylDgy71OqbRKBw96&690 界面函数" TITLE="【MQL4编程模版】4  界面函数" />

界面函数参数大部分采用常数(const)做预定义,就形成了默认参数,如果不需要变化写命令时无需输入。

主程序模版源码中有丰富的调用对象输出范例,例如仪表盘、一键清仓按钮等,本文不再就每一个函数举例。本次汇总了16个常用界面函数,逐一描述如下。

4.1     输出箭头到图表

输出坐标为“时间-价格”。

 

bool    egArrowOut(const   bool                 isout=true,             //允许输出

                   const   long                 chart_ID=0,             //主图ID

                   const   string               name="Arrow",          //对象名称

                   const   int                  sub_window=0,          //副图编号

                   const   datetime             time=0,          //标注点k线时间

                   const   double               price=0,          //标注点k线价格

                   const   uchar                arrow_code=252,        //箭头代码

                   const   ENUM_ARROW_ANCHOR  anchor=ANCHOR_BOTTOM, // 锚点

                   const   color                clr=clrRed,             //箭头颜色

                   const   ENUM_LINE_STYLE      style=STYLE_SOLID,   //显示类新型

                   const   int                  width=3,              //箭头尺寸

                   const   bool                 back=false,           //设置为背景

                   const   bool                 selection=false,        //高亮移动

                   const   bool                 hidden=true,    //列表中隐藏对象名

                   const   long                 z_order=0   // priority for mouse click

                  );

4.2     输出Bit图片到图表

输出坐标为“时间-价格”。

 

bool    egBitmapOut(const   bool              isout=true,               //允许输出

                    const   long              chart_ID=0,               //主图ID

                    const   string            name="Bitmap",            //对象名称

                    const   int               sub_window=0,            //副图编号

                            datetime          time=0,                 //锚点时间

                            double            price=0,                //锚点价格

                    const   string            file="",                 //图片文件名

                    const   int               width=10,                //对象宽度

                    const   int               height=10,                //对象高度

                    const   int               x_offset=0,               // X轴偏移

                    const   int               y_offset=0,               //Y轴偏移

                    const   color             clr=clrRed,               //背景颜色

                    const   ENUM_LINE_STYLE   style=STYLE_SOLID,        //线型

                    const   int               point_width=1,            //移动尺寸

                    const   bool              back=false,             //设置为背景

                    const   bool              selection=false,          //高亮移动

                    const   bool              hidden=true,      //列表中隐藏对象名

                    const   long              z_order=0     // priority for mouse click

                   );

4.3     输出Bit图片到图表(像素)

输出坐标为“x像素-y像素”。

 

bool    egBitmapLableOut(const   bool              isout=true,               //允许输出

                         const   long              chart_ID=0,               //主图ID

                         const   string            name="BmpLabel",          //对象名称

                         const   int               sub_window=0,             //副图编号

                         const   int               x=0,                      //x坐标

                         const   int               y=0,                      //y坐标

                         const   string            file_on="",               //On模式图片名

                         const   string            file_off="",              //Off模式图片名

                         const   int               width=10,                 //对象宽度

                         const   int               height=10,                //对象高度

                         const   int               x_offset=0,               //X轴偏移

                         const   int               y_offset=0,               //Y轴偏移

                         const   bool              state=false,              //按下/松开

                         const   ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, //锚点位置

                         const   ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, //锚类型

                         const   color             clr=clrRed,               //背景颜色

                         const   ENUM_LINE_STYLE   style=STYLE_SOLID,        //线型

                         const   int               point_width=1,            //移动尺寸

                         const   bool              back=false,               //设置为背景

                         const   bool              selection=false,          //高亮移动

                         const   bool              hidden=true,              //列表中隐藏对象名

                         const   long              z_order=0             //priority for mouse click

                   );

4.4     输出按钮到图表

输出坐标为“x像素-y像素”。

 

bool    egButtonOut(const   bool              isout=true,               //允许输出

                    const   long              chart_ID=0,               //主图ID

                    const   string            name="Button",            //对象名称

                    const   int               sub_window=0,             //副图编号

                    const   int               x=0,                      //x坐标

                    const   int               y=0,                      //y坐标

                    const   int               width=50,                 //按钮宽度

                    const   int               height=18,                //按钮高度

                    const   ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, //锚点

                    const   string            text="Button",            //按钮文字

                    const   string            font="Arial",             //文字字体

                    const   int               font_size=10,             //文字尺寸

                    const   color             clr=clrBlack,             //文字颜色

                    const   color             back_clr=clrGray,         //背景色

                    const   color             border_clr=clrNONE,       //边框色

                    const   bool              state=false,              //按下状态

                    const   bool              back=false,               //设置为背景

                    const   bool              selection=false,          //高亮移动

                    const   bool              hidden=true,              //列表中隐藏对象名

                    const   long              z_order=0                 // priority for mouse click

                   );

4.5     输出信息到图表

与系统命令Comment一样,结果输出在主图左上角。不同的是,该命令增加了是否显示的参数,执行后会返回布尔值,便于在if命令中执行。编程过程中会输出大量的调试信息,如果将“允许输出”项用全程变量定义,在程序调试完毕后,只需修改这一个变量值,即可实现禁止所有信息输出。用法参见【MQL4编程模版】1  快速编码范例。调用语法如下:

 

bool    egCommentOut(const    bool    isout=true,   //允许输出

                     const    string  text="text"   //输出信息

                    );

4.6     k线

这是为在副图(主图)画定制k线而准备的函数。MT4可以在离线图表画定制k线,但在常规主图或者副图(指标图)区域内画k线,只能用对象的方式实现。

 

void egDrawCandle(const long        myChartID,      //主图ID

                  const int         myWindow,       //副图编号

                  const string      object_name1,   //实体对象名称

                  const string      object_name2,   //引线对象名称

                  const datetime    &time,          //时间

                  const double      &open_price,    //开盘价

                  const double      &high_price,    //最高价

                  const double      &low_price,     //最低价

                  const double      &close_price,   //收盘价

                  const color       candle_color,   //k线颜色

                  const int         body_width=3,   //实体宽度

                  const int         wick_width=1    //引线宽度

                 );

4.7     输出可编辑文字到图表

输出坐标为“x像素-y像素”。

 

bool    egEditOut(const     bool             isout=true,               //允许输出

                  const     long             chart_ID=0,               //主图ID

                  const     string           name="Edit",              //对象名称

                  const     int              sub_window=0,             //副图编号

                  const     int              x=0,                      //x坐标

                  const     int              y=0,                      //y坐标

                  const     int              width=50,                 //编辑框宽度

                  const     int              height=18,                //编辑框高度

                  const     string           text="Text",              //编辑内容

                  const     string           font="Arial",             //字体

                  const     int              font_size=10,             //字号

                  const     ENUM_ALIGN_MODE  align=ALIGN_CENTER,       //对齐方式

                  const     bool             read_only=false,          //禁止编辑

                  const     ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, //锚点

                  const     color            clr=clrBlack,             //字色

                  const     color            back_clr=clrWhite,        //背景色

                  const     color            border_clr=clrNONE,       //边框色

                  const     bool             back=false,               //设置为背景

                  const     bool             selection=false,          //高亮移动

                  const     bool             hidden=true,              //列表中隐藏对象名

                  const     long             z_order=0                 // priority for mouse click

                 );

4.8     输出水平线到图表

在主图输出水平线。副图水平线则可以在指标中预定义。

 

bool    egHLineOut(const    bool            isout=true,         //允许输出

                   const    long            chart_ID=0,         //主图ID

                   const    string          name="HLine",       //对象名称

                   const    int             sub_window=0,       //副图编号

                   const    double          price=0,            //线价格

                   const    color           clr=clrRed,         //线色

                   const    ENUM_LINE_STYLE style=STYLE_SOLID,  //线型

                   const    int             width=1,            //线宽

                   const    bool            back=false,         //设置为背景

                   const    bool            selection=true,     //高亮移动

                   const    bool            hidden=true,        //列表中隐藏对象名

                   const    long            z_order=0           // priority for mouse click

                 );

4.9     输出标签到图表

输出坐标为“x像素-y像素”。

 

bool    egLableOut(const    bool                isout=true,               //允许输出

                   const    string              text="Label",             //输出内容

                   const    string              name="Label",             //对象名称

                   const    int                 font_size=10,             //字体尺寸

                   const    color               clr=clrRed,               //字体颜色

                   const    long                chart_ID=0,               //主图ID

                   const    int                 sub_window=0,             //副图编号

                   const    ENUM_BASE_CORNER    corner=CORNER_LEFT_UPPER, //锚点

                   const    int                 x=0,                      //x坐标

                   const    int                 y=0,                      //y坐标

                   const    string              font="Arial",             //字体类型

                   const    double              angle=0.0,                //字体角度

                   const    ENUM_ANCHOR_POINT   anchor=ANCHOR_LEFT_UPPER, //原始坐标

                   const    bool                back=false,               //设置为背景

                   const    bool                selection=false,          //高亮移动

                   const    bool                hidden=false,             //列表中隐藏对象名

                   const    long                z_order=0       //priority for mouse click

                  );

4.10        删除关键字对象

在EA或者指标中如果用到大量对象,那么在程序卸载的时候,需要打扫干净这些对象元素,就可以用这条命令。

 

void egObjectsDeleteByKeyword(const  long   chart_ID=0, //主图ID

                                     string keyword=""

                             );

4.11        对象颜色

屏幕显示数据时常常需要变换颜色以表示盈亏,本命令就用来针对正负或者0的数据返回不同的颜色。

 

color egObjectColor(double myInput  //数值

                   );

4.12        输出信息到日志

与系统命令Print一样,结果输出在EA日志中。不同的是,该命令增加了是否显示的参数,执行后会返回布尔值,便于在if命令中执行。编程过程中会输出大量的调试信息,如果将“允许输出”项用全程变量定义,在程序调试完毕后,只需修改这一个变量值,即可实现禁止所有信息输出。

 

bool    egPrintOut(const    bool    isout=true,    //允许输出

                   const    string  text="text"    //输出信息

                  );

4.13        输出矩形到图表

输出坐标为“x像素-y像素”。本模版用来作为背景框,详见第一章范例。

 

bool    egRectangleOut(const    bool                 isout=true,                 //允许输出

                       const    long                 chart_ID=0,                 //主图ID

                       const    string               name="RectLabel",           //对象名称

                       const    int                  sub_window=0,               //副图编号

                       const    int                  x=0,                        //x坐标

                       const    int                  y=0,                        //y坐标

                       const    int                  width=50,                   //矩形宽度

                       const    int                  height=18,                  //矩形高度

                       const    color                back_clr=clrGray,           //背景色

                       const    ENUM_BORDER_TYPE     border=BORDER_SUNKEN,      //矩形效果

                       const    ENUM_BASE_CORNER     corner=CORNER_LEFT_UPPER,   //锚点

                       const    color                clr=clrRed,                 //边框颜色

                       const    ENUM_LINE_STYLE      style=STYLE_SOLID,          //边框类型

                       const    int                  line_width=1,               //边框宽度

                       const    bool                 back=false,                 //设置为背景

                       const    bool                 selection=false,            //高亮移动

                       const    bool                 hidden=true,            //列表中隐藏对象名

                       const    long                 z_order=0           // priority for mouse click

                      );

4.14        输出标注到图表

标注可显示在主图或者副图中。一旦成功标注,将随着图表移动。输出坐标为“时间-价格”。

 

bool    egTextOut(const    bool                isout=true,                 //允许输出

                  const    string              text="Text",                //输出内容

                  const    string              name="Text",                //对象名称

                  const    int                 font_size=8,                //字体尺寸

                  const    color               clr=clrGreen,               //字体颜色

                  const    long                chart_ID=0,                 //主图ID

                  const    int                 sub_window=0,               //附图编号

                  const    datetime            time=0,                     //标注点时间

                  const    double              price=0,                    //标注点价格

                  const    string              font="Arial",               //字体类型

                  const    double              angle=0.0,                  //字体角度

                  const    ENUM_ANCHOR_POINT   anchor=ANCHOR_LEFT_UPPER,   //原始坐标

                  const    bool                back=false,                 //设置为背景

                  const    bool                selection=false,            //高亮移动

                  const    bool                hidden=false,               //列表中隐藏对象名

                  const    long                z_order=0                   //priority for mouse click

                 );

4.15        输出线段到图表

输出坐标为“时间-价格”。

 

bool    egTrendOut(const    bool            isout=true,         //允许输出

                   const    long            chart_ID=0,         //主图ID

                   const    string          name="TrendLine",   //对象名称

                   const    int             sub_window=0,       //副图编号

                            datetime        time1=0,            //1点时间

                            double          price1=0,           //1点价格

                            datetime        time2=0,            //2点时间

                            double          price2=0,           //2点价格

                   const    color           clr=clrRed,         //线色

                   const    ENUM_LINE_STYLE style=STYLE_SOLID,  //线型

                   const    int             width=1,            //线宽

                   const    bool            back=true,          //设置为背景

                   const    bool            selection=false,    //高亮移动

                   const    bool            ray_right=false,    //true为射线

                   const    bool            hidden=true,        //列表中隐藏对象名

                   const    long            z_order=0           //priority for mouse click

                 );

4.16        输出垂直线到图表

输出坐标为“时间”。

 

 

bool    egVLineOut(const    bool            isout=true,         //允许输出

                   const    long            chart_ID=0,         //主图ID

                   const    string          name="VLine",       //对象名称

                   const    int             sub_window=0,       //副图编号

                   const    datetime        time=0,             //线时间

                   const    color           clr=clrRed,         //线色

                   const    ENUM_LINE_STYLE style=STYLE_SOLID,  //线型

                   const    int             width=1,            //线宽

                   const    bool            back=false,         //设置为背景

                   const    bool            selection=true,     //高亮移动

                   const    bool            hidden=true,        //列表中隐藏对象名

                   const    long            z_order=0           // priority for mouse click

                 );


<<前一篇:【MQL4编程模版】3  主程序

>>后一篇:【MQL4编程模版】5  控制函数

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有