MT4价格预警指标使用

2025-10-07 09:15:10

1、1 源码如下

//+------------------------------------------------------------------+

//|                                                     价格预警.mq4 |

//|                                           Copyright ?2011, iPan. |

//|                                http://blog.sina.com.cn/panqunjun |

//+------------------------------------------------------------------+

#property copyright "Copyright ?2011, iPan."

#property link      "http://blog.sina.com.cn/panqunjun"

#property indicator_chart_window

//--- input parameters

extern double    Price = 0;    // 设定的价位;

extern int       UpDn01 = 0;   // 0:向上突破;1:向下突破;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int init()

  {

   string upDnStr = "";

   if (UpDn01 == 0) {

      upDnStr = "上破 ";

   } else {

      upDnStr = "下破 ";

   }

   Comment("价格预警: [", upDnStr, Price, "]");

   Print("init> " + Price);

   return(0);

  }

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function                       |

//+------------------------------------------------------------------+

int deinit()

  {

   return(0);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int start()

  {

   if (Price == 0) {

      return(0);

   }

   // 向上突破某价位

   if (UpDn01 == 0 && Bid >= Price) {

      Alert("价格上破:", Price);

   // 向下突破某价位  

   } else if (UpDn01 == 1 && Ask <= Price) {

      Alert("价格下破:", Price);

   }

   return(0);

  }

//+------------------------------------------------------------------+

  MT4价格预警指标使用

1)打开MetaEditor编辑器,新建 -> 客户指标 -> 导入上面源码 -> 编译;

MT4价格预警指标使用

2、2)在MT4主界面调用,选择“价格预警”指标,如下图:

MT4价格预警指标使用

3、2)设置你要定义突破某个价位的数值,如下图

在主图左上角有显示你设定的突破提示信息;

MT4价格预警指标使用

1、4)如何修改设定的参数,右击选择“技术指标列表”,如下图:

MT4价格预警指标使用

2、5)价格修改成1562后,当前卖价是1562.8突破1562,则报警如下:

增强版本如下:

//+------------------------------------------------------------------+

//|                                                     价格预警.mq4 |

//|                                           Copyright ?2011, iPan. |

//|                                http://blog.sina.com.cn/panqunjun |

//+------------------------------------------------------------------+

#property copyright "Copyright ?2012-06-11, iPan."

#property link      "http://blog.sina.com.cn/panqunjun"

#property indicator_chart_window

#property indicator_buffers 1

#property indicator_color1 Red

//---- indicator parameters

extern double    Price = 0;    // 设定的价位;

extern int       UpDn01 = 0;   // 0:向上突破;1:向下突破;

extern bool audio = false; // 默认音频关闭

//--- buffers

double PriceLine[]; // 价位线

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int init()

  {

   SetIndexStyle(0, DRAW_LINE, STYLE_DOT);

   SetIndexBuffer(0, PriceLine);

   SetIndexLabel(0, "预警");

   string upDnStr = "";

   if (UpDn01 == 0) {

      upDnStr = "上破 ";

   } else {

      upDnStr = "下破 ";

   }

  

   Comment("价格预警: [", upDnStr, Price, "]");

   //Print("init> " + Price);

   return(0);

  }

//+------------------------------------------------------------------+

//| Custom indicator deinitialization function                       |

//+------------------------------------------------------------------+

int deinit()

  {

   return(0);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int start()

  {

   int limit;

   int counted_bars = IndicatorCounted();

  

   if (Price == 0) {

      return(0);

   }

  

   if(counted_bars > 0) counted_bars--;

   limit = Bars - counted_bars;

  

   for(int i=0; i<limit; i++) {

      PriceLine[i] = Price;

   }

   // 向上突破某价位

   if (UpDn01 == 0 && Close[0] >= Price) {

      if (audio) {

         PlaySound("jd_alarm.wav");

      } else {

         Alert("价格上破:", Price);

      }

     

   // 向下突破某价位 

   } else if (UpDn01 == 1 && Close[0] <= Price) {

      if (audio) {

         PlaySound("jd_alarm.wav");

      } else {

         Alert("价格下破:", Price);

      }

   }

   return(0);

  }

//+------------------------------------------------------------------+

MT4价格预警指标使用

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