加载中…
个人资料
iPan
iPan
  • 博客等级:
  • 博客积分:0
  • 博客访问:12,870
  • 关注人气:234
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

MT4价格预警指标

(2011-12-31 14:18:31)
标签:

mt4

价格

预警

报警

提示

指标

脚本

财经

分类: 交易成长

    有时候等待某个点位的时候需要花时间盯盘,能否实现让程序自动提醒?今天有时间写了个指标可以实时提示,共享给大家使用。当价格达到自己设定的点位时候,MT4会弹出对话框报警,也可以设置为语言提示,代码稍微改下即可。下面代码已经可以满足简单使用了。

 

iPan

2011-12-31

 

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);
  }
//+------------------------------------------------------------------+

 

2 使用

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

 

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

MT4价格预警指标

 

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

MT4价格预警指标

在主图左上角有显示你设定的突破提示信息;
MT4价格预警指标


 

4)如何修改设定的参数,右击选择“技术指标列表”,如下图:
MT4价格预警指标


 

5)价格修改成1562后,当前卖价是1562.8突破了1562,则报警如下:
MT4价格预警指标

--------------------------------------------------------------------------------------------------

增强版本如下:

//+------------------------------------------------------------------+
//|                                                     价格预警.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);
  }
//+------------------------------------------------------------------+

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有