设为首页 收藏本站 切换语言

MT5通道突破预警

| 发表于 2022-12-20 15:55:20 | 显示全部楼层 |复制链接
  1. //+------------------------------------------------------------------+
  2. //|                                                junxianyujing.mq5 |
  3. //|                        Copyright 2019, MetaQuotes Software Corp. |
  4. //|                                             https://www.mql5.com |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2019, MetaQuotes Software Corp."
  7. #property link      "https://www.mql5.com"
  8. #property version   "1.00"
  9. #property indicator_chart_window
  10. #property indicator_buffers 5//定义4个画线位置
  11. #property indicator_plots   5 //画4条线
  12. //---- plot long
  13. #property indicator_label1  "long" //这条线的名称
  14. #property indicator_type1   DRAW_LINE //这条线的类型是线性
  15. #property indicator_color1  Red //这条线的颜色
  16. #property indicator_style1  STYLE_SOLID //这条线是实线
  17. #property indicator_width1  1 //这条线的宽度是1
  18. //---- plot small
  19. #property indicator_label2  "small"
  20. #property indicator_type2   DRAW_LINE
  21. #property indicator_color2  Yellow
  22. #property indicator_style2  STYLE_SOLID
  23. #property indicator_width2  1
  24. //---- plot long1
  25. #property indicator_label5  "long1" //这条线的名称
  26. #property indicator_type5   DRAW_LINE //这条线的类型是线性
  27. #property indicator_color5  Green //这条线的颜色
  28. #property indicator_style5  STYLE_SOLID //这条线是实线
  29. #property indicator_width5  1 //这条线的宽度是1
  30. //---- plot up
  31. #property indicator_label3  "up"
  32. #property indicator_type3   DRAW_ARROW //这里我们要画箭头
  33. #property indicator_color3  Red
  34. #property indicator_style3  STYLE_SOLID
  35. #property indicator_width3  1
  36. //---- plot down
  37. #property indicator_label4  "down"
  38. #property indicator_type4   DRAW_ARROW
  39. #property indicator_color4  Red
  40. #property indicator_style4  STYLE_SOLID
  41. #property indicator_width4  1
  42. //--- input parameters
  43. input int      longma=10; //长均线周期(也就是上面图中我们输入的)
  44. input int      smallma=10; //短均线周期(也就是上面图中我们输入的)
  45. input int      longma1=2; //收盘价均线周期
  46. //--- indicator buffers
  47. double         longBuffer[]; //(也就是上面图中我们输入的画线是long的时候,这里就会产生一个longBuffer[]数组)
  48. double         smallBuffer[]; //同上
  49. double         longBuffer1[]; //用于ma_low
  50. double         upBuffer[]; //同上
  51. double         downBuffer[]; //同上
  52. int             longma_handle; //这里定义长周期均线的句柄,有了句柄,以后就可以做相关的操作。
  53. int             smallma_handle; //这里定义短周期均线的句柄,有了句柄,以后就可以做相关的操作。
  54. int             longma_handle1;
  55. //+------------------------------------------------------------------+
  56. //| Custom indicator initialization function                         |
  57. //+------------------------------------------------------------------+
  58. int OnInit()
  59.   {
  60. //--- indicator buffers mapping
  61.    SetIndexBuffer(0,longBuffer,INDICATOR_DATA);
  62.    SetIndexBuffer(1,smallBuffer,INDICATOR_DATA);
  63.    SetIndexBuffer(2,upBuffer,INDICATOR_DATA);
  64.    SetIndexBuffer(3,downBuffer,INDICATOR_DATA);
  65.    SetIndexBuffer(4,longBuffer1,INDICATOR_DATA);
  66.    PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_ARROW);
  67.    PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_ARROW);
  68.    PlotIndexSetInteger(2,PLOT_ARROW,1001); //箭头类型是1001号箭头
  69.    PlotIndexSetInteger(3,PLOT_ARROW,1002); //箭头类型是1002号箭头
  70.    longma_handle=iMA(Symbol(),0,longma,0,MODE_SMA,PRICE_HIGH); //初始化长周期均线函数
  71.    smallma_handle=iMA(Symbol(),0,smallma,0,MODE_SMA,PRICE_LOW); //初始化短周期均线函数
  72.    longma_handle1=iMA(Symbol(),0,longma1,0,MODE_SMA,PRICE_CLOSE); //初始化长周期均线函数
  73. //---
  74.    return(0);
  75.   }
  76. //+------------------------------------------------------------------+
  77. //| Custom indicator iteration function                              |
  78. //+------------------------------------------------------------------+
  79. int OnCalculate(const int rates_total, //K线总数,会随着K线的增加而增加
  80.                 const int prev_calculated, //本根K线前一根K线的序号,通常来说prev_calculated=rates_total-1
  81.                 const datetime& time[], //存储所有K线的时间数组
  82.                 const double& open[], //存储所有K线的开盘价数组
  83.                 const double& high[], //存储所有K线的最高价数组
  84.                 const double& low[], //存储所有K线的最低价数组
  85.                 const double& close[], //存储所有K线的收盘价数组
  86.                 const long& tick_volume[],
  87.                 const long& volume[],
  88.                 const int& spread[])
  89.   {
  90.   int malong=CopyBuffer(longma_handle,0,0,rates_total,longBuffer); //使用longma_handle长周期均线数组句柄,把均线的值复制到longBuffer数组中
  91.   int masmall=CopyBuffer(smallma_handle,0,0,rates_total,smallBuffer); //使用smallma_handle长周期均线数组句柄,把均线的值复制到smallBuffer数组中
  92.   int malong1=CopyBuffer(longma_handle1,0,0,rates_total,longBuffer1);
  93.    for(int i=10;i<rates_total;i++)
  94.    {
  95.       if((longBuffer[i-1]>longBuffer1[i-1])&&(longBuffer<longBuffer1)) //判断两均线产生金叉了
  96.       {
  97.        upBuffer=longBuffer;//在金叉处画上白色箭头
  98.        if(i==prev_calculated)//只针对当前K线报警历史K线就不用报警了
  99.           {
  100.            Alert("up");
  101.            SendMail("EURUSD看多","上穿10天最高价均线");
  102.            SendNotification("EURUSD看多");
  103.           }//弹出窗口报警
  104.       }
  105.      if((smallBuffer[i-1]<longBuffer1[i-1])&&(smallBuffer>longBuffer1)) //判断两均线产生了死叉
  106.       {
  107.        downBuffer=longBuffer1;//在死叉处画上青色箭头
  108.        if(i==prev_calculated)//只针对当前K线报警历史K线就不用报警了
  109.           {
  110.            Alert("down");
  111.            SendMail("EURUSD看空","下穿10天最低价均线");
  112.            SendNotification("EURUSD看空");
  113.           }//弹出窗口报警
  114.       }
  115.    }
  116. //---
  117. //--- return value of prev_calculated for next call
  118.    return(rates_total);
  119.   }
复制代码
如果有帮助,就支持一下我呗
举报

评论 使用道具

精彩评论4

daerwushen
DD
| 发表于 2022-12-21 12:18:14 | 显示全部楼层
突破预警
举报

点赞 评论 使用道具

ken138888
B
| 发表于 2022-12-22 07:23:12 | 显示全部楼层
哪里找到这么多教程啊
举报

点赞 评论 使用道具

dongxu64
DDD
| 发表于 2022-12-26 17:33:58 | 显示全部楼层
挺好的预警
举报

点赞 评论 使用道具

daerwushen
DD
| 发表于 2022-12-27 21:03:22 | 显示全部楼层
mt5复杂好多
举报

点赞 评论 使用道具

发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册

简体中文
繁體中文
English(英语)
日本語(日语)
Deutsch(德语)
Русский язык(俄语)
بالعربية(阿拉伯语)
Türkçe(土耳其语)
Português(葡萄牙语)
ภาษาไทย(泰国语)
한어(朝鲜语/韩语)
Français(法语)