I want to mark Pivot High and Pivot Low based on the following logic.

Pivot Low is marked by finding a combination of 3 bars. Lets say Anchor Bar, Bar 1 and Bar 2

The Anchor Bar will be qualified as Pivot Low if Bar 1 and Bar 2 has higher high and higher close compared to the Anchor Bar.

The complication here is that the Bar 1 and Bar 2 need not be the subsequent two bars to the Anchor Bar. They can be 4th and 5th bars or can be 4th and 7th bar to the Anchor Bar.

Reverse logic for the Pivot High (Lower Lows and Lower Close)

How can this be done in AFL? I have tried to compare each and every bar with subsequant bars.....but I think I am doing it wrong and moreover it consumes a lot of CPU time. Anyway I was unable to find the solution. I have tried searching within this forum and outside butunable to find anything that can help me here. It would be of great help if any one can help me or provide me with some pointers that I can refer to.

I am still too new to afl to help you directly in this matter, but it might be worth your time to check the code from @empottasch in the members zone http://www.amibroker.com/members/library/detail.php?id=1349 on "Using fractals to create automatic trendlines". He is defining Highs and Lows like this:

Thanks for your response. But I have already looked in to the script that you have refered. It does not help me to achieve the logic that I have mentioned.

The logic that I have mentioned is different than the fractals.

the way I understand your question is that a pivot low is defined as

the 1-st and the 2-nd bar following the pivot low have a higher high and a higher close
or

the 4-th and the 5-th bar following the pivot low have a higher high and a higher close
or

the 4-th and the 7-th bar following the pivot low have a higher high and a higher close

so if my understanding is correct this can be coded as (see below). But this pivot low will only be known at least 2 bars and at the most 7 bars after the fact.

case1 = H < Ref( H, 1 ) AND C < Ref( C, 1 ) AND H < Ref( H, 2 ) AND C < Ref( C, 2 );
case2 = H < Ref( H, 4 ) AND C < Ref( C, 4 ) AND H < Ref( H, 5 ) AND C < Ref( C, 5 );
case3 = H < Ref( H, 4 ) AND C < Ref( C, 4 ) AND H < Ref( H, 7 ) AND C < Ref( C, 7 );
pivotLow = case1 OR case2 OR case3;
PlotShapes( shapeCircle * pivotLow, ColorBlue, 0, L, -10 );

No... the Bar 1 and Bar 2 can be any bar after the Anchor Bar....not nessarily 4 & 5 or 4 & 7....I was just giving an example...these bars can be any bar after the Anchor Bar.

No worries @empottasch . I too did not clearly mention that it was an example. My apologies for that. Hope you are clear about my problem. Is this can be done?

i was being sarcastic. I would help if I would understand your question. The way I understand it now is that any combnination of 2 bars that come after the anchor bar can define the pivot. It could be bar 1 and 2 after the achor or 4 and 5 or 4 and 7. So also 145 and 5006 after the anchor could define the pivot.

If this is the case then all bars will fulfill the requirement of being the pivot high/low.

So I do not understand it I will leave it for someone else

Once you identify the Bar1 and Bar2 for an Anchor Bar, The anchor bar will become the Pivot Low. After marking the anchor bar as Pivot Low, you must mark for Pivot High (identify its Anchor, Bar 1 and Bar 2). Pivot high and Pivot Low will keep alternating. So not all bars will qualify for that.