//+------------------------------------------------------------------+
//| 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; //ma_high周期(也就是上面图中我们输入的)
input int smallma=10; //ma_low周期(也就是上面图中我们输入的)
input int longma1=2; //收盘价均线周期
//--- indicator buffers
double longBuffer[]; //(也就是上面图中我们输入的画线是long的时候,这里就会产生一个longBuffer[]数组),是记录ma_high的数组
double smallBuffer[]; //是记录ma_low的数组
double longBuffer1[]; //用于记录收盘价
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); //初始化,ma_high均线函数longma
smallma_handle=iMA(Symbol(),0,smallma,0,MODE_SMA,PRICE_LOW); //初始化,ma_low均线函数smallma
longma_handle1=iMA(Symbol(),0,longma1,0,MODE_SMA,PRICE_CLOSE); //初始化,ma_close函数longma1
//---
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((smallBuffer[i-1]>longBuffer1[i-1])&&(smallBuffer[i]<longBuffer1[i])) //判断两均线产生金叉了,上穿ma_low
{
upBuffer[i]=smallBuffer[i];//在金叉处,ma_low数组smallBuffer[i]画上白色箭头
if(i==prev_calculated)//只针对当前K线报警历史K线就不用报警了
{
Alert("up");
SendMail("XAGUSD看多","上穿10天最低价均线");
SendNotification("XAGUSD看多");
}//弹出窗口报警
}
if((longBuffer[i-1]<longBuffer1[i-1])&&(longBuffer[i]>longBuffer1[i])) //判断两均线产生了死叉,下穿ma_high
{
downBuffer[i]=longBuffer[i];//在死叉处,ma_high数组longBuffer[i]画上青色箭头
if(i==prev_calculated)//只针对当前K线报警历史K线就不用报警了
{
Alert("down");
SendMail("XAGUSD看空","下穿10天最高价均线"); //EURUSD1是单均线突破、2是上穿最高价均线做多、3是上穿最低价就做多、想对2是提前了
SendNotification("XAGUSD看空");
}//弹出窗口报警
}
}
//---
//--- return value of prev_calculated for next call
return(rates_total);
}
EURUSD3
最新推荐文章于 2024-06-28 17:28:02 发布