//+------------------------------------------------------------------+
//| ADX-报警.mq4 |
//| Copyright 2014, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 4
#property indicator_plots 4
//--- plot DI1
#property indicator_label1 "DI1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot DI2
#property indicator_label2 "DI2"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrGreen
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- plot up
#property indicator_label3 "up"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrRed
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//--- plot down
#property indicator_label4 "down"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrRed
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//--- input parameters
input int preit=14;
//--- indicator buffers
double DI1Buffer[];
double DI2Buffer[];
double DI1pBuffer[];
double DI2pBuffer[];
double DI1,DI2,DI11,DI22;
double upBuffer[];
double downBuffer[];
datetime jincha=0;
datetime sicha=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,DI1Buffer);
SetIndexBuffer(1,DI2Buffer);
SetIndexBuffer(2,upBuffer);
SetIndexBuffer(3,downBuffer);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
int limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=1000-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=limit; i>=0; i--)
{
double DI1=iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,i);
double DI2=iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,i-1);
double DI11=iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,i);
double DI22=iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,i-1);
if((DI1>DI1)&&(DI11<DI22))//金叉
{
if(i==0)
{
if(jincha!=Time[0])
{
Alert("金叉");
jincha=Time[0];
}
}
upBuffer[i]=Low[i]-100*Point;
}
if((DI1<DI1)&&(DI11>DI22))//死叉
{
if(i==0)
{
if(jincha!=Time[0])
{
Alert("死叉");
jincha=Time[0];
}
}
} downBuffer[i]=Low[i]-100*Point;
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
|