//+++======================================================================+++
//+++ True Fractals Bands AA MTF TT +++
//+++======================================================================+++
#property copyright "http://tradexperts.ru © Tankk, 10 December 2016, http://forexsystems.ru/"
#property link "https://forexsystemsru.com/indikatory-foreks/86203-indikatory-sobranie-sochinenii-tankk.html" ///"https://forexsystemsru.com/1259817-post7617.html" ///https://forexsystemsru.com/1198113-post65.html" //http://forexsystemsru.com/indikatory-foreks-f41/"
#property description "Фракталы [Fractals] — это один из пяти индикаторов торговой системы Билла Вильямса,"
#property description "для обнаружения впадины или вершины графика цены."
#property description "Фрактал вверх описывается как серия из, как минимум, пяти последовательных баров,"
#property description "в которой непосредственно перед самым высоким максимумом и сразу же после него"
#property description "находятся по два бара с более низкими максимумами."
#property description "Противоположная конфигурация соответствует фракталу вниз."
#property description " " //^^^^ ^^^ ^^^ ^^^^ ^^^ ^^^ ^^^^" //// ^^^ ^^^ ^^^ ^^^ ^^^^"
#property description "Перерисовывается! на пол-периода!"
#property description "^^^ ^^^ ^^^ ^^^ ^^^ ^^^ ^^^" //// ^^^ ^^^ ^^^ ^^^ ^^^^"
#property description "Почта: tualatine@mail.ru"
#property version "5.55"
//#property strict
#property indicator_chart_window
#property indicator_buffers 5
//------
#property indicator_color1 clrOrangeRed //DarkOrange
#property indicator_color2 clrDodgerBlue //DeepSkyBlue
#property indicator_color3 clrSlateGray //LightSteelBlue
//------
#property indicator_width1 0
#property indicator_width2 0
#property indicator_width3 0
//------
#property indicator_style1 STYLE_DOT
#property indicator_style2 STYLE_DOT
#property indicator_style3 STYLE_DOT //ASH
//**************************************************************************//
//*** Custom indicator ENUM settings ***
//**************************************************************************//
enum showBND { BandsOFF, bCENTER, bBANDS, bFULL };
//+++======================================================================+++
//+++ Custom indicator input parameters +++
//+++======================================================================+++
extern int History = 4444; //1234;
extern ENUM_TIMEFRAMES HLTimeFrame = 240;
extern int HLPeriod = 28; //5; = оригинальный Fractals Вильямса...
extern double HLDivider = 1.37;
extern color FRUpper = clrRed, //Magenta; //FireBrick, //Orange
FRLower = clrLime; //White, //LightCyan, //Lavender, //DarkGreen;
extern int FRGap = 0, //Дистанция от High/Low свечи (4-значные пипсы)
FRCodUP = 217, //233, //225 //241 //171,
FRCodLO = 218, //234, //226 //242 //171,
FRSize = 2;
extern showBND ShowBands = bFULL;
extern bool BandsLikeHL = true;
extern ENUM_TIMEFRAMES BDTimeFrame = PERIOD_CURRENT;
extern int BDPeriod = 36; //5; = оригинальный Fractals Вильямса...
extern double BDDivider = 1.5;
extern double BandsGap = 0.0;
extern int BandsShift = 0;
extern int SIGNALBAR = 1; //На каком баре сигналить....
//+++======================================================================+++
//+++ Custom indicator buffers +++
//+++======================================================================+++
double SUPP[], RESS[], MIDD[], FracUP[], FracLO[];
double GAP, BGAP;
int MAX, HLDV, BDDV, SGB;
datetime TimeBar=0;
bool buy=1,sell=1;
//+++======================================================================+++
//+++ Custom indicator initialization function +++
//+++======================================================================+++
int init()
{
HLTimeFrame = fmax(HLTimeFrame,_Period);
HLPeriod = fmax(HLPeriod,1);
HLDivider = fmax(HLDivider,1.001);
HLDV = floor(HLPeriod/HLDivider);
//------
if(BandsLikeHL)
{
BDTimeFrame = HLTimeFrame;
BDPeriod = HLPeriod;
BDDivider = HLDivider;
BDDV = HLDV;
}
else
{
BDTimeFrame = fmax(BDTimeFrame,_Period);
BDPeriod = fmax(BDPeriod,1);
BDDivider = fmax(BDDivider,1.001);
BDDV = floor(BDPeriod/BDDivider);
}
//------
MAX = fmax(HLPeriod,BDPeriod);
//------
GAP=FRGap*_Point;
if(Digits==3 || Digits==5)
GAP*=10;
BGAP=BandsGap*_Point;
if(Digits==3 || Digits==5)
BGAP*=10;
SGB=SIGNALBAR; //+HLPeriod/2;
//------ additional buffers are used for counting
IndicatorBuffers(5);
IndicatorDigits(Digits);
if(Digits==3 || Digits==5)
IndicatorDigits(Digits-1);
//------ 2 indicator buffers mapping
int BDLT = (ShowBands==0 || ShowBands==1) ? DRAW_NONE : DRAW_ARROW; //DRAW_LINE;
SetIndexBuffer(0,RESS);
SetIndexStyle(0,BDLT);
SetIndexShift(0,BDTimeFrame/_Period*BandsShift);
SetIndexArrow(0,FRCodUP);
SetIndexBuffer(1,SUPP);
SetIndexStyle(1,BDLT);
SetIndexShift(1,BDTimeFrame/_Period*BandsShift);
SetIndexArrow(1,FRCodUP);
int MDLT = (ShowBands==0 || ShowBands==2) ? DRAW_NONE : DRAW_ARROW; //DRAW_LINE;
SetIndexBuffer(2,MIDD);
SetIndexStyle(2,MDLT);
SetIndexShift(2,BDTimeFrame/_Period*BandsShift);
SetIndexArrow(2,FRCodUP);
//------
SetIndexBuffer(3,FracUP); //SetIndexEmptyValue(0,0.0);
SetIndexBuffer(4,FracLO); //SetIndexEmptyValue(1,0.0);
//------
for(int i=0; i<indicator_buffers; i++)
{
//SetIndexStyle(i,DRAW_ARROW,EMPTY,MXSize,MXClrUP); //--- настройка параметров отрисовки
SetIndexEmptyValue(i,0.0); //--- значение 0 отображаться не будет
//SetIndexShift(11,SlowShift); //--- установка сдвига линий при отрисовке
if(History > MAX)
SetIndexDrawBegin(i,Bars-History); //--- пропуск отрисовки первых баров
if(History <= MAX)
SetIndexDrawBegin(i,MAX);
}
//------ drawing settings
int Tup = (FRUpper!=clrNONE && FRCodUP>32) ? DRAW_ARROW : DRAW_NONE;
SetIndexStyle(3,Tup,EMPTY,FRSize,FRUpper);
SetIndexArrow(3,FRCodUP);
int Tlo = (FRLower!=clrNONE && FRCodLO>32) ? DRAW_ARROW : DRAW_NONE;
SetIndexStyle(4,Tlo,EMPTY,FRSize,FRLower);
SetIndexArrow(4,FRCodLO);
//+++======================================================================+++
//---- initialization done
return(0);
}
//+++======================================================================+++
//+++ Custom indicator deinitialization function +++
//+++======================================================================+++
int deinit() { Comment(""); return(0); }
//+++======================================================================+++
//+++ Custom indicator iteration function +++
//+++======================================================================+++
int start()
{
//+++======================================================================+++
//---- main loop
for(int i=1111; i>=0; i--) ///for (int i=0; i<limit; i++) //в "старой версии": цикл "положительный"....
{
FracUP[i]=0;
FracLO[i]=0;
RESS[i]=0;
SUPP[i]=0;
MIDD[i]=0;
//------
int y = iBarShift(NULL,HLTimeFrame,Time[i],1);
//------
if(iHighest(NULL,HLTimeFrame,MODE_HIGH,HLPeriod,y-HLDV) == y)
{
FracUP[i] = iHigh(NULL,HLTimeFrame,y) +GAP;
buy=0;
sell=1;
}
if(iLowest(NULL,HLTimeFrame,MODE_LOW, HLPeriod,y-HLDV) == y)
{
FracLO[i] = iLow(NULL,HLTimeFrame,y) -GAP;
sell=0;
buy=1;
}
//------
//------
if(ShowBands!=0)
{
int b = iBarShift(NULL,BDTimeFrame,Time[i]);
//------
if(buy)
RESS[i] = iHigh(NULL,BDTimeFrame,iHighest(NULL,BDTimeFrame,MODE_HIGH,BDPeriod,b-BDDV)) +BGAP; //y-HLPeriod/2+BandsShift
if(sell)
SUPP[i] = iLow(NULL,BDTimeFrame,iLowest(NULL,BDTimeFrame,MODE_LOW, BDPeriod,b-BDDV)) -BGAP;
} //y-HLPeriod/2+BandsShift
MIDD[i] = (RESS[i]+SUPP[i]) /2;
}
//+++======================================================================+++
//---- iteration done
return(0);
}
//+------------------------------------------------------------------+
AM2