Drawing upper limit and lower limit when in a range

Hi Guys ,

image

For the above chart i would like to get draw only when bars are in a range . Not sure how to do it . Appreciate if any one can point me or help me
image

You should first define your criteria for that range .. then you can ask for help to express this in AFL

1 Like

True .. But no idea how to start or close . Though its pretty basic someone might have did it . Sorry about that

Range= H-L ;
RangeTop =  O < Ref( Range,-1) and O <  Ref( Range,-2) and O< Ref( Range,-3)  and  C < Ref( Range,-1) and C <  Ref( Range,-2) and  C< Ref( Range,-3 );

But above approach is pretty lame ( i can feel) because its only confined to 3 bars .. Some times it may be 5 to 7 bars .. how i define that .Appreciate any input and help

As you did not specify any objective criteria for that so i put an assumption to define these congestion zones , which is the current bar 's high & low is neither broke up nor down for the next 5 days ( you can later change that from your parameter window )

If that condition is met two horizontal line will be drawn from the high and low of that bar extending rightward for the next 5 bars .. you can test it and put your feedback & notice if you had any ....

Plot(C,"Close",colorDefault,styleBar);
//SetBarsRequired(sbrAll,sbrAll);

Period = Param("Prefered Period For Congestion Zone",5,0,100);



k = 0;
m = 0;
counter = 0;

for ( i = 0 ; i <= BarCount-period-2 ; i++)
{
	for ( z = i ; z <= i+period ; z++)
	{
		if ( High[i] > Close[z+1] AND Low[i] < Close[z+1] AND m < i) {counter = counter +1;} else{counter = 0;}
		if ( counter == period ) 
		{
			k[i] = 1; 	counter = 0;	m = z;
			
			GfxSetZOrder(-1);
			GfxSetCoordsMode(1);
			GfxSelectPen(colorGold);
			GfxMoveTo(i,High[i]);
			GfxLineTo(z,High[i]);
			GfxMoveTo(i,Low[i]);
			GfxLineTo(z,Low[i]);
		}
		//printf(StrFormat("i = %g\tCounter = %g\n",i,Counter));
	}
}

5 Likes

Ive been thinking about it too. I dont know all the details of how im going to implement it, but the path is something like this:

1 - find a swingLow. Its a bool type. Something like SwingL = L < Ref(L,-1) and L < Ref(L,1);
It will create an array that returns 0 or 1.

2 - Mark that bar where SwingL = 1. How to do it? The way my limited knowledge thought was using the indexbar function.

bi = barindex(); //each bar will have a different bi.
LastSwingLIndex = ValueWhen (SwingL, bi, 1); //this will return the bi of the bar where SwingL was true.

3 - Now we need to see if there was any lower bar than our marked SwingL. To do that, i thought of this:

BarsSwingL = bi - LastSwingLIndex //How many bars ago was the LastSwing?
NewSL = L < LLV(L, BarsSwingL); //the actual low is lower than the LastSwing?

Now comes the parto to assign a new value to LastSwingL and so on... still trying to figure it out.

And then you do the same for the swing high.

@amsai also worth looking at

http://amibroker.com/members/traders/08-2018.html

The original,article looked at price consolidation, ATR consolidation and ADX consolidation. But we have only been provided with one of the examples.

1 Like

Can anybody help in adding a Filter and range percentage between upper limit and lower limit.

@Venkatam, Welcome to the Forum.

You will need to get your "Verified Badge" (just search for it and follow the instructions).

As a new member, you may not be aware of the following items.

In essence, it means that you need to search a little bit, read some posts, and understand that there are many very helpful members on the site, BUT, they want to see you putting in some effort to learn this Fantastic Tool that Tomasz has built.

@Venkatam,

Multiple User Accounts is against forum rules!

You will need to get this rectified before being able to do any further posting.