,欢迎光临!
加入收藏设为首页在线咨询
您当前位置:网站首页 >> 投资软件 >> MT4/MT5 >> MT4-MQL4 编程入门(第11节 自定义指标函数)

MT4-MQL4 编程入门(第11节 自定义指标函数)

2010-12-27 14:06:40 来源:《008财富网》 浏览:8231

500人免费超级QQ群94337889(验证必填“008财富网”)

第十一节 自定义指标函数 [Custom Indicator Functions]

 

void IndicatorBuffers(int count) 设置自定义指标缓存数 :: 输入参数 count - 缓存数量 示例: #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Silver //---- indicator parameters extern int FastEMA=12; extern int SlowEMA=26; extern int SignalSMA=9; //---- indicator buffers double ind_buffer1[]; double ind_buffer2[]; double ind_buffer3[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 2 additional buffers are used for counting. IndicatorBuffers(3); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3); SetIndexDrawBegin(0,SignalSMA); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2); //---- 3 indicator buffers mapping SetIndexBuffer(0,ind_buffer1); SetIndexBuffer(1,ind_buffer2); SetIndexBuffer(2,ind_buffer3); //---- name for DataWindow and indicator subwindow label IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")"); //---- initialization done return(0); }

 

int IndicatorCounted() 返回缓存数量 示例: int start() { int limit; int counted_bars=IndicatorCounted(); //---- check for possible errors if(counted_bars<0) return(-1); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; //---- main loop for(int i=0; i { //---- ma_shift set to 0 because SetIndexShift called abowe ExtBlueBuffer=iMA(NULL,0,JawsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i); ExtRedBuffer=iMA(NULL,0,TeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i); ExtLimeBuffer=iMA(NULL,0,LipsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i); } //---- done return(0); }

 

void IndicatorDigits( int digits) 设置指标精确度 :: 输入参数 digits - 小数点后的小数位数 示例: #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Silver //---- indicator parameters extern int FastEMA=12; extern int SlowEMA=26; extern int SignalSMA=9; //---- indicator buffers double ind_buffer1[]; double ind_buffer2[]; double ind_buffer3[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 2 additional buffers are used for counting. IndicatorBuffers(3); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3); SetIndexDrawBegin(0,SignalSMA); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2); //---- 3 indicator buffers mapping SetIndexBuffer(0,ind_buffer1); SetIndexBuffer(1,ind_buffer2); SetIndexBuffer(2,ind_buffer3); //---- name for DataWindow and indicator subwindow label IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")"); //---- initialization done return(0); }

 

void IndicatorShortName( string name) 设置指标的简称 :: 输入参数 name - 新的简称 示例: #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Silver //---- indicator parameters extern int FastEMA=12; extern int SlowEMA=26; extern int SignalSMA=9; //---- indicator buffers double ind_buffer1[]; double ind_buffer2[]; double ind_buffer3[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 2 additional buffers are used for counting. IndicatorBuffers(3); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3); SetIndexDrawBegin(0,SignalSMA); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2); //---- 3 indicator buffers mapping SetIndexBuffer(0,ind_buffer1); SetIndexBuffer(1,ind_buffer2); SetIndexBuffer(2,ind_buffer3); //---- name for DataWindow and indicator subwindow label IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")"); //---- initialization done return(0); }

 

void SetIndexArrow( int index, int code) 在指标上设置一个箭头符号 :: 输入参数 index - 第几根指标线 0-7 code - 符号的编码,参照 Wingdings 字体 示例: SetIndexArrow(0, 217);

 

bool SetIndexBuffer( int index, double array[]) 设置指标线的缓存数组 :: 输入参数 index - 第几根指标线 0-7 array[] - 缓存的数组 示例: double ExtBufferSilver[]; int init() { SetIndexBuffer(0, ExtBufferSilver); // set buffer for first line // ... }

 

void SetIndexDrawBegin( int index, int begin) 设置划线的开始点 :: 输入参数 index - 第几根指标线 0-7 begin - 划线的开始点 示例: #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Silver //---- indicator parameters extern int FastEMA=12; extern int SlowEMA=26; extern int SignalSMA=9; //---- indicator buffers double ind_buffer1[]; double ind_buffer2[]; double ind_buffer3[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 2 additional buffers are used for counting. IndicatorBuffers(3); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3); SetIndexDrawBegin(0,SignalSMA); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2); //---- 3 indicator buffers mapping SetIndexBuffer(0,ind_buffer1); SetIndexBuffer(1,ind_buffer2); SetIndexBuffer(2,ind_buffer3); //---- name for DataWindow and indicator subwindow label IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")"); //---- initialization done return(0); }

 

void SetIndexEmptyValue( int index, double value) 设置划线的空值,空值不划在和出现在数据窗口 :: 输入参数 index - 第几根指标线 0-7 value - 新的空值 示例: SetIndexEmptyValue(6,0.0001);

 

 void SetIndexLabel( int index, string text) 设置指标线的名称 :: 输入参数 index - 第几根指标线 0-7 text - 线的名称,Null不会显示在数据窗口中 示例: //+------------------------------------------------------------------+ //| 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 SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_DOT); SetIndexBuffer(2,SpanA_Buffer); SetIndexDrawBegin(2,Kijun+a_begin-1); SetIndexShift(2,Kijun); //---- Up Kumo bounding line does not show in the DataWindow SetIndexLabel(2,NULL); SetIndexStyle(5,DRAW_LINE,STYLE_DOT); SetIndexBuffer(5,SpanA2_Buffer); SetIndexDrawBegin(5,Kijun+a_begin-1); SetIndexShift(5,Kijun); SetIndexLabel(5,"Senkou Span A"); //---- SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_DOT); SetIndexBuffer(3,SpanB_Buffer); SetIndexDrawBegin(3,Kijun+Senkou-1); SetIndexShift(3,Kijun); //---- Down Kumo bounding line does not show in the DataWindow SetIndexLabel(3,NULL); //---- SetIndexStyle(6,DRAW_LINE,STYLE_DOT); SetIndexBuffer(6,SpanB2_Buffer); SetIndexDrawBegin(6,Kijun+Senkou-1); SetIndexShift(6,Kijun); SetIndexLabel(6,"Senkou Span B"); //---- SetIndexStyle(4,DRAW_LINE); SetIndexBuffer(4,Chinkou_Buffer); SetIndexShift(4,-Kijun); SetIndexLabel(4,"Chinkou Span"); //---- return(0); }

 

void SetIndexShift( int index, int shift) 设置指标线的位移数 :: 输入参数 index - 第几根指标线 0-7 shift - 位移多少 示例: //+------------------------------------------------------------------+ //| Alligator initialization function | //+------------------------------------------------------------------+ int init() { //---- line shifts when drawing SetIndexShift(0,JawsShift); SetIndexShift(1,TeethShift); SetIndexShift(2,LipsShift); //---- first positions skipped when drawing SetIndexDrawBegin(0,JawsShift+JawsPeriod); SetIndexDrawBegin(1,TeethShift+TeethPeriod); SetIndexDrawBegin(2,LipsShift+LipsPeriod); //---- 3 indicator buffers mapping SetIndexBuffer(0,ExtBlueBuffer); SetIndexBuffer(1,ExtRedBuffer); SetIndexBuffer(2,ExtLimeBuffer); //---- drawing settings SetIndexStyle(0,DRAW_LINE); SetIndexStyle(1,DRAW_LINE); SetIndexStyle(2,DRAW_LINE); //---- index labels SetIndexLabel(0,"Gator Jaws"); SetIndexLabel(1,"Gator Teeth"); SetIndexLabel(2,"Gator Lips"); //---- initialization done return(0); }

 

void SetIndexStyle( int index, int type, int style=EMPTY, int width=EMPTY, color clr=CLR_NONE) 设置指标线的样式 :: 输入参数 index - 第几根指标线 0-7 type - 线形状的种类,详见线条种类 style - 划线的样式 width - 显得宽度(1,2,3,4,5) clr - 线的颜色 示例: SetIndexStyle(3, DRAW_LINE, EMPTY, 2, Red);

发表评论
网名:
评论:
验证:
共有0人对本文发表评论查看所有评论(网友评论仅供表达个人看法,并不表明本站同意其观点或证实其描述)
  • 联系邮箱:service#918008.com(请把#换成@) - 在线QQ:77446881
  • 外盘期货|外盘开户|恒指期货|恒指期货期权开户|外盘期货开户|外盘期权开户|新华富时A50指数开户|恒指开户|恒指配资|恒指软件|
  • 外盘配资|外盘期货配资|外汇软件|恒指期权开户|美原油软件|恒指喊单软件|期货配资|恒指分析软件
  • 苏ICP备17053501号 Copyright 2018, 版权所有 www.918008.com.
在线客服 客服软件
在线客服系统

免责申明: 本网站刊载的内容,部份搜集自网络,供大家免费浏览,所有相关权益归原作者所有,《008财富网》无意侵犯任何人、任何机构的权益!如果其中有您的文章不想被我们转载,请告诉我们!本网站刊载的所有内容,不构成投资建议,仅供参考,风险自负。任何投机交易在具体高度收益性的同时也具有高度风险性,通常只适合于能够承担相应风险的人士。鉴于存在的这些风险,您应该在完全了解所涉及交易的性质以及自身面临风险的程度后才进行交易。投资有风险,入市须谨慎!所有解释权归《008财富网》所有。