mt5指标,照着别人的代码写的,结果画出来的千奇百怪 新评论 cloudchina 2022.03.11 07:25 如上图所示,下面日期上方出现了很多箭头,最后一个填充柱乱七八糟的。还有另一张图片也是 如上图所示,上下都有箭头,搞不懂为撒,主要是切换周期的时候经常出现这种问题,有时把这个指标保存为模板后,切换模板也是出现这种问题。 还有想出现信号后提醒通知到手机,但是启动指标的时候,之前的信号不需要提醒,设置了一个时间变量,刚开始一段时间没问题,随着挂vps的时间越长,就越乱,比如周末都停盘了,却来大量通知,有时明明还未收线,又来大量通知。请大佬帮忙看下代码。 //+------------------------------------------------------------------+ //| 双均线pinbar.mq5 | //| Copyright 2022, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 13 #property indicator_plots 7 //--- plot xian #property indicator_label1 "小周期均线" #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 clrRed,clrBlue #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot zhu2 #property indicator_label2 "填充柱" #property indicator_type2 DRAW_COLOR_HISTOGRAM2 #property indicator_color2 clrRed,clrBlue #property indicator_style2 STYLE_SOLID #property indicator_width2 2 //--- plot up #property indicator_label3 "多头箭头" #property indicator_type3 DRAW_COLOR_ARROW #property indicator_color3 clrRed,clrIndianRed #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- plot down #property indicator_label4 "空头箭头" #property indicator_type4 DRAW_COLOR_ARROW #property indicator_color4 clrBlue,clrDeepSkyBlue #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- plot xian2 #property indicator_label5 "大周期均线" #property indicator_type5 DRAW_COLOR_LINE #property indicator_color5 clrRed,clrBlue #property indicator_style5 STYLE_SOLID #property indicator_width5 1 //--- plot pinbar_up #property indicator_label6 "pinbar_up箭头" #property indicator_type6 DRAW_ARROW #property indicator_color6 clrRed #property indicator_style6 STYLE_SOLID #property indicator_width6 2 //--- plot pinbar_down #property indicator_label7 "pinbar_down箭头" #property indicator_type7 DRAW_ARROW #property indicator_color7 clrBlue #property indicator_style7 STYLE_SOLID #property indicator_width7 2 //--- indicator buffers double xianBuffer[]; double xianColors[]; double xian2Buffer[]; double xian2Colors[]; double zhu2Buffer1[]; double zhu2Buffer2[]; double zhu2Colors[]; double upBuffer[]; double upColors[]; double downBuffer[]; double downColors[]; double pinbar_upBuffer[]; double pinbar_downBuffer[]; input int shortma=9;//小周期均线周期 input ENUM_MA_METHOD shortma_method=MODE_EMA;//小周期均线类型 input int longma=22;//大周期均线周期 input ENUM_MA_METHOD longma_method=MODE_EMA;//大周期均线类型 input double longshadow=3;//长影线倍数 datetime starttime=0; datetime alerttime=0; int shortma_h; int longma_h; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,xianBuffer,INDICATOR_DATA); SetIndexBuffer(1,xianColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(2,zhu2Buffer1,INDICATOR_DATA); SetIndexBuffer(3,zhu2Buffer2,INDICATOR_DATA); SetIndexBuffer(4,zhu2Colors,INDICATOR_COLOR_INDEX); SetIndexBuffer(5,upBuffer,INDICATOR_DATA); SetIndexBuffer(6,upColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(7,downBuffer,INDICATOR_DATA); SetIndexBuffer(8,downColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(9,xian2Buffer,INDICATOR_DATA); SetIndexBuffer(10,xian2Colors,INDICATOR_COLOR_INDEX); SetIndexBuffer(11,pinbar_upBuffer,INDICATOR_DATA); SetIndexBuffer(12,pinbar_downBuffer,INDICATOR_DATA); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW PlotIndexSetInteger(2,PLOT_ARROW,225);//向上箭头 PlotIndexSetInteger(3,PLOT_ARROW,226);//向下箭头 PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0);//没有箭头时画空值 PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,0); PlotIndexSetInteger(5,PLOT_ARROW,217);//pinbar_up向上箭头 PlotIndexSetInteger(6,PLOT_ARROW,218);//pinbar_down向下箭头 PlotIndexSetDouble(5,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,0); PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);//两根均线画0 PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,0); //--- ArraySetAsSeries(xianBuffer,false); ArraySetAsSeries(xianColors,false); ArraySetAsSeries(xian2Buffer,false); ArraySetAsSeries(xian2Colors,false); ArraySetAsSeries(upBuffer,false); ArraySetAsSeries(upColors,false); ArraySetAsSeries(downBuffer,false); ArraySetAsSeries(downColors,false); ArraySetAsSeries(pinbar_upBuffer,false); ArraySetAsSeries(pinbar_downBuffer,false); starttime=TimeTradeServer(); shortma_h=iMA(NULL,0,shortma,0,shortma_method,PRICE_CLOSE); longma_h=iMA(NULL,0,longma,0,longma_method,PRICE_CLOSE); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { double short_ma[]; ArraySetAsSeries(short_ma,false); CopyBuffer(shortma_h,0,0,rates_total-1,short_ma); double long_ma[]; ArraySetAsSeries(long_ma,false); CopyBuffer(longma_h,0,0,rates_total-1,long_ma); ArraySetAsSeries(time,false); ArraySetAsSeries(open,false); ArraySetAsSeries(high,false); ArraySetAsSeries(close,false); ArraySetAsSeries(low,false); int start=2; string periodstr=Periodstr(Period()); if(prev_calculated>0) { start=prev_calculated-1; } for(int i=start;i<rates_total-1;i++) { xianBuffer[i]=short_ma[i];//画线 xian2Buffer[i]=long_ma[i];//画线 if(close[i]>short_ma[i] && short_ma[i]>long_ma[i])//多头趋势 { xianColors[i]=0;//线的颜色 xian2Colors[i]=0; //多头pinbar判断,阳K && 下影线>=3*实体 && 下影线>=3*上影线 && 从右往左第二根K线开始) //避免当根K线未收线出现假信号 //指标加载时间要小于K线时间,即指标加载后产生的信号才通知提醒 if(close[i]>open[i] && (open[i]-low[i])>=longshadow*(close[i]-open[i]) && (open[i]-low[i])>=longshadow*(high[i]-close[i])) { pinbar_upBuffer[i]=xian2Buffer[i]-100*Point();//箭头位置 if(alerttime!=time[i+1] && starttime<time[i]) { string notify=TimeToString(TimeLocal())+" "+ Symbol() +periodstr+" 多头pinbar入场!"; Alert(notify); SendNotification(notify); alerttime=time[i+1]; } } } else if(close[i]<short_ma[i] && short_ma[i]<long_ma[i])//空头趋势 { xianColors[i]=1;//线的颜色 xian2Colors[i]=1; //空头pinbar判断,阴K && 上影线>=3*实体 && 上影线>=3*下影线 && 从右往左第二根K线开始) //避免当根K线未收线出现假信号 if(close[i]<open[i] && (high[i]-open[i])>=longshadow*(open[i]-close[i]) && (high[i]-open[i])>=longshadow*(close[i]-low[i])) { pinbar_downBuffer[i]=xian2Buffer[i]+100*Point();//箭头位置 //string piodstr=Periodstr(Period()); if(alerttime!=time[i+1] && starttime<time[i]) { string notify=TimeToString(TimeLocal())+" "+ Symbol() +periodstr+" 空头pinbar入场!"; Alert(notify); SendNotification(notify); alerttime=time[i+1]; } } } else //延续之前的趋势颜色 { xianColors[i]=xianColors[i-1]; xian2Colors[i]=xian2Colors[i-1]; //之前是多头的颜色,0 if(xianColors[i]==0) { if(close[i]>open[i] && (open[i]-low[i])>=longshadow*(close[i]-open[i]) && (open[i]-low[i])>=longshadow*(high[i]-close[i])) { pinbar_upBuffer[i]=xian2Buffer[i]-100*Point();//箭头位置 if(alerttime!=time[i+1] && starttime<time[i]) { string notify=TimeToString(TimeLocal())+" "+ Symbol() +periodstr+" 多头pinbar入场!"; Alert(notify); SendNotification(notify); alerttime=time[i+1]; } } } else//之前是死叉的颜色,1 { if(close[i]<open[i] && (high[i]-open[i])>=longshadow*(open[i]-close[i]) && (high[i]-open[i])>=longshadow*(close[i]-low[i])) { pinbar_downBuffer[i]=xian2Buffer[i]+100*Point();//箭头位置 //string piodstr=Periodstr(Period()); if(alerttime!=time[i+1] && starttime<time[i]) { string notify=TimeToString(TimeLocal())+" "+ Symbol() +periodstr+" 空头pinbar入场!"; Alert(notify); SendNotification(notify); alerttime=time[i+1]; } } } } //金叉,避免当根K线未收线出现假信号 if(xianBuffer[i-1]<xian2Buffer[i-1] && xianBuffer[i]>xian2Buffer[i]) { upBuffer[i]=xian2Buffer[i]-200*Point();//箭头位置 if(xianBuffer[i]-xian2Buffer[i] >100*Point())//看金叉点数,决定箭头颜色 { upColors[i]=0; } else { upColors[i]=1; } } //死叉,避免当根K线未收线出现假信号 if(xianBuffer[i-1]>xian2Buffer[i-1] && xianBuffer[i]<xian2Buffer[i]) { downBuffer[i]=xian2Buffer[i]+200*Point();//箭头位置 if(xian2Buffer[i]-xianBuffer[i] >100*Point())//看死叉点数,决定箭头颜色 { downColors[i]=0; } else { downColors[i]=1; } } //边界画柱 zhu2Buffer1[i]=short_ma[i]; zhu2Buffer2[i]=long_ma[i]; if(xianBuffer[i]>xian2Buffer[i]) { zhu2Colors[i]=0; } else { zhu2Colors[i]=1; } ////图表上下平移 //candleBuffer1[i]=close[i]-1000*Point(); //candleBuffer2[i]=low[i]-1000*Point(); //candleBuffer3[i]=high[i]-1000*Point(); //candleBuffer4[i]=open[i]-1000*Point(); //if(candleBuffer1[i]>candleBuffer4[i]) // { // candleColors[i]=1; // } //else // { // candleColors[i]=0; // } } return(rates_total); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { //--- } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- } //+------------------------------------------------------------------+ string Periodstr(int piod) { string str; //调用该函数获取Period()的值 // 5:"M5";30:"M30";16385:"H1";16388:"H4";16390:"H6";16392:"H8";16396:"H12";16408:"D1";32769:"W1" switch(piod) { case 0: str="Cur"; break; case 1: str="M1"; break; case 5: str="M5"; break; case 15: str="M15"; break; case 30: str="M30"; break; case 16385: str="H1"; break; case 16388: str="H4"; break; case 16408: str="D1"; break; case 10080: str="W1"; break; case 43200: str="MN"; break; default: break; } return str; } 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
如上图所示,下面日期上方出现了很多箭头,最后一个填充柱乱七八糟的。还有另一张图片也是
如上图所示,上下都有箭头,搞不懂为撒,主要是切换周期的时候经常出现这种问题,有时把这个指标保存为模板后,切换模板也是出现这种问题。
还有想出现信号后提醒通知到手机,但是启动指标的时候,之前的信号不需要提醒,设置了一个时间变量,刚开始一段时间没问题,随着挂vps的时间越长,就越乱,比如周末都停盘了,却来大量通知,有时明明还未收线,又来大量通知。请大佬帮忙看下代码。