Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Triangle Pattern for Amibroker (AFL)
i4you
over 12 years ago
Amibroker (AFL)

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

When the Triangle formed just enter the share :)

Screenshots

Indicator / Formula

Copy & Paste Friendly
_SECTION_BEGIN("Traingle 2");
function calculatePosition(array,shift)
{
result = Null;
for( i = 0; i < BarCount; i++ )
{
if (array[ i ] == 1)
{
k = i - shift[ i ];
if( k >= 0 AND k < BarCount ) result[ k ] = 1;
}
}
return result;
}
function pattern_func(PLow,bi,t1,t2,t3,AA,AABar,BB,BBBar,CC,CCBar,nbar)
{ 
pattern =
(t3 == 1) AND (t2 == 3) AND (t1 == 2) AND PLow AND
BBBar - AABar > nbar AND CCBar - BBBar > nbar;

return pattern;
}

// E.M.Pottasch, 2/21/2011
// example code triangle fill using arrays

//SetBarsRequired(sbrAll,sbrAll);
bi = BarIndex();
nbar = Param("nbar",7,2,50,1); 

// define fractals
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); 

ll = IIf( PLow AND PLowPrice < Ref(PLowPrice, -1), 1, 0 );
hl = IIf( PLow AND PLowPrice >= Ref(PLowPrice, -1), 2, 0 ); 
lh = IIf( PHigh AND PHighPrice < Ref(PHighPrice, -1), 3, 0 ); 
hh = IIf( PHigh AND PHighPrice >= Ref(PHighPrice, -1), 4, 0 ); 

combi = ll + hl + lh + hh;

t1 = ValueWhen(combi,combi,1); 
t2 = ValueWhen(combi,combi,2); 
t3 = ValueWhen(combi,combi,3); 

AA = ValueWhen(PLow,L,2);
AABar = ValueWhen(PLow,bi,2);
BB = ValueWhen(PHigh,H,1);
BBBar = ValueWhen(PHigh,bi,1);
CC = ValueWhen(PLow,L,1);
CCBar = ValueWhen(PLow,bi,1);

// calculate the end point of the pattern => C
pattern = pattern_func(PLow,bi,t1,t2,t3,AA,AABar,BB,BBBar,CC,CCBar,nbar);

// calculate the starting point of the pattern => A
dBar = IIf(pattern,CCBar-AABar,0);
hhh1 = calculatePosition(pattern,dBar);
// calculate the middle point of the pattern => B
dBar = IIf(pattern,CCBar-BBBar,0);
hhh2 = calculatePosition(pattern,dBar);

// define x-axis range between A-C
rangeAC = Flip(hhh1,pattern);
// define x-axis range between A-B
rangeAB = Flip(hhh1,hhh2);
// define x-axis range between B-C
rangeBC = Flip(hhh2,pattern);

// extend AC
rangeAC = IIf(Ref(rangeAC,-1),Ref(rangeAC,-1),rangeAC);

// now define the legs of the triangle
// AC leg
startval1 = ValueWhen(PLow,L,1); 
endval1 = ValueWhen(PLow,L,0);
startbar1 = ValueWhen(PLow,bi,1); 
endbar1 = ValueWhen(PLow,bi,0); 
aa1 = (endval1-startval1)/(endbar1-startbar1);
bb1 = startval1;
ACLeg = aa1 * (bi - startbar1) + bb1;
ACLeg = IIf(ACLeg AND rangeAC,ACLeg,Null);

// AB leg
startval1 = ValueWhen(PLow,L,1); 
endval1 = ValueWhen(PHigh,H,0); 
startbar1 = ValueWhen(PLow,bi,1); 
endbar1 = ValueWhen(PHigh,bi,0); 
aa1 = (endval1-startval1)/(endbar1-startbar1);
bb1 = startval1;
ABLeg = aa1 * (bi - startbar1) + bb1;
ABLeg = IIf(ABLeg AND rangeAB,ABLeg,Null);

// BC leg
startval1 = ValueWhen(PHigh,H,1); 
endval1 = ValueWhen(PLow,L,0); 
startbar1 = ValueWhen(PHigh,bi,1); 
endbar1 = ValueWhen(PLow,bi,0); 
aa1 = (endval1-startval1)/(endbar1-startbar1);
bb1 = startval1;
BCLeg = aa1 * (bi - startbar1) + bb1;
BCLeg = IIf(BCLeg AND rangeBC,BCLeg,Null);

// define top and bottom array for polygon fill
topLineArray = IIf(ABLeg,ABLeg,BCLeg);
bottomLineArray = ACLeg;
topLineArray = IIf(bottomLineArray AND IsEmpty(topLineArray),bottomLineArray,topLineArray);

// chart
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
Plot( C, "\nPrice",colorBrightGreen, styleCandle );
PlotShapes(shapeSmallCircle*PLow,colorGreen,0,L,-10);
PlotShapes(shapeSmallCircle*PHigh,colorRed,0,H,10);
PlotShapes(IIf(pattern,shapeUpTriangle,shapeNone),colorBrightGreen,0,L,-25);
PlotShapes(IIf(pattern,shapeHollowUpTriangle,shapeNone),colorWhite,0,L,-25);
//Plot(ACLeg,"",colorWhite,styleLine);
//Plot(ABLeg,"",colorWhite,styleLine);
//Plot(BCLeg,"",colorWhite,styleLine);
Plot(topLineArray,"",colorWhite,styleLine);
Plot(bottomLineArray,"",colorWhite,styleLine);

fillOnOff = ParamToggle("Fill Pattern","Fill Off|Fill On",1); 
if (fillOnOff)
{
PlotOHLC(topLineArray,topLineArray,bottomLineArray,bottomLineArray,"", 
colorAqua, styleCloud | styleNoLabel ); 
SetChartBkColor( ParamColor("background",colorBlack)); 
}
_SECTION_END();

8 comments

1. laxmi

sabse bakar

2. guruji

oks

3. parfumeur

Just VERY curious. How can comments be made on an indicator that is not approved or displayed !??

4. administrator

People stumble upon them through google.

5. morgen

“over 3 years ago” and “Indicator has not been approved yet” ?!?!?!

6. administrator

Approved. Looks like it was missed somehow or the user edited it after it was reviewed.

7. ntadi28

Hi, can anyone please guide how to use this AFL,

is it for intra-day? if so what the best time-frame?

8. mandymoore

gives only buy signal,,,,
sir can you please write the same formula for sell signal as well?

Thankyou

Leave Comment

Please login here to leave a comment.

Back