So i tried the following code. Testing the S&P 500 from ib in 5 minute an hourly. - It gave no results..
Maci /* Detecting double tops and bottoms*/ percdiff = 20; /* peak detection threshold */ fwdcheck = 2; /* forward validity check */ mindistance = 5; validdiff = percdiff/400; PK= Trough( 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 ); Troughdiff = ValueWhen( PK, H, 1 )/ValueWhen( PK, H, 2 ); Troughdiff=ValueWhen( tr, L, 1 )/ValueWhen( tr, L, 2 ); doubletop = PK AND abs( troughdiff - 1 ) < validdiff AND (Xpk1 -Xpk2)>mindistance AND High > HHVBars( Ref( H, fwdcheck ), fwdcheck - 1 ); doubleBot=tr AND abs( troughdiff - 1 ) < validdiff AND (Xtr1 -Xtr2)>mindistance AND Low < LLVBars( Ref( L, fwdcheck ), fwdcheck - 1 ); Sell = doubletop; Buy = doublebot; 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(Highest( 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() ); Filter=Buy OR Sell; AddColumn( IIf( doubletop , 88, 01), "Double TOP", formatChar ); AddColumn( IIf( doublebot , 88, 01), "Double BOT", formatChar ); AddColumn(Volume,"Volume"); --- In [email protected], "sethbutrue" <[EMAIL PROTECTED]> wrote: > > Thanks for your answer. > > I tried it but it give no signals on an intraday chart back... > > Maci > > > --- In [email protected], "gp_sydney" <gp.investment@> wrote: > > > > From a quick look, start by using the Trough function for PKB instead > > of the Peak function. > > > > Regards, > > GP > > > > > > --- In [email protected], "Hans" <hansib@> wrote: > > > > > > Thank you very much, I did it, but result is not a bottom... > > > something wrong... > > > > > > Here is my new code.... working for Tops... but not for bottoms...: > > > > > > /* Detecting double tops */ > > > percdiff = 5; /* peak detection threshold */ > > > fwdcheck = 5; /* forward validity check */ > > > mindistance = 10; > > > validdiff = percdiff/400; > > > PK= Peak( H, percdiff, 1 ) == High; > > > PKB= Peak( L, percdiff, 1 ) == Low; > > > > > > x = Cum( 1 ); > > > XPK1 = ValueWhen( PK, x, 1 ); > > > XPK2 = ValueWhen( PK, x, 2 ); > > > > > > y = Cum( 1 ); > > > XPKB1 = ValueWhen( PKB, y, 1 ); > > > XPKB2 = ValueWhen( PKB, y, 2 ); > > > > > > peakdiff = ValueWhen( PK, H, 1 )/ValueWhen( PK, H, 2 ); > > > doubletop = PK AND abs( peakdiff - 1 ) < validdiff AND (XPK1 - XPK2) > > > >mindistance AND High > HHV( Ref( H, fwdcheck ), fwdcheck - 1 ); > > > > > > peakdiffb = ValueWhen( PKB, L, 1 )/ValueWhen( PKB, L, 2 ); > > > doublebot = PKB AND abs( peakdiffb - 1 ) < validdiff AND (XPKB1 - > > > XPKB2)>mindistance AND Low < LLV( Ref( L, fwdcheck ), fwdcheck - 1 ); > > > > > > Buy = doubletop; > > > Sell = doublebot; > > > > > > WriteIf( Highest( doubletop ) == 1 OR Lowest(doublebot) > > > ==1 , "AmiBroker has detected some possible double"+ WriteIf( Highest > > > ( doubletop ) == 1," top "," bottom ") + "patterns for " + Name() > > > + "\nLook for green arrows on the price > > > chart.", "There are no double top/bottom patterns for " + name() ); > > > > > > Filter=Highest(doubletop)==1 OR Lowest(doublebot)==1 ; > > > > > > AddColumn( IIf( doubletop , 88, 01), "Double TOP", formatChar ); > > > AddColumn( IIf( doublebot , 88, 01), "Double BOT", formatChar ); > > > > > > > > > ****************** > > > > > > --- In [email protected], "YEA RIGHT" <[EMAIL PROTECTED]> wrote: > > > > You would need to change the lines: PK= Peak( H, percdiff, 1 ) == > > > > HIGH; and peakdiff = ValueWhen( PK, H, 1 )/ValueWhen( PK, H, 2 ); > > > as > > > > well as the HHV line. > > > > > > > > > > > > > > > > --- In [email protected], "Hans" <[EMAIL PROTECTED]> wrote: > > > > > Hello, > > > > > I need some help.... > > > > > I get this code at amibroker/library to get double tops. I tried > > > to > > > > > modify it (Low instead of High and LLV instead of HHV) to > > > > get "double > > > > > Bottoms".... without success. I hope anyone can help me.... > > > > > Many thanks > > > > > Hans > > > > > > > > > > /* Detecting double tops */ > > > > > percdiff = 5; /* peak detection threshold */ > > > > > fwdcheck = 5; /* forward validity check */ > > > > > mindistance = 10; > > > > > validdiff = percdiff/400; > > > > > PK= Peak( H, percdiff, 1 ) == HIGH; > > > > > > > > > > x = Cum( 1 ); > > > > > XPK1 = ValueWhen( PK, x, 1 ); > > > > > XPK2 = ValueWhen( PK, x, 2 ); > > > > > > > > > > peakdiff = ValueWhen( PK, H, 1 )/ValueWhen( PK, H, 2 ); > > > > > doubletop = PK AND abs( peakdiff - 1 ) < validdiff AND (XPK1 - > > > > > XPK2)>mindistance > > > > > AND HIGH > HHV( Ref( H, fwdcheck ), fwdcheck - 1 ); > > > > > buy = doubletop; > > > > > sell = 0; > > > > > > > > > > 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() ); > > > > > grazie > > > > > >
