ok will have look later if I can add the additional constraints. Will have to
read article.
Below same type of code as posted earlier however now using the Trough function
instead of "fractals",
regards, Ed
// triple bottom using Trough
// E.M.Pottasch 05/11/10
SetBarsRequired(sbrAll,sbrAll);
percBot = Param("percBot",2,0.05,10,0.05);
percTrough = Param("percTrough",5,0.1,20,0.1);
PLow = Trough(L,percTrough,1) == L;
PLowPrice = ValueWhen(PLow,L);
// bottoms
b1 = ValueWhen(PLow,PLowPrice,1); // most recent bottom
b2 = ValueWhen(PLow,PLowPrice,2); // bottom prior b1
b3 = ValueWhen(PLow,PLowPrice,3); // prior to b2
// triple bottom
trip = IIf(PLow AND 100 * abs(b1 - b2) / (abs(b1 + b2) / 2) < percBot AND 100 *
abs(b2 - b3) / (abs(b2 + b3) / 2) < percBot,1,0);
tripValid = H > ValueWhen(trip,PLowPrice + PLowPrice/100*percTrough);
tripValid = ExRem(tripValid,trip);
entryPrice = Max(O,PLowPrice + PLowPrice/100*percTrough);
//SetChartBkColor(colorblack);
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
Plot(C,"\nLast",colorWhite,styleCandle);
PlotShapes(shapeSmallCircle*PLow,colorWhite,0,L,-10);
PlotShapes(IIf(trip,shapeUpTriangle,shapeNone),colorYellow,0,L,-25);
PlotShapes(IIf(tripValid,shapeUpArrow,shapeNone),colorBrightGreen,0,L,-15);
PlotShapes(IIf(tripValid,shapeHollowSmallCircle,shapeNone),colorWhite,0,entryPrice,0);
PlotShapes(IIf(tripValid,shapeHollowUpArrow,shapeNone),colorWhite,0,L,-15);
From: ford7k
Sent: Tuesday, May 11, 2010 4:49 AM
To: [email protected]
Subject: [amibroker] Re: Request afl for identifying and confirming TRIPPLE
BOTTOM pattern
Dear Edward Pottasch,
I thank you very much for your prompt reply and with a solid solution.It is a
pleasure to see the coding from a different valid angle too.
The fractal thing is a bit new to me and I am digging into that area.
please excuse me for some extra queries.
As per write up I added before,confirmation point,decreasing volume,final price
breakout and volume breakout form the confirmation of tripple bottom. most of
the time, a tripple bottom begins in downtrend and by the time confirmation
point is reached the trend is changed into uptrend.
time period 4 months.upward volume rise on price break thru confirmation point
or highest high of 3 highs is a must.I am trying to check these now manually
though it may not be a clever way of doing it.The other problem is if the three
lows are successively higher or lower,it becomes a triangle pattern.
My basic interest is to spot a tripple bottom and to spot a inverse head and
shoulders pattern.Both are good buy patterns with high success rate.
I really wonder if it is possible to incorporate above conditions into the
coding,in future,to efficiently catch the tripple bottom genuine.
The basic problems have been solved by you already. just adding few salient
conditions will finish the task that is nearly 60% completed by you.
Once again I thank you for your kind efforts to present the code for tripple
bottom that hasnt existed so far in amibroker.
I appreciate and would like to say the initial steps are very difficult to make
but once the direction is set,finetuning the code is rather not so difficult.I
request the other senior experts to kindly help us in this task.
Thanks for your time and efforts,
gratefully
ford
--- In [email protected], "Edward Pottasch" <empotta...@...> wrote:
>
> below an example on how to do it using "fractals". Right click mouse ->
> parameter window allows you to play with the parameters.
>
> see also example chart, rgds, Ed
>
>
> // triple bottom
> // E.M.Pottasch 05/10/10
> SetBarsRequired(sbrAll,sbrAll);
> nbar = Param("nbar",10,2,50,1);
> perc = Param("percentage", 0.15, 0.05, 10, 0.05);
>
> PHigh = H > Ref(HHV(H,nbar),-1) AND Ref(HHV(H,nbar),nbar) < H;
> PHighPrice = ValueWhen(PHigh,H);
> PLow = L < Ref(LLV(L,nbar),-1) AND Ref(LLV(L,nbar),nbar) > L;
> PLowPrice = ValueWhen(PLow,L);
>
> // bottoms
> b1 = ValueWhen(PLow,PLowPrice,1); // most recent bottom
> b2 = ValueWhen(PLow,PLowPrice,2); // bottom prior b1
> b3 = ValueWhen(PLow,PLowPrice,3); // prior to b2
>
> // triple bottom
> trip = IIf(PLow AND 100 * abs(b1 - b2) / (abs(b1 + b2) / 2) < perc AND 100 *
> abs(b2 - b3) / (abs(b2 + b3) / 2) < perc,1,0);
> tripValid = Ref(trip,nbar * -1);
>
> //SetChartBkColor(colorblack);
> GraphXSpace = 5;
> SetChartOptions(0, chartShowDates);
> Plot(C,"\nLast",colorWhite,styleCandle);
> PlotShapes(shapeSmallCircle*PLow,colorWhite,0,L,-10);
> PlotShapes(IIf(trip,shapeUpTriangle,shapeNone),colorYellow,0,L,-25);
> PlotShapes(IIf(tripValid,shapeUpArrow,shapeNone),colorBrightGreen,0,L,-15);
> PlotShapes(IIf(tripValid,shapeHollowSmallCircle,shapeNone),colorWhite,0,C,0);
> PlotShapes(IIf(tripValid,shapeHollowUpArrow,shapeNone),colorWhite,0,L,-15);
>
>
>
>
>
>
>
> From: ford7k
> Sent: Saturday, May 08, 2010 12:27 PM
> To: [email protected]
> Subject: [amibroker] Request afl for identifying and confirming TRIPPLE
> BOTTOM pattern
>
>
>
> Hi Afl coding experts
>
> i AM LOOKING FOR AFL AMIBROKER FORMULA for identifying tripple bottom pattern.
>
> Here is a link for afl to identify double bottom.
> Can an expert code afl for tripple bottom by configuring peak3 and trough3?
>
> The basic rules for tripple bottom are given here, and these need to be
> incorporated into tripple bottom afl.Kindly do the formula coding and oblige.
>
> please ,if it is already available elsewhere,kindly give me the code and link.
> --------------------------
> basis of TB
> http://www.trending123.com/patterns/triple_bottom.html
>
> Triple Bottom Chart Pattern
>
> What does a triple bottom look like?
> Why is this pattern important?
> Is volume important in a triple bottom?
> What are the details that I should pay attention to in the triple bottom?
> How can I trade this pattern?
>
> A triple bottom pattern displays three distinct minor lows at approximately
> the same price level. The triple bottom is considered to be a variation of
> the head and shoulders bottom. Like that pattern, the triple bottom is a
> reversal pattern.
>
> The only thing which differentiates a triple bottom from a head and shoulders
> bottom is the lack of a "head" between the two shoulders. The triple bottom
> illustrates a downtrend in the process of becoming an uptrend. It is,
> therefore, vital to the validity of the pattern that it commence with prices
> moving in a downtrend.
>
> Elaine Yager, Director of Technical Analysis at Investec Ernst and Company in
> New York and a member of Recognia's Board of Advisors goes further to say
> that this pattern must commence with prices moving in a major downtrend - one
> that has lasted for one year or more.
>
> What does a triple bottom look like?
>
> As illustrated below, the triple bottom pattern is composed of three sharp
> lows, all at about the same price level. Prices fall to a support level,
> rise, fall to that support level again, rise, and finally fall, returning to
> the support level for a third time before beginning an upward climb. In the
> classic triple bottom, the upward movement in the price marks the beginning
> of an uptrend.
>
> Investors should note that the three lows tend to be sharp. When prices hit
> the first low, sellers become scarce, believing prices have fallen too low.
> If a seller does agree to sell, buyers are quick to buy at a good price.
> Prices then bounce back up. The support level is established and the next two
> lows also are sharp and quick. Bulkowski points out that the sharp lows are
> often only one-day spikes.
>
> While the three lows should be sharp and distinct, the highs of the pattern
> can appear to be rounded. The pattern is complete when prices rise about the
> highest high in the formation. The highest high is called the "confirmation
> point."
>
> This pattern, the experts warn, can be easily confused with other similar
> patterns. For example, if the center low is lower than the other two, the
> pattern may be a head and shoulders bottom. Also, if the three bottoms are
> successively higher or lower than one another, the pattern may be a triangle
> formation.
>
> Because the pattern is easy to confuse, an investor should look for three
> sharp lows which are well separated and not part of a larger congestion
> pattern. In addition, between the lows, the highs should be fairly rounded in
> shape, although it is not absolutely necessary to the validity of the
> pattern. If the pattern fails to move up and break through the confirmation
> point after reaching the third low, the pattern is not a valid triple bottom.
>
> top
>
> Why is this pattern important?
>
> Like the head and shoulders bottom which it so closely resembles, the triple
> bottom is considered to be a reliable pattern. Bulkowski estimates the
> failure rate to be a low 4%, assuming that an investor waits for the upside
> breakout through the confirmation point.
>
> top
>
> Is volume important in a triple bottom?
>
> Generally, volume in a triple bottom tends to trend downward as the pattern
> forms. Volume tends to be lighter on each successive low. Volume then picks
> up as prices rise above the confirmation point and break into the new upward
> trend.
>
> An investor should not dismiss a triple bottom if volume does not display
> this pattern. The pattern can take several months to form and, during that
> time, volume can be irregular and unpredictable. Volume should be higher at
> the lows than on the days leading to the lows.
>
> top
>
> What are the details that I should pay attention to in the triple bottom?
>
> 1. Duration of the Pattern
> The average formation takes approximately four months to develop. The triple
> bottom is one of the longer patterns to develop. Schabacker and Murphy agree,
> however, that the longer the pattern takes to form, the greater the
> significance of the price move once breakout occurs.
>
> 2. Need for a Downtrend
> The triple bottom is a reversal pattern. This means it is essential to the
> validity of the pattern that it begin with a downward trend in a stock's
> price. As Yager noted above, some experts believe the downtrend must be a
> major one.
>
> 3. Decisive Breakout
> Because a triple bottom can be confused with many other patterns as it is
> developing, experts advise that investors wait for a valid breakout through
> the confirmation point before deciding whether the pattern is a true triple
> bottom. Bulkowski reinforces this message, stating that true triple bottoms
> are quite rare and waiting for a valid breakout is essential before
> determining whether the pattern is a triple bottom.
>
> 4. Volume
> As discussed, it is typical to see volume diminish as the pattern progresses.
> This should change, however, when breakout occurs. A valid breakout should be
> accompanied by a burst in volume. Certain experts are less concerned by
> seeing a steadily diminishing trend in volume as the pattern progresses
> through its three lows.
>
> 5. Pullback after Breakout
> It is very common in the triple bottom to see a pullback after the breakout.
> Bulkowski estimates that 70% of triple bottoms will throw back to the
> breakout price.
>
> top
>
> How can I trade this pattern?
>
> Begin by calculating the target price - the minimum expected price move. The
> triple bottom is measure in a way similar to that for the head and shoulders
> bottom.
>
> Calculate the height of the pattern by subtracting the lowest low from the
> highest high in the formation. Then, add the height to the highest high. In
> other words, an investor can expect the price to move upwards at least the
> distance from the breakout point plus the height of the pattern.
> For example, assume the lowest low of the triple bottom is 200 and the
> highest high is 240. The height of the pattern is 40 (240 - 200 = 40). The
> minimum target price is 280 (240 + 40 = 280).
> Experts agree that triple bottoms are not that common.
>
> Edwards and Magee, for example, stress the necessity for waiting for a valid
> breakout through the confirmation point.However, this is a reliable pattern
> if the pattern has been confirmed by a valid breakout. Pullbacks are common
> with triple bottoms. Investors can use this to their favor advises Bulkowski.
> If prices return to the confirmation point quickly after the breakout (within
> two weeks but no more than a month), Bulkowski suggests that the time to jump
> in is once the prices have turned around again and headed back up.
>
> Investors looking for a valid triple bottom should be wary of a pattern that
> shows a lot of white space as it is developing. The pattern should display a
> fairly regular progression among the three, well-separated lows. Yager
> suggests that the symmetry of this pattern is something that should catch
> your eye.
>
> ====================================================
> DOUBLE BOTTOM CODE AFL
> http://www.amibroker.com/library/detail.php?id=19&hilite=HHV
>
> AND ANOTHER CODE
>
> ======================
> DOUBLE TOP AND DOUBLE BOTTOM DETECTION
> ------------
>
> x = Cum(1);
> per = 5;
> back=50;
> inter=100;
> s11=H;s12=L;
> /* H & S */
> pR = PeakBars( s11, per, 1 ) == 0;
> endt1= LastValue(ValueWhen( pR, x, 1 ));
> medt1=LastValue(ValueWhen( pR, x, 2 ));
> startt1=LastValue(ValueWhen( pR, x, 3 ));
> dt1=endt1-startt1;
> C1=x==endt1 OR x==medt1 OR x==startt1;
> endR = LastValue(ValueWhen( pR, s11, 1 ) );
> medR=LastValue(ValueWhen( pR, s11, 2 ) );
> startR = LastValue( ValueWhen( pR, s11, 3 ));
> Filter1=medR>endR AND medR>startR AND abs(startR-endR)<0.02*(startR+endR) AND
> dt1<inter AND endt1>LastValue(x)-back;
> MaxGraph=10;Graph1=C;Graph1Style=64;GraphXSpace=5;
> /*H&S Neck Line*/
> Aper=medt1-startt1;bper=endt1-medt1;
> La= LastValue(ValueWhen(x==medt1,LLV(L,Aper)));
> Lb=LastValue(ValueWhen(x==-1+endt1,LLV(L,bper)));
> Fa=L==La AND x>startt1 AND x<medt1;
> Fb=L==Lb AND x>medt1 AND x<endt1;
> endt= LastValue(ValueWhen( Fb, x ));
> startt=LastValue(ValueWhen( Fa, x ));
> dtS =endt-startt;endS = Lb;startS = La;
> aS = (endS-startS)/dtS;bS = endS;
> trendlineS = aS * ( x -endt ) + bS;
> Graph3 = IIf(Filter1 AND x>startt-5,trendlineS,-1e10);Graph3BarColor=7;
> /*Inverted H & S*/
> tpR = TroughBars( s12, per, 1 ) == 0;
> tendt1=LastValue(ValueWhen(tpr,x,1));
> tmedt1=LastValue(ValueWhen(tpr,x,2));
> tstartt1=LastValue(ValueWhen(tpr,x,3));
> tdt1=tendt1-tstartt1;
> C2=x==tendt1 OR x==tmedt1 OR x==tstartt1;
> tendR = LastValue(ValueWhen( tpR, s12, 1 ) );
> tmedR=LastValue(ValueWhen( tpR, s12, 2 ) );
> tstartR = LastValue( ValueWhen( tpR, s12, 3 ));
> Filter2=tmedR<tendR AND tmedR<tstartR AND
> abs(tstartR-tendR)<0.02*(tstartR+tendR) AND tdt1<inter AND
> tendt1>LastValue(x)-back;
> Graph1BarColor=IIf(C1 AND Filter1,7,IIf(C2 AND Filter2,10,1));
> /*Inverted H&S Neck Line*/
> tAper=tmedt1-tstartt1;tbper=tendt1-tmedt1;
> Ha= LastValue(ValueWhen(x==tmedt1,HHV(H,tAper)));
> Hb=LastValue(ValueWhen(x==-1+tendt1,HHV(H,tbper)));
> tFa=H==Ha AND x>tstartt1 AND x<tmedt1;
> tFb=H==Hb AND x>tmedt1 AND x<tendt1;
> Rendt= LastValue(ValueWhen(tFb, x ));
> Rstartt=LastValue(ValueWhen( tFa, x ));
> Rdt =Rendt-Rstartt;endR = Hb;startR = Ha;
> aR = (endR-startR)/Rdt;bR = endR;
> trendlineR = aR * ( x -Rendt ) + bR;
> Graph4 = IIf(Filter2 AND x>Rstartt-5,trendlineR,-1e10);Graph4BarColor=10;
> Filter=Filter1 OR Filter2;
> NumColumns=2;/*Graph2=x==-1+tendt1;*/
> Column0=Filter1;
> Column1=Filter2;
> Column0Format=Column1Format=1.0;
> Column0Name="H&S";
> Column1Name="inv H&S";
>
> /* Detecting double tops and bottoms*/
> percdiff = 5; /* peak detection threshold */
> fwdcheck = 5; /* forward validity check */
> mindistance = 10;
> validdiff = percdiff/10;
>
> 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 );
>
> 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=Sell OR Buy ;
>
> AddColumn( IIf( doubletop , 88, 01), "Double TOP", formatChar );
> AddColumn( IIf( doublebot , 88, 01), "Double BOT", formatChar );
>
> =========================
>
> The old afl is given
> coding for peak1,2,bottom1 and 2 already here.
> just code for peak3 and bottom3,add volume condition,breakout cond etc
> A tripple bottom code will be ready.
>
> I am a novice and tried whatever possible.
> From here only an expert can help
> and please help
>
> thanks
> ford
>