//+------------------------------------------------------------------+
//| ADXL.mq4 |
//| Copyright 2018, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
input int MAPeriod=50;
input int ADXPeriod=14;
input int RSIPeriod=14;
input int RSILevel=40;
input int ADXLevel=45;
input int Count=5;
input int Length=10;
input int Barov=111;
input ENUM_TIMEFRAMES tf=PERIOD_H1;
int k=0;
datetime t=0;
double up[],dn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
ObjectsDeleteAll(0,0,OBJ_ARROW_LEFT_PRICE);
SetIndexBuffer(0,up);
SetIndexBuffer(1,dn);
SetIndexStyle(0,DRAW_ARROW,0,2,Red);
SetIndexStyle(1,DRAW_ARROW,0,2,Yellow);
SetIndexArrow(0,217);
SetIndexArrow(1,218);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
ObjectsDeleteAll();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void LeftPrice(string name,datetime time,double price)
{
ObjectCreate(0,name,OBJ_ARROW_LEFT_PRICE,0,time,price);
//--- установим цвет метки
ObjectSetInteger(0,name,OBJPROP_COLOR,Red);
//--- установим стиль окаймляющей линии
ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID);
//--- установим размер метки
ObjectSetInteger(0,name,OBJPROP_WIDTH,1);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void PutTrendLine(string name,datetime time1,double price1,datetime time2,double price2,color clr)
{
ObjectDelete(0,name);
ObjectCreate(0,name,OBJ_TREND,0,time1,price1,time2,price2);
//--- установим цвет линии
ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
//--- установим стиль отображения линии
ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_DOT);
//--- установим толщину линии
ObjectSetInteger(0,name,OBJPROP_WIDTH,2);
//--- включим (true) или отключим (false) режим продолжения отображения линии вправо
ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double ZZPrice(int n=0)
{
double zz=0;
k=0;
for(int i=0; i<1111; i++)
{
zz=iCustom(NULL,0,"ZigZag",12,5,3,0,i);
if(zz!=0)
{
k++;
if(k>n) return(zz);
}
}
return(0);
}
//+------------------------------------------------------------------+
//| 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[])
{
//---
if(t!=time[0])
{
for(int i=0;i<Barov;i++)
{
double adx1=iADX(NULL,tf,ADXPeriod,0,0,i);
double adx2=iADX(NULL,tf,ADXPeriod,0,0,i+1);
double rsi=iRSI(NULL,tf,RSIPeriod,0,i);
double ao=iAO(NULL,tf,i);
double ma=iMA(NULL,tf,MAPeriod,0,1,0,i);
double zz1=ZZPrice(0);
double zz2=ZZPrice(1);
double zz3=ZZPrice(2);
if(adx1>ADXLevel && adx2<ADXLevel && close[i]>ma && rsi>100-RSILevel && ao>0)
{
if(i>Length) PutTrendLine("Line "+(string)time[i],time[i],close[i],time[i-Length],close[i],Red);
PutTrendLine("ZZ",time[0],(zz2+zz3)/2,time[0+10],(zz2+zz3)/2,Yellow);
Alert(_Symbol+": "+"Нарисовался верхний уровень!");
LeftPrice("Arrow "+(string)time[i],time[i],close[i]);
up[i]=high[i];
k++;
}
if(adx1>ADXLevel && adx2<ADXLevel && close[i]<ma && rsi<RSILevel && ao<0)
{
if(i>Length) PutTrendLine("Line "+(string)time[i],time[i],close[i],time[i-Length],close[i],Red);
PutTrendLine("ZZ",time[0],(zz2+zz3)/2,time[0+10],(zz2+zz3)/2,Yellow);
Alert(_Symbol+": "+"Нарисовался нижний уровень!");
LeftPrice("Arrow "+(string)time[i],time[i],close[i]);
dn[i]=low[i];
k++;
}
if(k>=Count) break;
t=time[0];
Comment("\n zz1: ",zz1,
"\n zz2: ",zz2,
"\n zz3: ",zz3);
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
AM2