код зигзага из метатрейдера
Code:
Name := ZigZag

Separate Window := No
First Color := Blue
First Draw Type := Line
Use Second Data := No
]]*/
Inputs: depth(12),deviation(5),backstep(3);
Variables : shift(0),lasthigh(-1),lastlow(-1),lasthighpos(0),lastlowpos(0);
Variables : val(0),back(0),res(0);
Variables : curlow(0),curhigh(0);

SetLoopCount(0);
lasthigh=-1; 
lastlow=-1;

for shift = Bars-300 downto 0
{
//--- low
val=Low[Lowest(MODE_LOW,shift+depth-1,depth)];
if val==lastlow then val=0
else 
{ 
lastlow=val; 
if (Low[shift]-val)>(deviation*Point) then val=0
else
{
for back=1 to backstep
{
res=GetIndexValue(shift+back);
if res!=0 and res>val then SetIndexValue(shift+back,0); 
};
};
}; 
SetIndexValue(shift,val);
//--- high
val=High[Highest(MODE_HIGH,shift+depth-1,depth)];
if val==lasthigh then val=0
else 
{
lasthigh=val;
if (val-High[shift])>(deviation*Point) then val=0
else
{
for back=1 to backstep
{
res=GetIndexValue2(shift+back);
if res!=0 and res<val then SetIndexValue2(shift+back,0); 
}; 
};
};
SetIndexValue2(shift,val);
};

// final cutting 
lasthigh=-1; lasthighpos=-1;
lastlow=-1; lastlowpos=-1;

for shift = Bars-300 Downto 0
{
curlow=GetIndexValue(shift);
curhigh=GetIndexValue2(shift);
if curlow==0 & curhigh==0 then continue;
//---
if curhigh!=0 then
{
if lasthigh>0 then 
{
if lasthigh<curhigh then SetIndexValue2(lasthighpos,0)
else SetIndexValue2(shift,0);
};
//---
if lasthigh<curhigh then
{
lasthigh=curhigh;
lasthighpos=shift;
};
lastlow=-1;
};
if curlow!=0 then
{
if lastlow>0 then
{
if lastlow>curlow then SetIndexValue(lastlowpos,0)
else SetIndexValue(shift,0);
};
//---
if curlow<lastlow | lastlow<0 then
{
lastlow=curlow;
lastlowpos=shift;
}; 
lasthigh=-1;
};
};

for shift = Bars-300 Downto 0
{
res=GetIndexValue2(shift);
if res!=0 then SetIndexValue(shift,res);
};



надеюсь поможет smile

P.S.и вот тут описание http://ta.mql4.com/ru/indicators/trends/zigzag и код для метатрейдера в файле http://codebase.mql4.com/ru/source/12910


Отредактировано Takinava (Fri Sep 10 2010 03:36 PM)