新手入门教程 发表于 2026-1-26 16:01:53

MQL4自定义外汇MT4指标编写相关函数(二)

MQL4自定义外汇MT4指标编写相关函数(二)
本组函数用于设计和编写自定义外汇MT4指标。
这些函数不能用在智能交易和脚本中。
[*]IndicatorBuffers() – 外汇MT4指标数据缓冲区[*]IndicatorCounted() – 外汇MT4指标计数[*]IndicatorDigits() – 设置外汇MT4指标精度[*]IndicatorShortName() – 设置外汇MT4指标简称[*]SetIndexArrow() – 设置外汇MT4指标箭头符号[*]SetIndexBuffer() – 设置外汇MT4指标缓冲区位置[*]SetIndexDrawBegin() – 设置外汇MT4指标线起始位置[*]SetIndexEmptyValue() – 设置图表画线空值[*]SetIndexLabel() – 设置外汇MT4指标线标签[*]SetIndexShift() – 设置外汇MT4指标线偏移值[*]SetIndexStyle() – 设置外汇MT4指标线样式[*]SetLevelStyle() – 设置水平线样式[*]SetLevelValue() – 设置水平线值

SetIndexDrawBegin() – 设置外汇MT4指标线起始位置void SetIndexDrawBegin(int index, int begin)设置开始绘制外汇MT4指标线的柱体(外汇MT4指标线从什么位置开始绘制)。外汇MT4指标线从左边绘制到右边,已给出的柱子左边的数组值不会显示在图表或数据窗口中。设置0作为默认值,所有数据将被绘出。
参数:
index - 外汇MT4指标线。必须在0至7之间。 begin - 开始绘制外汇MT4指标线的柱体编号。 示例:
int init(){//----使用2个额外的缓冲区用于计算。   IndicatorBuffers(3);//----画线设置   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);   SetIndexDrawBegin(0,SignalSMA);   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);//---- 设置 3 个外汇MT4指标缓冲区位置   SetIndexBuffer(0,ind_buffer1);   SetIndexBuffer(1,ind_buffer2);   SetIndexBuffer(2,ind_buffer3);//---- DataWindow 和自定义子窗口标签名称   IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");//---- 初始化完成   return(0);}SetIndexEmptyValue() – 设置图表画线空值void SetIndexEmptyValue(int index, double value)设置图表画线空值。设置的值不绘出或不显示在数据窗口。默认值为 EMPTY VALUE。
参数:
index - 外汇MT4指标线。必须在0至7之间。 value - 设置的"空值"。 示例:
int init(){//----设置 2 个外汇MT4指标缓冲区位置    SetIndexBuffer(0,ExtUppperBuffer);    SetIndexBuffer(1,ExtLowerBuffer);//---- 画出参数设置    SetIndexStyle(0,DRAW_ARROW);    SetIndexArrow(0,217);    SetIndexStyle(1,DRAW_ARROW);    SetIndexArrow(1,218);//---- 值为 0 不显示    SetIndexEmptyValue(0,0.0);    SetIndexEmptyValue(1,0.0);//----   SetIndexLabel(0,"Fractal Up");    SetIndexLabel(1,"Fractal Down");//---- 初始化完成   return(0);}
SetIndexLabel() – 设置外汇MT4指标线标签void SetIndexLabel(int index, string text)设置在数据窗口和快速提示中显示的外汇MT4指标线说明。
参数:
index - 外汇MT4指标线。必须在0至7之间。 text - 标签文本。NULL表示外汇MT4指标值在数据窗口中不显示。 示例:
//+------------------------------------------------------------------+//| Ichimoku Kinko Hyo initialization function                     |//+------------------------------------------------------------------+int init(){//----   SetIndexStyle(0,DRAW_LINE);   SetIndexBuffer(0,Tenkan_Buffer);   SetIndexDrawBegin(0,Tenkan-1);   SetIndexLabel(0,"Tenkan Sen");//----   SetIndexStyle(1,DRAW_LINE);   SetIndexBuffer(1,Kijun_Buffer);   SetIndexDrawBegin(1,Kijun-1);   SetIndexLabel(1,"Kijun Sen");//----   a_begin=Kijun; if(a_begin设置在数据窗口和快速提示中显示的外汇MT4指标线说明。
参数:
index - 外汇MT4指标线。必须在0至7之间。 shift - 柱体(K线)偏移值。 示例:
//+------------------------------------------------------------------+//| Alligator initialization function                              |//+------------------------------------------------------------------+int init(){//----当画线时外汇MT4指标线的偏移   SetIndexShift(0,JawsShift);   SetIndexShift(1,TeethShift);   SetIndexShift(2,LipsShift);//---- 当画线时外汇MT4指标线跳过的位置   SetIndexDrawBegin(0,JawsShift+JawsPeriod);   SetIndexDrawBegin(1,TeethShift+TeethPeriod);   SetIndexDrawBegin(2,LipsShift+LipsPeriod);//---- 设置 3 个外汇MT4指标缓冲区位置   SetIndexBuffer(0,ExtBlueBuffer);   SetIndexBuffer(1,ExtRedBuffer);   SetIndexBuffer(2,ExtLimeBuffer);//---- 画出设置   SetIndexStyle(0,DRAW_LINE);   SetIndexStyle(1,DRAW_LINE);   SetIndexStyle(2,DRAW_LINE);//---- 外汇MT4指标线标签文本   SetIndexLabel(0,"Gator Jaws");   SetIndexLabel(1,"Gator Teeth");   SetIndexLabel(2,"Gator Lips");//---- 初始化完成   return(0);}SetIndexStyle() – 设置外汇MT4指标线样式void SetIndexStyle(int index, int type, void style, void width, void clr)为指定的外汇MT4指标线设置新类型、样式、宽度和颜色。
参数:
index - 外汇MT4指标线。必须在0至7之间。 type - 形状样式,可以是 划线形状样式列表 中任意一个。 style - 线型。可以应用一个像素的粗线,可以是 划线形状样式列表 其中一个。EMPTY值表示线型不变。width - 线宽。有效值是1,2,3,4,5。EMPTY值表示线宽不变。clr - 线的颜色。省略本参数表示颜色将保持不变示例:
SetIndexStyle(3, DRAW_LINE, EMPTY, 2, Red);SetLevelStyle() – 设置水平线样式void SetLevelStyle(int draw_style, int line_width, void clr)本函数设置输出到独立窗口的外汇MT4指标水平线的样式、宽度和颜色。
参数:
draw_style - 形状样式,可以是 划线形状样式列表 中任意一个。 line_width - 线宽。有效值是1,2,3,4,5。EMPTY值表示线宽不变。clr - 线的颜色。空值CLR_NONE表示颜色不变。示例:
//---- 红色单线显示水平   SetLevelStyle(STYLE_SOLID,2,Red)SetLevelValue() – 设置水平线值void SetLevelValue(int level, double value)本函数设置在独立窗口输出的水平外汇MT4指标线的值。
参数:
level - 水平线编号,0到31。 value - 给出的水平线值。clr - 线的颜色。空值CLR_NONE表示颜色不变。示例:
SetLevelValue(1,3.14);
大家在看了小编以上对"MQL4自定义外汇MT4指标编写相关函数(二)"的介绍后应该都清楚了吧,希望对大家做单有所帮助。如果大家还想要下载更多有关"MQL4自定义外汇MT4指标编写相关函数(二)"的相关EA源码,敬请关注汇探网下载。我们会持续更新交易系统,EA源码。
页: [1]
查看完整版本: MQL4自定义外汇MT4指标编写相关函数(二)