Skip to main content

Double Top and Bottom Detection for Amibroker (AFL)

isfandi over 15 years ago Amibroker (AFL)

  • Rating:
    2 / 5 (Votes 6)
  • Tags:
    amibroker, exploration, pattern

writing “Top and Bottom” you can view at the wall chart.
hopefully usefull.

Isfandi
Indonesia

Screenshots

Indicator / Formula

Copy & Paste Friendly
_SECTION_BEGIN("Detecting double tops and bottoms");
/* Detecting double tops and bottoms (come into view, by Isfandi)*/ 
percdiff = 5; /* peak detection threshold */ 
fwdcheck = 5; /* forward validity check */ 
mindistance = 10; 
validdiff = percdiff/400; 

PK= Peak( H, percdiff, 1 ) == High; 
TR= Trough( L, percdiff, 1 ) == Low; 


x = Cum( 1 ); 
XPK1 = ValueWhen( PK, x, 1 ); 
XPK2 = ValueWhen( PK, x, 2 ); 
xTR1 = ValueWhen( Tr, x, 1 ); 
xTr2 = ValueWhen( Tr, x, 2 ); 

peakdiff = ValueWhen( PK, H, 1 )/ValueWhen( PK, H, 2 ); 
Troughdiff=ValueWhen( tr, L, 1 )/ValueWhen( tr, L, 2 ); 

doubletop = PK AND abs( peakdiff - 1 ) < validdiff AND (Xpk1 -Xpk2)>mindistance AND High > HHV( Ref( H, fwdcheck ), fwdcheck - 1 ); 
doubleBot=tr AND abs( troughdiff - 1 ) < validdiff AND (Xtr1 -Xtr2)>mindistance AND Low < LLV( Ref( L, fwdcheck ), fwdcheck - 1 ); 

Buy = doublebot; 
Sell = doubletop; 
for( i = 0; i < BarCount; i++ ) 
{ 
if( Buy[i] ) PlotText( "BOT " , i, L[ i ],colorYellow ); 
if( Sell[i] ) PlotText( "TOP" , i, H[ i ], colorWhite ); 
} 


WriteIf( Highest( doubletop ) == 1, "AmiBroker has detected some possible 
double top patterns for " + Name() + "\nLook for green arrows on the price 
chart.", "There are no double top patterns for " + Name() ); 

WriteIf(Lowest( doublebot)==1,"AmiBroker has detected some possible double 
bottom patterns for " + Name() + "\nLook for red arrows on the price 
chart.", "There are no double bottom patterns for " + Name() ); 
_SECTION_END();

18 comments

over 15 years ago

Dear sir, am using AMI-5, the double top-double bottom afl not working in my system AMI-5 not supporting ?? am not know..pls help me… S.SURESH…98424 06366.

2. Alok
over 15 years ago

Even this AFL is not showing any top or bot in the chart it is blank, ami 5.30

3. isfandi
over 15 years ago

Sir.. pls u put the price firsly or u grab this afl into price chart. no prob with Ami 5.3

4. Alok
over 15 years ago

Dear Isfandi,

I did exactly as you said, still does not display anything. using AMi 5.3,

5. Anthony
over 15 years ago

My suggestion change your back ground with black color, so you can see it because the words in White and Yellow color. And don’t forget drag the price first. Have a nice day!

6. isfandi
over 15 years ago

Dear Alok,

I have been change the writing color, if u use background with white color try this a part of formula (copy and paste to similar paragraf), dont forget put the price firstly and try for some stock pic until u find it.

Buy = doublebot; 
Sell = doubletop; 
for( i = 0; i < BarCount; i++ ) 
{ 
if( Buy[i] ) PlotText( "BOT " , i, L[ i ],colorBlue ); 
if( Sell[i] ) PlotText( "TOP" , i, H[ i ], colorRed ); 
} 
8. gopal
over 15 years ago

Hi,

Yes. None of us are able to see this indicator.
Also, the indicator says to look for green and red arrows.But, there is no code for plotting these arrows.

Request you to please post the working formula of this indicator once again for everyone’s benefit.

Thanks,
Gopal

9. isfandi
over 15 years ago

Ok, hope not everyone get same problem, I dont know why can’t show wheres no prob with me, am using 5.3 too

try one’s more:

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Detecting double tops and bottoms");
/* Detecting double tops and bottoms (come into view, by Isfandi)*/ 
percdiff = 5; /* peak detection threshold */ 
fwdcheck = 5; /* forward validity check */ 
mindistance = 10; 
validdiff = percdiff/400; 

PK= Peak( H, percdiff, 1 ) == High; 
TR= Trough( L, percdiff, 1 ) == Low; 


x = Cum( 1 ); 
XPK1 = ValueWhen( PK, x, 1 ); 
XPK2 = ValueWhen( PK, x, 2 ); 
xTR1 = ValueWhen( Tr, x, 1 ); 
xTr2 = ValueWhen( Tr, x, 2 ); 

peakdiff = ValueWhen( PK, H, 1 )/ValueWhen( PK, H, 2 ); 
Troughdiff=ValueWhen( tr, L, 1 )/ValueWhen( tr, L, 2 ); 

doubletop = PK AND abs( peakdiff - 1 ) < validdiff AND (Xpk1 -Xpk2)>mindistance AND High > HHV( Ref( H, fwdcheck ), fwdcheck - 1 ); 
doubleBot=tr AND abs( troughdiff - 1 ) < validdiff AND (Xtr1 -Xtr2)>mindistance AND Low < LLV( Ref( L, fwdcheck ), fwdcheck - 1 ); 

Buy = doublebot; 
Sell = doubletop; 
for( i = 0; i < BarCount; i++ ) 
{ 
if( Buy[i] ) PlotText( "BOT " , i, L[ i ],colorBlue ); 
if( Sell[i] ) PlotText( "TOP" , i, H[ i ], colorRed ); 
} 


WriteIf( Highest( doubletop ) == 1, "AmiBroker has detected some possible 
double top patterns for " + Name() + "\nLook for green arrows on the price 
chart.", "There are no double top patterns for " + Name() ); 

WriteIf(Lowest( doublebot)==1,"AmiBroker has detected some possible double 
bottom patterns for " + Name() + "\nLook for red arrows on the price 
chart.", "There are no double bottom patterns for " + Name() ); 
_SECTION_END();
10. isfandi
over 15 years ago

Please check afl not different, I dont know not show maybe plugins problem.

Ok, I will contribute some plugins with new title “Sharing Plugins” hope finish this problem.

11. isfandi
over 15 years ago

sorry can not post zip file here, pls moderator help us

thanks,
Isfandi

over 15 years ago

Hello

I checked it and it works fine it doesn’t need any plugins. It certainly doesn’t work very well but it works sometimes.

18. niladri
almost 7 years ago

Original code is here https://aflcode.com/double-top-double-bottom-detector-2/

Confirmed working 0n Amibroker 5.6.x

Leave Comment

Please login here to leave a comment.