
//+------------------------------------------------------------------+
//| Levels.mq4 |
//| Copyright 2017, AM2 |
//| http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, AM2"
#property link "http://www.forexsystems.biz"
#property version "1.00"
#property strict
#property indicator_chart_window
input int MAPeriod=50;
input int ADXPeriod=14;
input int RSIPeriod=14;
input int RSILevel=30;
input int ADXLevel=45;
input int Count=5;
input int Length=100;
input ENUM_TIMEFRAMES tf=PERIOD_H4;
int k=0;
datetime t=0;
int length=Length;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
Comment("");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void RightPrice(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);
}
//+------------------------------------------------------------------+
//| 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<Bars;i++)
{
if(iADX(NULL,tf,ADXPeriod,0,0,i)>ADXLevel && iRSI(NULL,tf,RSIPeriod,0,i)>100-RSILevel && iRSI(NULL,tf,RSIPeriod,0,i+1)<100-RSILevel && iAO(NULL,tf,i)>0)
{
int step=i-length;
if(i<Length) {length=i;}
PutTrendLine("Line "+(string)Time[i],Time[i],Close[i],Time[i-length],Close[i],Red);
Alert(_Symbol+": "+"Нарисовался верхний уровень!");
RightPrice("Arrow "+(string)Time[i],Time[i],Close[i]);
k++;
}
if(iADX(NULL,tf,ADXPeriod,0,0,i)>ADXLevel && iRSI(NULL,tf,RSIPeriod,0,i)<RSILevel && iRSI(NULL,tf,RSIPeriod,0,i+1)>RSILevel && iAO(NULL,tf,i)<0)
{
PutTrendLine("Line "+(string)Time[i],Time[i],Close[i],Time[i-length],Close[i],Red);
Alert(_Symbol+": "+"Нарисовался нижний уровень!");
RightPrice("Arrow "+(string)Time[i],Time[i],Close[i]);
k++;
}
if(k>=Count) break;
t=Time[0];
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
AM2