Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: ZigZag filter rewrited from scratch in AFL
Author/Uploader: Tintin92 - (email hidden)
Date/Time added: 2004-12-28 17:42:50
Origin:
Keywords:
Level: medium
Flags: indicator

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

ZigZag filter rewrited from scratch in AFL

Formula:


_SECTION_BEGIN("Reversal");
Reversal = Param( _DEFAULT_NAME(), 01.0,0.01,20,0.01);
_SECTION_END();

ZigZArray = Avg;
ZigZArray = Null;

ValFromPro=0;
ValToPro=0;
ValRead=0;

BarFromPro=0;
BarToPro=0;
BarRead=0;

ProcessUndef = 10;
ProcessIncrease = 11;
ProcessDecrease = 12;

Process = ProcessUndef;
ValFromPro=Avg[0];
ValToPro=Avg[0];
BarFromPro=0;
BarToPro=0;
BarRead=0;

function FillLine( startbar, startval, endbar, endval )
{
	for( j = startbar; j <= endbar; j++ )
	{
		ZigZArray[ j ] = startval + (( j - startbar) * (endval-startval)/( endbar -
startbar ));
	}
}

function TrtUndef( )
{
	if ( ValRead > ( ((100 + Reversal)/100 ) * ValFromPro ) )///If rupture
Increase
	{
		Process = ProcessIncrease;
		ValToPro=ValRead;
		BarToPro=BarRead;
	}
	else
	{
		if ( ValRead < ( ((100- Reversal)/100 ) * ValFromPro ) )  // If rupture
Decrease
		{
			Process = ProcessDecrease;
			ValToPro=ValRead;
			BarToPro=BarRead;
		}
		else
		{
			Process = ProcessUndef;
		}
	}
}

function TrtIncrease( )
{
	if ( ValRead > ValToPro )  // Still Increase
	{
		Process = ProcessIncrease;
		ValToPro=ValRead;
		BarToPro=BarRead;
	}
	else   // Break Increase Process
	{
		if ( ValRead <  ( ((100- Reversal)/100 ) * ValToPro ) )   // If break
Decrease
		{
			Process = ProcessDecrease;
			ValFromPro=ValToPro;
			BarFromPro=BarToPro;
			ValToPro=ValRead;
			BarToPro=BarRead;
		}
	}
}

function TrtDecrease( )
{
	if ( ValRead < ValToPro )  // Still Decrease
	{
		Process = ProcessDecrease;
		ValToPro=ValRead;
		BarToPro=BarRead;
	}
	else  // Break Decrease Process
	{
		if ( ValRead >  ( ( (100+ Reversal)/100 ) * ValToPro ) ) // If break
Decrease
		{
   		   Process = ProcessIncrease;
			ValFromPro=ValToPro;
			BarFromPro=BarToPro;
			ValToPro=ValRead;
			BarToPro=BarRead;
		}
	}
}


for( i = 1; i < BarCount; i++ )
{
	ValRead = Avg[i];
	BarRead = i;

	if ( Process == ProcessUndef )
	{
		TrtUndef();
	}
	else
	{
		if ( Process == ProcessIncrease )
		{
			TrtIncrease();
		}
		else
		{
			TrtDecrease();
		}
	}

	if ( BarToPro == BarRead )
		FillLine( BarFromPro, ValFromPro, BarToPro, ValToPro );
	else
		FillLine( BarToPro, ValToPro, BarRead, ValRead );
}


_SECTION_BEGIN("avg");
SetChartOptions(0,chartShowArrows);
Plot( Avg, _DEFAULT_NAME(), ParamColor("Color", colorBlack ),
ParamStyle("Style", styleLine + styleDots, maskPrice ) ); 
_SECTION_END();

 _SECTION_BEGIN("ZigZArray");
Plot( ZigZArray, _DEFAULT_NAME(), ParamColor("Color", colorRed ),
ParamStyle("Style", styleLine + styleThick) ); 
_SECTION_END();

Comments:

john

2004-12-31 04:21:05
Has anybody tried this script without getting errors or are you all on Holidays.
Tomasz Janeczko
tj --at-- amibroker.com
2004-12-31 05:17:38
To the author:

Please DO NOT POST codes that use features available only in beta versions (such as _SECTION_BEGIN/_SECTION_END) because most people do NOT have BETA version installed.
===============

To the users getting Syntax error on this code:
this formula:

