I'm trying to find and export the peak and trough of a chart to a txt file.
I know how to export to file and other basic things, but I'm having touble with zig zag function.
when you see the output of zig zag function it contains value at every bar count,
helps in plotting a line chart , but i don't want all the data . i only want the extreme edges of that line chart , the Peaks and the Troughs
only those extreme points exported.
You can simply use these functions:
https://www.amibroker.com/guide/afl/peak.html
https://www.amibroker.com/guide/afl/trough.html
If you only want your exploration to produce output when there's a peak or trough, then you have to identify where those occur. Something like this untested snippet should work:
zz = Zig(C,5);
isPeak = zz > Ref(zz,-1) AND zz > ref(zz,1);
isTrough = zz < Ref(zz,-1) AND zz < ref(zz,1);
Filter = isPeak OR isTrough;
AddColumn(zz, "ZigZag Inflection");
You could of course output the peaks and troughs in separate columns if you desire, or add a column to identify whether a value is a peak or a trough. The proof is left as an exercise to the reader.