How to reference any proceeding zig-zag trough

The below code snippet produces a basic bar chart with a zig-zag feature added. Can someone please assist me. How to reference any of the proceeding zig-zag troughs.

Thanks Keith

_SECTION_BEGIN("Price");

SetChartOptions(0,chartShowArrows|chartShowDates);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

_SECTION_END();

_SECTION_BEGIN("ZZ");

P1 = ParamField( "ZIG Price field" );

change = Param("% change",5,3,15,0.5); // Param( ''name'', defaultval, min, max, step, sincr = 0 )

Color =(ParamColor("ZZ Wave",coloryellow));

Plot( zz=TEMA(Zig(P1, change),1), _DEFAULT_NAME(), Color, styleLine) ;

_SECTION_END();

You need to use CODE TAGS when posting code. See How to use this site

Properly formatted code should look like this:

_SECTION_BEGIN("Price");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

_SECTION_END();

_SECTION_BEGIN("ZZ");

P1 = ParamField( "ZIG Price field" );
change = Param("% change",5,3,15,0.5); // Param( ''name'', defaultval, min, max, step, sincr = 0 );
Color =(ParamColor("ZZ Wave",coloryellow));
Plot( zz=TEMA(Zig(P1, change),1), _DEFAULT_NAME(), Color, styleLine) ;

_SECTION_END();

@keithwt you should look at these functions:

By the way, I wonder why you are applying a TEMA() - triple exponential moving average - to your ZigZag line with the 'periods' parameter set to 1 that has no effect on the array (the resulting array has the same values as the original one).

2 Likes

Use the Ref() fn.
https://www.amibroker.com/guide/afl/ref.html