//+------------------------------------------------------------------+
//| Envelopes for RSI.mq4 |
//| Copyright 2018, Tor |
//| https://www.mql5.com/ru/users/tormovies |
//+------------------------------------------------------------------+
/*
https://www.mql5.com/ru/code/21187
Очередная версия стрелочного канального индикатора Envelopes, который строится на стандартном индикаторе RSI.
Не все трейдеры согласны ждать пересечения индикатором RSi общих уровней перекупленности и перепроданности,
поэтому они строят усредненные каналы RSI, например, BB или Envelopes.
Envelopes построить стандартными способами над индикатором RSI нельзя, наш индикатор теперь решает эту проблему.
Индикатор рисует стрелки или вертикальные линии на местах пересечений данных уровней Envelopes:
?Для продажи - пересечение верхнего уровня Envelopes сверху вниз;
?Для покупки - пересечение нижнего уровня Envelopes снизу вверх.
*/
#property copyright "Copyright 2018, Tor"
#property link "https://www.mql5.com/ru/users/tormovies"
#property version "1.0"
#property description "This indicator is based on standard indicator Relative Strength Index"
#property description "and draws a Envelopes channel for him"
#property strict
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots 5
#property indicator_minimum 0
#property indicator_maximum 100
input string t1="--- Input Sto parameters ---";
extern int KPeriod = 8; //
extern int DPeriod = 3; //
extern int Slowing = 3; //
input int MaxLevel = 70; // Max signal level
input int MinLevel = 30; // Min signal level
input color rsicolor=clrDodgerBlue;// RSI color
input int rsiwidth=1; // RSI width
input string t2="--- Input Envelopes parameters ---";
input int EnvPeriod=80; // Envelopes Period
input ENUM_MA_METHOD EnvMethod=MODE_EMA;//Envelopes method
input double EnvDeviation= 35;// Envelopes Deviation
input color Envcolor=clrLime;// Envelopes Color
input int EnvWidth=1;// Envelopes Width
input ENUM_LINE_STYLE EnvStyle=STYLE_SOLID;// Envelopes line style
input string t3="--- Other parameters ---";
input int alertShift=1; // Candle which look for the signal (0 = current candle)
input bool showLine=false; // Show vertical lines
input bool showArrows=true; // Show arrows
double RSIx[],bbup[],bbdn[],buy[],sell[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
IndicatorShortName("Env for Sto");
SetIndexBuffer(0,RSIx);
SetIndexBuffer(1,bbup);
SetIndexBuffer(2,bbdn);
SetIndexBuffer(3,buy);
SetIndexBuffer(4,sell);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,rsiwidth,rsicolor);
SetIndexStyle(1,DRAW_LINE,EnvStyle,EnvWidth,Envcolor);
SetIndexStyle(2,DRAW_LINE,EnvStyle,EnvWidth,Envcolor);
SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,1,clrBlue);
SetIndexStyle(4,DRAW_ARROW,STYLE_SOLID,1,clrRed);
SetIndexArrow(3,233);
SetIndexArrow(4,234);
SetIndexLabel(0,"Sto");
SetIndexLabel(1,"Envelopes Up");
SetIndexLabel(2,"Envelopes Down");
SetLevelValue(1,MinLevel);
SetLevelValue(2,MaxLevel);
SetLevelValue(3,50);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
int deinit()
{
del("Envfrs_");
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[])
{
//---
int limit; int xxx=0;
static datetime altime=0;
//---
if(rates_total<=1)
return(0);
//--- last counted bar will be recounted
limit=rates_total-prev_calculated;
if(prev_calculated>0)
limit=limit+2;
for(int x=limit-2; x>=0; x--)
{
RSIx[x]=iStochastic(NULL,0,KPeriod,DPeriod,Slowing,0,0,0,x);
}
for(int x2=limit-2; x2>=0; x2--)
{
bbup[x2]=iEnvelopesOnArray(RSIx,0,EnvPeriod,EnvMethod,0,EnvDeviation,MODE_UPPER,x2);
bbdn[x2]=iEnvelopesOnArray(RSIx,0,EnvPeriod,EnvMethod,0,EnvDeviation,MODE_LOWER,x2);
}
for(int x3=limit-2; x3>=0; x3--)
{
if(RSIx[x3+alertShift]<bbup[x3+alertShift] && RSIx[x3+alertShift+1]>bbup[x3+alertShift+1])
{
if(showArrows){ sell[x3]=RSIx[x3]; }
if(showLine){ Lines(x3,"Sell",clrRed); }
}
if(RSIx[x3+alertShift]>bbdn[x3+alertShift] && RSIx[x3+alertShift+1]<bbdn[x3+alertShift+1])
{
if(showArrows){ buy[x3]=RSIx[x3]; }
if(showLine){ Lines(x3,"Buy",clrBlue); }
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
void Lines(int shift,string txt,color clr=clrRed)
{
datetime time=iTime(Symbol(),0,shift);
ObjectCreate(0,"Envfrs_"+txt+"_"+(string)time,OBJ_VLINE,0,time,0);
ObjectSetInteger(0,"Envfrs_"+txt+"_"+(string)time,OBJPROP_COLOR,clr);
ObjectSetInteger(0,"Envfrs_"+txt+"_"+(string)time,OBJPROP_STYLE,STYLE_DOT);
ObjectSetString(0,"Envfrs_"+txt+"_"+(string)time,OBJPROP_TOOLTIP,txt);
ObjectSetInteger(0,"Envfrs_"+txt+"_"+(string)time,OBJPROP_BACK,true);
return;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int del(string name)
{
for(int n=ObjectsTotal()-1; n>=0; n--)
{
string Obj_Name=ObjectName(n);
if(StringFind(Obj_Name,name,0)!=-1)
{
ObjectDelete(Obj_Name);
}
}
return 0;
}
//+------------------------------------------------------------------+
2. Стововые по мах и мин M1
3. Лимитные по мах и мин Н4
extern double KLot = 1; // увеличение лота
Индикатор Envelopes нанесенный на индикатор Stochastic. Параметры: период 32, отклонение 42%
AM2