/*======================== ZigZag Pivot ==========================
=================== Autor: Nikolay Khrushchev ====================
Contact Information / Êîíòàêòíàÿ èíôîðìàöèÿ:
e-mail: N.A.Khrushchev@gmail.com; skype: keep4er
e-mail: Nikolay.keep@yandex.ru ICQ: 463607666
Ìîäèôèêàöèè: */
#property copyright "Nikolay Khrushchev"
#property link "Nikolay.keep@yandex.ru"
#property show_inputs
extern int TimeFrame = 0;
extern int BarsLimit = 500;
extern int LineLengthMin = 30;
extern string menucomment = " êîíñîëèäèðîâàíèå ëèíèé ";
extern bool Accumulation = true;
extern double Shift = 200;
extern string menucomment1 = " íàñòðîéêè çèã çàãà ";
extern int ExtDepth = 12;
extern int ExtDeviation = 5;
extern int ExtBackstep = 3;
extern string menucomment2 = " íàñòðîéêè îáû÷íûõ ëèíèé ";
extern color LineColor = Yellow;
extern int LineWidth = 1;
extern int LineStyle = 1;
extern string menucomment3 = " íàñòðîéêè êîíñîëèäèðîâàííûõ ëèíèé ";
extern color LineColor2 = Red;
extern int LineWidth2 = 2;
extern int LineStyle2 = 0;
int i,k,on;
void init() {
int bars=Bars;
if(TimeFrame==0) TimeFrame=Period();
bars/=TimeFrame/Period();
int time1,time2;
double zz,price;
string name;
if(bars>BarsLimit) bars=BarsLimit;
for(i=bars;i>0;i--) {
zz=iCustom(Symbol(),TimeFrame,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
if(zz!=0) {
price=zz;
time1=iTime(Symbol(),TimeFrame,i);
//if(i-LineLength>=0) time2=iTime(Symbol(),TimeFrame,i-LineLength); else time2=time1+LineLength*TimeFrame*60;
for(k=i;k>0;k--) {
if(iOpen(Symbol(),TimeFrame,k)>=zz && iClose(Symbol(),TimeFrame,k)<zz) break;
if(iOpen(Symbol(),TimeFrame,k)<=zz && iClose(Symbol(),TimeFrame,k)>zz) break;
}
time2=iTime(Symbol(),TimeFrame,k);
if(i-k<LineLengthMin && k!=0) continue;
name=StringConcatenate("ZigZag Pivot ",TimeFrame," ",on); on++;
ObjectCreate(name,OBJ_TREND,0,time1,price,time2,price);
ObjectSet(name,OBJPROP_COLOR,LineColor);
ObjectSet(name,OBJPROP_WIDTH,LineWidth);
ObjectSet(name,OBJPROP_STYLE,LineStyle);
ObjectSet(name,OBJPROP_RAY,false);
}
}
if(Accumulation) {
string name2;
int time12,time22;
double price2;
for(i=on-1;i>=0;i--) {
name=StringConcatenate("ZigZag Pivot ",TimeFrame," ",i);
if(ObjectFind(name)<0) continue;
time1=ObjectGet(name,OBJPROP_TIME1);
time2=ObjectGet(name,OBJPROP_TIME2);
price=ObjectGet(name,OBJPROP_PRICE1);
bool cons=false;
for(k=on-1;k>=0;k--) {
if(i==k) continue;
name2=StringConcatenate("ZigZag Pivot ",TimeFrame," ",k);
if(ObjectFind(name2)<0) continue;
time12=ObjectGet(name2,OBJPROP_TIME1);
time22=ObjectGet(name2,OBJPROP_TIME2);
price2=ObjectGet(name2,OBJPROP_PRICE1);
if((time2>time12 && time1<time12) || (time1<time22 && time2>time22)) {
if(MathAbs(price-price2)<=Shift*Point) { cons=true; break; }
}
}
if(cons) {
ObjectDelete(name2);
price=(price+price2)/2;
time1=MathMin(time1,time12);
time2=MathMax(time2,time22);
ObjectSet(name,OBJPROP_TIME1,time1);
ObjectSet(name,OBJPROP_TIME2,time2);
ObjectSet(name,OBJPROP_PRICE1,price);
ObjectSet(name,OBJPROP_PRICE2,price);
ObjectSet(name,OBJPROP_COLOR,LineColor2);
ObjectSet(name,OBJPROP_WIDTH,LineWidth2);
ObjectSet(name,OBJPROP_STYLE,LineStyle2);
ObjectSet(name,OBJPROP_RAY,false);
}
}
}
}
Comments