[求助]老师能帮忙吧MT5的这个MACD改成WH7的吗 [文华财经]
-
咨询内容:
取指标数据
通过获取系统自带的MACD指标数据,进行变色重建,实现起来非常方便,可以直接取到需要的数据。需要先建立指标句柄,再用CopyBuffer()函数取数据。
intmacd_handle =0;macd_handle =iMACD(Symbol(),Period(),12,26,9,PRICE_CLOSE);//取指标数据CopyBuffer(macd_handle,0,0,rates_total,macdBuffer);CopyBuffer(macd_handle,1,0,rates_total,signalBuffer);
填充缓冲区
生成自定义指标,其实就是填充缓冲区的过程,将指标线、柱图、填充区、箭头缓冲区数据进行赋值,就可以实现我们需要的效果。
在填充箭头缓冲区时,需要更改箭头的样式,并且只是在双线出现金叉、死叉时才赋值,所以还需要将0值位置设为空绘制区PLOT_EMPTY_VALUE。
PlotIndexSetInteger(5,PLOT_ARROW,225); PlotIndexSetInteger(6,PLOT_ARROW,226); PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,0);
需要注意的是,采用循环遍历赋值的方式,循环变量起始值在初始加载指标时为1,加载之后为prev_calculated - 1,这样在循环体内,即加载了所有历史数据,也实时更新最新数据,不会重新计算所有历史值。
//给缓冲区赋值,起始值intstart =1;if(prev_calculated >1) { start = prev_calculated -1; }for(inti = start; i < rates_total; i++) {//循环体 }
实现源码
#propertycopyright"-> wentxiong"#propertylink "https://www.mql5.com/zh/users/xiongsir/seller"#propertyversion "1.00"#propertyindicator_separate_window#propertyindicator_buffers12#propertyindicator_plots 7//--- plot macd#propertyindicator_label1 "macd"#propertyindicator_type1 DRAW_LINE#propertyindicator_color1 clrRed#propertyindicator_style1 STYLE_SOLID#propertyindicator_width1 1//--- plot signal#propertyindicator_label2 "signal"#propertyindicator_type2 DRAW_LINE#propertyindicator_color2 clrBlue#propertyindicator_style2 STYLE_SOLID#propertyindicator_width2 1//--- plot upper#propertyindicator_label3 "upper"#propertyindicator_type3 DRAW_COLOR_HISTOGRAM#propertyindicator_color3 clrPurple,clrDimGray#propertyindicator_style3 STYLE_SOLID#propertyindicator_width3 2//--- plot down#propertyindicator_label4 "down"#propertyindicator_type4 DRAW_COLOR_HISTOGRAM#propertyindicator_color4 clrPurple,clrDimGray#propertyindicator_style4 STYLE_SOLID#propertyindicator_width4 2//--- plot fill#propertyindicator_label5 "fill"#propertyindicator_type5 DRAW_FILLING#propertyindicator_color5 clrRed,clrBlue#propertyindicator_style5 STYLE_SOLID#propertyindicator_width5 1//--- plot arrow#propertyindicator_label6 "arrow"#propertyindicator_type6 DRAW_COLOR_ARROW#propertyindicator_color6 clrRed,clrBlue#propertyindicator_style6 STYLE_SOLID#propertyindicator_width6 1#propertyindicator_label7 "arrow2"#propertyindicator_type7 DRAW_COLOR_ARROW#propertyindicator_color7 clrRed,clrBlue#propertyindicator_style7 STYLE_SOLID#propertyindicator_width7 1//--- indicator buffersdouble macdBuffer[];double signalBuffer[];double upperBuffer[];double upperColors[];double downBuffer[];double downColors[];double fillBuffer1[];double fillBuffer2[];double arrowBuffer[];double arrowColors[];double arrow2Buffer[];double arrow2Colors[];intmacd_handle =0;//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit() {//--- indicator buffers mapping SetIndexBuffer(0,macdBuffer,INDICATOR_DATA); SetIndexBuffer(1,signalBuffer,INDICATOR_DATA); SetIndexBuffer(2,upperBuffer,INDICATOR_DATA); SetIndexBuffer(3,upperColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(4,downBuffer,INDICATOR_DATA); SetIndexBuffer(5,downColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(6,fillBuffer1,INDICATOR_DATA); SetIndexBuffer(7,fillBuffer2,INDICATOR_DATA); SetIndexBuffer(8,arrowBuffer,INDICATOR_DATA); SetIndexBuffer(9,arrowColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(10,arrow2Buffer,INDICATOR_DATA); SetIndexBuffer(11,arrow2Colors,INDICATOR_COLOR_INDEX);//--- setting a code from the Wingdings charset as the property of PLOT_ARROW PlotIndexSetInteger(5,PLOT_ARROW,225); PlotIndexSetInteger(6,PLOT_ARROW,226); PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,0);//指标handle macd_handle =iMACD(Symbol(),Period(),12,26,9,PRICE_CLOSE);//--- return(INIT_SUCCEEDED); }//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constintrates_total, constintprev_calculated, constdatetime&time[], constdouble&open[], constdouble&high[], constdouble&low[], constdouble&close[], constlong&tick_volume[], constlong&volume[], constint&spread[]) {//--- CopyBuffer(macd_handle,0,0,rates_total,macdBuffer); CopyBuffer(macd_handle,1,0,rates_total,signalBuffer); intstart =1; if(prev_calculated >1) { start = prev_calculated -1; } for(inti = start; i < rates_total; i++) { if(macdBuffer[i] > signalBuffer[i]) { upperBuffer[i] = macdBuffer[i] - signalBuffer[i]; } else { downBuffer[i] = macdBuffer[i] - signalBuffer[i]; } if(upperBuffer[i] > upperBuffer[i -1]) { upperColors[i] =0; } else { upperColors[i] =1; } if(downBuffer[i] < downBuffer[i -1]) { downColors[i] =0; } else { downColors[i] =1; } fillBuffer1[i] = macdBuffer[i]; fillBuffer2[i] = signalBuffer[i]; if(macdBuffer[i] > signalBuffer[i] && macdBuffer[i -1] < signalBuffer[i -1]) { arrowBuffer[i -1] = macdBuffer[i] -0.0005; arrowColors[i -1] =0; } if(macdBuffer[i] < signalBuffer[i] && macdBuffer[i -1] > signalBuffer[i -1]) { arrow2Buffer[i -1] = macdBuffer[i] +0.0003; arrow2Colors[i -1] =1; } }//--- return value of prev_calculated for next call return(rates_total); }//+------------------------------------------------------------------+来源:程序化99
-
文华技术人员:
1楼指标注释部分与执行部分混在一起了
您重新上传一下 正常格式的源码,我们分析看下。
另外1楼图片没有上传成功,您可以在如图位置上传图片
MT4指标和文华指标言语相差过大,需要联系相关同事来进行修改。
文件名:qq截图20210803154610.jpg
有思路,想编写各种指标公式,交易模型,选股公式,还原公式的朋友
可联系技术人员 QQ: 262069696 或微信号:cxh99cxh99 进行 有偿收费 编写!
(注:由于人数限制,QQ或微信请选择方便的一个联系我们就行,加好友时请简单备注下您的需求,否则无法通过。谢谢您!)
相关文章
-
没有相关内容