You are getting syntax error because this formula uses _SECTION_BEGIN / _SECTION_END functions which are available ONLY IN most recent BETA VERSIONS of AmiBroker (available to registered users only). If you are using version 4.60 or older you must REMOVE all _SECTION_BEGIN / _SECTION_END lines from the code.
Tomasz Janeczko
tj --at-- amibroker.com
2004-12-31 05:23:31
To the author:

If you really have to use new features INCLUDE THE INFORMATION that
your formula REQUIRES BETA version.

Better yet - USE VERSION STATEMENT that is designed SPECIFICALLY FOR THIS
(i.e. to make sure that user is informed about minimum requirements when running given formula).

http://www.amibroker.com/f?version

For example, putting this on the top of your formula

Version(4.65);

Will ensure that user will receive appropriate message when trying to run
given formula on lower versions.
Dan
danzietlow [at] hotmail.com
2005-01-12 02:13:09
I am running beta version 4.66.2, but still get syntax errors at line 39 "{". Anyone else?
Anders
http://www.musikprylar.se
2005-01-19 02:08:47
Try this one, it should work;
==================================================

GraphXSpace=1;
Reversal = Param( "", 01.0,0.01,20,0.01);

ZigZArray = Avg;
ZigZArray = Null;

ValFromPro=0;
ValToPro=0;
ValRead=0;

BarFromPro=0;
BarToPro=0;
BarRead=0;

ProcessUndef = 10;
ProcessIncrease = 11;
ProcessDecrease = 12;

Process = ProcessUndef;
ValFromPro=Avg[0];
ValToPro=Avg[0];
BarFromPro=0;
BarToPro=0;
BarRead=0;

function FillLine( startbar, startval, endbar, endval )
{
for( j = startbar; j <= endbar; j++ )
{
ZigZArray[ j ] = startval + (( j - startbar) * (endval-startval)/( endbar - startbar ));
}
}

function TrtUndef( )
{
if ( ValRead > ( ((100 + Reversal)/100 ) * ValFromPro ) )///If rupture Increase
{
Process = ProcessIncrease;
ValToPro=ValRead;
BarToPro=BarRead;
}
else
{
if ( ValRead < ( ((100- Reversal)/100 ) * ValFromPro ) ) // If rupture Decrease
{
Process = ProcessDecrease;
ValToPro=ValRead;
BarToPro=BarRead;
}
else
{
Process = ProcessUndef;
}
}
}

function TrtIncrease( )
{
if ( ValRead > ValToPro ) // Still Increase
{
Process = ProcessIncrease;
ValToPro=ValRead;
BarToPro=BarRead;
}
else // Break Increase Process
{
if ( ValRead < ( ((100- Reversal)/100 ) * ValToPro ) ) // If break Decrease
{
Process = ProcessDecrease;
ValFromPro=ValToPro;
BarFromPro=BarToPro;
ValToPro=ValRead;
BarToPro=BarRead;
}
}
}

function TrtDecrease( )
{
if ( ValRead < ValToPro ) // Still Decrease
{
Process = ProcessDecrease;
ValToPro=ValRead;
BarToPro=BarRead;
}
else // Break Decrease Process
{
if ( ValRead > ( ( (100+ Reversal)/100 ) * ValToPro ) ) // If break Decrease
{
Process = ProcessIncrease;
ValFromPro=ValToPro;
BarFromPro=BarToPro;
ValToPro=ValRead;
BarToPro=BarRead;
}
}
}


for( i = 1; i < BarCount; i++ )
{
ValRead = Avg[i];
BarRead = i;

if ( Process == ProcessUndef )
{
TrtUndef();
}
else
{
if ( Process == ProcessIncrease )
{
TrtIncrease();
}
else
{
TrtDecrease();
}
}

if ( BarToPro == BarRead )
FillLine( BarFromPro, ValFromPro, BarToPro, ValToPro );
else
FillLine( BarToPro, ValToPro, BarRead, ValRead );
}





Plot( ZigZArray, "ZigZArray", colorBlack, styleLine + styleThick );

Plot( Avg, "Avg", 12, styleLine + styleDots );
salicsale
salicsale [at] yahoo.com
2005-05-04 09:00:38
Thank you thank you thank you !!!
Graham
gkavanagh [at] e-wire.net.au
2005-10-16 21:15:28
Why you have defined a variable twice? AB only remembers the last definition, unless I am missing something
ZigZArray = Avg;
ZigZArray = Null;
you can just say
ZigZArray = Null;
Tintin92

2005-11-12 06:32:02
Why you have defined a variable twice?

I think it is safer to first define a array with a other array than just a null value.
I think it is safer, but I am not sure about it.
A better choice will be to define directly like a Array.
Something like that :
ZigZArray = Array;


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM