找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
首页论坛EAHub 外汇论坛
查看: 12|回复: 0

MT5通道突破预警

[复制链接]

4万

主题

54

回帖

4万

积分

管理员

积分
45954
发表于 2026-8-26 15:14:00 | 显示全部楼层 |阅读模式
//+------------------------------------------------------------------+
//|                                                junxianyujing.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 5//定义4个画线位置
#property indicator_plots   5 //画4条线
//---- plot long
#property indicator_label1  "long" //这条线的名称
#property indicator_type1   DRAW_LINE //这条线的类型是线性
#property indicator_color1  Red //这条线的颜色
#property indicator_style1  STYLE_SOLID //这条线是实线
#property indicator_width1  1 //这条线的宽度是1
//---- plot small
#property indicator_label2  "small"
#property indicator_type2   DRAW_LINE
#property indicator_color2  Yellow
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//---- plot long1
#property indicator_label5  "long1" //这条线的名称
#property indicator_type5   DRAW_LINE //这条线的类型是线性
#property indicator_color5  Green //这条线的颜色
#property indicator_style5  STYLE_SOLID //这条线是实线
#property indicator_width5  1 //这条线的宽度是1
//---- plot up
#property indicator_label3  "up"
#property indicator_type3   DRAW_ARROW //这里我们要画箭头
#property indicator_color3  Red
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//---- plot down
#property indicator_label4  "down"
#property indicator_type4   DRAW_ARROW
#property indicator_color4  Red
#property indicator_style4  STYLE_SOLID
#property indicator_width4  1

//--- input parameters
input int      longma=10; //长均线周期(也就是上面图中我们输入的)
input int      smallma=10; //短均线周期(也就是上面图中我们输入的)
input int      longma1=2; //收盘价均线周期
//--- indicator buffers
double         longBuffer[]; //(也就是上面图中我们输入的画线是long的时候,这里就会产生一个longBuffer[]数组)
double         smallBuffer[]; //同上
double         longBuffer1[]; //用于ma_low
double         upBuffer[]; //同上
double         downBuffer[]; //同上
int             longma_handle; //这里定义长周期均线的句柄,有了句柄,以后就可以做相关的操作。
int             smallma_handle; //这里定义短周期均线的句柄,有了句柄,以后就可以做相关的操作。
int             longma_handle1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,longBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,smallBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,upBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,downBuffer,INDICATOR_DATA);

   SetIndexBuffer(4,longBuffer1,INDICATOR_DATA);

   PlotIndexSetInteger(2,PLOT_DRAW_TYPE,DRAW_ARROW);
   PlotIndexSetInteger(3,PLOT_DRAW_TYPE,DRAW_ARROW);

   PlotIndexSetInteger(2,PLOT_ARROW,1001); //箭头类型是1001号箭头
   PlotIndexSetInteger(3,PLOT_ARROW,1002); //箭头类型是1002号箭头
   longma_handle=iMA(Symbol(),0,longma,0,MODE_SMA,PRICE_HIGH); //初始化长周期均线函数
   smallma_handle=iMA(Symbol(),0,smallma,0,MODE_SMA,PRICE_LOW); //初始化短周期均线函数
   longma_handle1=iMA(Symbol(),0,longma1,0,MODE_SMA,PRICE_CLOSE); //初始化长周期均线函数
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, //K线总数,会随着K线的增加而增加
                const int prev_calculated, //本根K线前一根K线的序号,通常来说prev_calculated=rates_total-1
                const datetime& time[], //存储所有K线的时间数组
                const double& open[], //存储所有K线的开盘价数组
                const double& high[], //存储所有K线的最高价数组
                const double& low[], //存储所有K线的最低价数组
                const double& close[], //存储所有K线的收盘价数组
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
  int malong=CopyBuffer(longma_handle,0,0,rates_total,longBuffer); //使用longma_handle长周期均线数组句柄,把均线的值复制到longBuffer数组中
  int masmall=CopyBuffer(smallma_handle,0,0,rates_total,smallBuffer); //使用smallma_handle长周期均线数组句柄,把均线的值复制到smallBuffer数组中
  int malong1=CopyBuffer(longma_handle1,0,0,rates_total,longBuffer1);
   for(int i=10;i<rates_total;i++)
   {
      if((longBuffer[i-1]>longBuffer1[i-1])&&(longBuffer<longBuffer1)) //判断两均线产生金叉了
      {
       upBuffer=longBuffer;//在金叉处画上白色箭头
       if(i==prev_calculated)//只针对当前K线报警历史K线就不用报警了
          {
           Alert("up");
           SendMail("EURUSD看多","上穿10天最高价均线");
           SendNotification("EURUSD看多");
          }//弹出窗口报警
      }
     if((smallBuffer[i-1]<longBuffer1[i-1])&&(smallBuffer>longBuffer1)) //判断两均线产生了死叉
      {
       downBuffer=longBuffer1;//在死叉处画上青色箭头
       if(i==prev_calculated)//只针对当前K线报警历史K线就不用报警了
          {
           Alert("down");
           SendMail("EURUSD看空","下穿10天最低价均线");
           SendNotification("EURUSD看空");
          }//弹出窗口报警
      }
   }
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }

复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|EAHub外汇论坛

GMT+8, 2026-10-11 01:18 , Processed in 0.106789 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表