Miscellaneous
1
Views
0
Downloads
0
Favorites
ZZ_Orlova
//+------------------------------------------------------------------+
//| ZZ_Orlova.mq4 |
//| Denis Orlov, http://denis-or-love.narod.ru |
//| http://denis-or-love.narod.ru |
/*
ZigZag Îðëîâà
ÇèãÇàã ñ ïðîñòûì, ïîíÿòíûì è åñòåñòâåííûì ïðèíöèïîì ðàáîòû. Ïî öåíàì çàêðûòèÿ. Áåç ïåðåðèñîâêè.
Ïîäðîáíî: http://codebase.mql4.com/7277
ZigZag of Orlov
Zigzag with a simple, clear and natural principle of work. By the Close prices. Without redrawing.
In detail: http://codebase.mql4.com/7278
*/
//+------------------------------------------------------------------+
#property copyright "Denis Orlov, http://denis-or-love.narod.ru"
#property link "http://denis-or-love.narod.ru"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 2
//---- input parameters
extern double MinRatio=0.33;
extern int MinPoints=20;
extern int ForcePoints=50;
extern bool ByClose=False;
extern int History=5000;
//---- buffers
double ZZ_Orlova[];
double LastUp;
double LastDn;
bool LastIsUp;
datetime LastPicTime=0;
int Zbar[3]; //íîìåð áàðà ñ ïåðåãèáîì
double Zval[3]; //çíà÷åíèå çèãçàãà â òî÷êå ïåðåãèáà Zval[1] - â òî÷êå 1 è òä.
int ZObar[6]; //íîìåð áàðà ñ ïåðåãèáîì
double ZOval[6]; //çíà÷åíèå çèãçàãà â òî÷êå ïåðåãèáà Zval[1] - â òî÷êå 1 è òä.
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_SECTION);
SetIndexBuffer(0,ZZ_Orlova);
SetIndexEmptyValue(0,0.0);
//----
if(ForcePoints<MinPoints) ForcePoints=MinPoints;
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
if(ByClose)
{
static datetime perB;
if (perB== Time[0]) return(0); // îäèí ðàç â áàð
perB = Time[0];
}
double upPrice, dnPrice;
int limit;
int counted_bars=IndicatorCounted();
//---- ïîñëåäíèé ïîñ÷èòàííûé áàð áóäåò ïåðåñ÷èòàí
// if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars-1;
if (History>0 && limit>History)
limit=History;
int fstBar=0; if(ByClose)fstBar=1;
for(int i =limit; i>=fstBar; i--)
{
if (LastPicTime==0)//íàõîäèì ñàìûå ïåðâûå òî÷êè ïî ñò ÇÇ, ïðîñòî ÷òîáû íà÷àòü...
{
FindZigZag(i, 3);
if(Zval[0]==Low[Zbar[0]])
{
LastIsUp=False;
LastUp=Zval[1]; LastDn=Zval[0];
}
else
{
LastIsUp=True;
LastUp=Zval[0]; LastDn=Zval[1];
}
//LastIsUp=Zval[1]==High[Zbar[1]];
ZZ_Orlova[Zbar[1]]=Zval[1];
ZZ_Orlova[Zbar[0]]=Zval[0];
LastPicTime=Time[Zbar[0]]; //Alert("ðàññòàâèëè!");
// continue;
}
int LastBar=iBarShift(NULL,0,LastPicTime);//èíäåêñ(áàð) ïîñëåäíåãî ïèêà
if(ByClose)//îïðåäåëÿåì ðåæèì öåíû ïî ýêñòðåìóìàì èëè ïî çàêðûòèþ
{
upPrice=Close[i]; dnPrice=Close[i];
}
else {upPrice=High[i]; dnPrice=Low[i]; }
//----------------------------
if(LastIsUp)
{
if(upPrice>=LastUp)
{
LastUp=upPrice;
ZZ_Orlova[LastBar]=0.0;
ZZ_Orlova[i]=upPrice;
LastPicTime=Time[i];
}
else
if(
(dnPrice<=LastUp-(LastUp-LastDn)*MinRatio
&& (LastUp-dnPrice)/Point>=MinPoints
)
|| (LastUp-dnPrice)/Point>=ForcePoints
)
{
LastDn=dnPrice;
LastIsUp=False;
ZZ_Orlova[i]=dnPrice;
LastPicTime=Time[i];
}
} //if(LastIsUp)
else
if(!LastIsUp)
{
if(dnPrice<=LastDn)
{
LastDn=dnPrice;
ZZ_Orlova[LastBar]=0.0;
ZZ_Orlova[i]=dnPrice;
LastPicTime=Time[i];
}
else
if(
(upPrice>=LastDn+(LastUp-LastDn)*MinRatio
&& (upPrice-LastDn)/Point>=MinPoints
)
|| (upPrice-LastDn)/Point>=ForcePoints
)
{
LastUp=upPrice;
LastIsUp=True;
ZZ_Orlova[i]=upPrice;
LastPicTime=Time[i];
}
}// if(!LastIsUp)
}
//----
return(0);
}
//+------------------------------------------------------------------+
datetime FindZigZag(int bar, int nP )
{
int ExtDepth=12;
int ExtDeviation=5;
int ExtBackstep=3;
int n; datetime res;
for(int i=bar;i<Bars;i++)
{
double zz=iCustom(NULL,0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
if(zz!=0 && zz!=EMPTY_VALUE)
{
Zbar[n]=i;
Zval[n]=zz;
if(n==1) res=Time[Zbar[n]];//iTime(NULL, 0 , Zbar[n]);
n++;
if(n>=nP)break;
}
}
return(res);
}
//+------------------------------------------------------------------+
int FindZZO(int bar, int nP )
{
int n; datetime res;
for(int i=bar;i<Bars;i++)
{
double zz=ZZ_Orlova[i];
if(zz!=0 && zz!=EMPTY_VALUE)
{
ZObar[n]=i;
ZOval[n]=zz;
n++;
if(n>=nP)break;
}
}
return(n);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---