Scan for price retesting break-out levels

I’d like to know how can I write an AFL for stocks that retest their previous break-out levels. I’m looking to use that as entry criteria. I’m looking for a retest within 5-10 days from the day of the break-out.

Any help or pointers will be useful. Thanks in advance.


Hi Girish

You’ll first need to define what a “breakout” is. Once you have that, you can use ValueWhen to hold the breakout level, then look for a cross of the level from the other side. BarsSince can be used to limit the number of bars allowed for the retest.

The code below should get you started. It uses the 10 day high as the breakout level, and then a retest is defined as a cross of the Low of a bar back through that level within 10 bars. BreakoutLevel is Ref'd one bar back to avoid the low of the breakout bar giving a retest result.

Google Amibroker + functionname for anything you don’t understand. The user guide links are usually the top result.

BarLimit = 10;
Resistance = Ref(HHV(H, 10), -1);
Breakout = Cross(H, Resistance);
BreakoutLevel = Ref(ValueWhen(Breakout, Resistance), -1);
Retest = Cross(BreakoutLevel, L) AND BarsSince(Breakout) <= BarLimit;

Filter = Breakout OR Retest;
AddColumn(H, "High");
AddColumn(L, "Low");
AddColumn(Breakout, "Breakout", 1);
AddColumn(BreakoutLevel, "BreakoutLevel");
AddColumn(Retest, "Retest", 1);

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) \n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
PlotShapes(Breakout * shapeUpTriangle, colorGreen, 0, Resistance);
PlotShapes(Retest * shapeDownTriangle, colorOrange, 0, L);

Thanks much for your response, HelixTrader.

Will go through the code and try it out as well. Appreciate your response.


Don’t forget to come back and mark the above post as the solution if it works (it’s the check mark below the reply). Alternatively feel free to post your own solution.

Hi @HelixTrader

I need code for, Resistance & Support break, e.g. i will draw a horizontal line as a Resistance on Ami broker on daily chart, if 5 min candle break this resistance then it should give pop-up saying “Resistance break” & vice versa scenario for Support…

You can find (almost) ready to use solution in this article from AB Knowledge base:

Read some additional information in this thread:



Thanks for this link… Really appreciate your efforts…

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.