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 Amibroker.com 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);
SetChartOptions(0,chartShowArrows|chartShowDates);
_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 ) ) ));
Plot(C,"C",colorBlack,styleCandle);
PlotShapes(Breakout * shapeUpTriangle, colorGreen, 0, Resistance);
PlotShapes(Retest * shapeDownTriangle, colorOrange, 0, L);