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

HA+EMA+SMA+BB for Amibroker (AFL)

Rating:
4 / 5 (Votes 13)
Tags:
trading system, amibroker, pattern

harmonic pattern detechtion with moving avg. with BB

approx 70% success ratio

Similar Indicators / Formulas

Auto Analysis Hook Reversal
Submitted by kaiji almost 15 years ago
Candlestick Evaluation
Submitted by olive about 14 years ago
PATTERN WITH CANDLE RAJA
Submitted by rajaswamy about 14 years ago
Book Profit with 101% garanty best modifiyed
Submitted by wiki over 12 years ago

Indicator / Formula

Copy & Paste Friendly
/*                     HARMONIC PATTERN DETECTION                        


Automatic Detection of Harmonic Patterns - Gartley, Bat, Butterfly and Crab. 


*/



_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| chartLogarithmic  | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

_SECTION_BEGIN("Shark");

SBmin = Param("Swing B Min.",0.34,0.3,1,0.01);
SBmax = Param("Swing B Max.",0.95,0.4,1,0.01);
SCmin = Param("Swing C Min.",1.0,1.0,1.2,0.01);
SCmax = Param("Swing C Max.",1.7,1,2.7,0.01);
SDmin = Param("Swing D Min.(XA)",0.7,0.7,1.2,0.01);
SDmax = Param("Swing D Max.(XA)",1.2,1.0,2.7,0.01);

_SECTION_END();
_SECTION_BEGIN("Gartley");

GBmin = Param("Swing B Min.",0.34,0.3,1,0.01);
GBmax = Param("Swing B Max.",0.7,0.4,1,0.01);
GCmin = Param("Swing C Min.",0.34,0.3,1.27,0.01);
GCmax = Param("Swing C Max.",0.92,0.4,1.27,0.01);
GDmin = Param("Swing D Min.(XA)",0.55,0.4,1,0.01);
GDmax = Param("Swing D Max.(XA)",0.82,0.6,1.0,0.01);

_SECTION_END();

_SECTION_BEGIN("Bat");

BatBmin = Param("Swing B Min.",0.34,0.3,1,0.01);
BatBmax = Param("Swing B Max.",0.6,0.4,1,0.01);
BatCmin = Param("Swing C Min.",0.34,0.3,1,0.01);
BatCmax = Param("Swing C Max.",0.94,0.4,1,0.01);
BatDmin = Param("Swing D Min.(XA)",0.8,0.6,1,0.01);
BatDmax = Param("Swing D Max.(XA)",1.2,0.8,1.7,0.01);

_SECTION_END();

_SECTION_BEGIN("Butterfly");

BtBmin = Param("Swing B Min.",0.55,0.3,1,0.01);
BtBmax = Param("Swing B Max.",0.92,0.4,1,0.01);
BtCmin = Param("Swing C Min.",0.34,0.3,1,0.01);
BtCmax = Param("Swing C Max.",0.92,0.7,1,0.01);
BtDmin = Param("Swing D Min.(XA)",1.2,1,1.8,0.01);
BtDmax = Param("Swing D Max.(XA)",2.3,1,3.8,0.01);

_SECTION_END();

_SECTION_BEGIN("Crab");

CBmin = Param("Swing B Min.",0.34,0.3,1,0.01);
CBmax = Param("Swing B Max.",0.92,0.6,1,0.01);
CCmin = Param("Swing C Min.",0.34,0.3,1,0.01);
CCmax = Param("Swing C Max.",0.92,0.6,1,0.01);
CDmin = Param("Swing D Min.(XA)",1.55,1,1.7,0.01);
CDmax = Param("Swing D Max.(XA)",1.7,3.6,2,0.01);

_SECTION_END();

_SECTION_BEGIN("Patterns");

strength = Param("Strength",5,2,15,1);
bu = ParamToggle("Bullish Pattern","Off|On",1);
be = ParamToggle("Bearish Pattern","Off|On",1);

bi = Cum(1)-1;

function GetTop(bars) 
	{
		Top = H == HHV(H,2*bars) AND Ref(HHV(H,bars),bars) < H;
		Top = Top AND LastValue(bi)-ValueWhen(Top,bi) > bars;
		return Top;
	}

function GetValley(bars)
	{
		Valley = L == LLV(L,2*bars) AND Ref(LLV(L,bars),bars) > L;
		Valley = Valley AND LastValue(bi)-ValueWhen(Valley,bi) > bars;
		return Valley;
	}


// Build fractals array

P1 = GetTop(strength);
V1 = GetValley(Strength);

P1 = IIf(P1,IIf(ValueWhen(P1,bi,2) < ValueWhen(V1,bi),P1,IIf(ValueWhen(P1,H,2) > H,False,P1)),P1);
//P1 = IIf(P1 AND ValueWhen(P1,bi,0) > bi,IIf(ValueWhen(P1,bi,0) < ValueWhen(V1,bi,0),IIf(ValueWhen(P1,H,0) >= H,False,P1),P1),P1);
P1 = IIf(P1 AND ValueWhen(P1,bi,0) > bi AND NOT(ValueWhen(V1,bi,0) > 0 AND ValueWhen(V1,bi,0)<ValueWhen(P1,bi,0)),IIf(ValueWhen(P1,H)<=ValueWhen(P1,H,0),False,P1),P1);


V1 = IIf(V1,IIf(ValueWhen(V1,bi,2) < ValueWhen(P1,bi),V1,IIf(ValueWhen(V1,L,2)<L,False,V1)),V1);
//V1 = IIf(V1 AND ValueWhen(V1,bi,0) > bi ,IIf(ValueWhen(V1,bi,0) < ValueWhen(P1,bi,0),IIf(ValueWhen(V1,L,0) <= L, False,V1),V1),V1); 
V1 = IIf(V1 AND ValueWhen(V1,bi,0) > bi AND NOT(ValueWhen(P1,bi,0) > bi AND ValueWhen(P1,bi,0)<ValueWhen(V1,bi,0))  , IIf(ValueWhen(V1,L)>=ValueWhen(V1,L,0),False,V1),V1);


P1H1 = ValueWhen(P1,H);
P1Bar1 = ValueWhen(P1,bi);
P1H2 = ValueWhen(P1,H,2);
P1Bar2 = ValueWhen(P1,bi,2);
V1L1 = ValueWhen(V1,L);
V1Bar1 = ValueWhen(V1,bi);
V1L2 = ValueWhen(V1,L,2);
V1Bar2 = ValueWhen(V1,bi,2);


//Bullish Patterns

PTvalid = (P1Bar1 > V1Bar1 AND V1Bar1 > P1Bar2 AND P1bar2 > V1Bar2) AND P1; // Peaks and troughs are in order

// 4 swings of developing Gartley/Bat etc.

BullGartley4 = PTvalid AND (P1H2-V1L1)/(P1H2-V1L2) > GBmin AND (P1H2-V1L1)/(P1H2-V1L2) < GBmax
				AND (P1H1-V1L1)/(P1H2-V1L1) > GCMin AND (P1H1-V1L1)/(P1H2-V1L1) < GCMax; 

BullBat4 = PTvalid AND (P1H2-V1L1)/(P1H2-V1L2) > BatBmin AND (P1H2-V1L1)/(P1H2-V1L2) < BatBmax
				AND (P1H1-V1L1)/(P1H2-V1L1) > BatCMin AND (P1H1-V1L1)/(P1H2-V1L1) < BatCMax; 

BullButterfly4 = PTvalid AND (P1H2-V1L1)/(P1H2-V1L2) > BtBmin AND (P1H2-V1L1)/(P1H2-V1L2) < BtBMax
				AND (P1H1-V1L1)/(P1H2-V1L1) > BtCmin AND (P1H1-V1L1)/(P1H2-V1L1) < BtCMax; 

BullCrab4 = PTvalid AND (P1H2-V1L1)/(P1H2-V1L2) >CBmin AND (P1H2-V1L1)/(P1H2-V1L2) < CBmax 
				AND (P1H1-V1L1)/(P1H2-V1L1) > CCmin AND (P1H1-V1L1)/(P1H2-V1L1) < CCmax; 

BullShark4 = PTvalid AND (P1H2-V1L1)/(P1H2-V1L2) > SBmin AND (P1H2-V1L1)/(P1H2-V1L2) < SBmax
				AND (P1H1-V1L1)/(P1H2-V1L1) > SCMin AND (P1H1-V1L1)/(P1H2-V1L1) < SCMax; 


// Bullish Gartley/Bat found. D retacement level is not evaluated

BullGartley = IIf(LowestSince(BullGartley4,L) < ValueWhen(BullGartley4,P1H2)-(ValueWhen(BullGartley4,P1H2)-ValueWhen(BullGartley4,V1L2))*GDmin AND
						LowestSince(bullGartley4,L) > ValueWhen(BullGartley4,P1H2)-(ValueWhen(BullGartley4,P1H2)-ValueWhen(BullGartley4,V1L2))*GDmax AND
						HighestSince(BullGartley4,H) <= ValueWhen(BullGartley4,P1H1  ) AND
						LowestSince(bullGartley4,L)==L, True,False);
BullGartley = BullGartley AND LowestSince(BullGartley4,L) < ValueWhen(BullGartley4,V1L1);


BullShark = IIf(LowestSince(BullShark4,L) < ValueWhen(BullShark4,P1H2)-(ValueWhen(BullShark4,P1H2)-ValueWhen(BullShark4,V1L2))*SDmin AND
						LowestSince(bullShark4,L) > ValueWhen(BullShark4,P1H2)-(ValueWhen(BullShark4,P1H2)-ValueWhen(BullShark4,V1L2))*SDmax AND
						HighestSince(BullShark4,H) <= ValueWhen(BullShark4,P1H1  ) AND
						LowestSince(bullShark4,L)==L, True,False);
BullShark = BullShark AND LowestSince(BullShark4,L) < ValueWhen(BullShark4,V1L1);


BullBat = IIf(LowestSince(BullBat4,L) < ValueWhen(BullBat4,P1H2)-(ValueWhen(BullBat4,P1H2)-ValueWhen(BullBat4,V1L2))*BatDmin AND
						LowestSince(BullBat4,L) > ValueWhen(BullBat4,P1H2)-(ValueWhen(BullBat4,P1H2)-ValueWhen(BullBat4,V1L2))*BatDmax AND
						HighestSince(BullBat4,H) <= ValueWhen(BullBat4,P1H1  ) AND
						LowestSince(BullBat4,L)==L, True,False);
BullBat = BullBat AND LowestSince(BullCrab4,L) < ValueWhen(BullCrab4,V1L1);


BullCrab = IIf(LowestSince(BullCrab4,L) < ValueWhen(BullCrab4,P1H2)-(ValueWhen(BullCrab4,P1H2)-ValueWhen(BullCrab4,V1L2))*CDmin AND
						LowestSince(BullCrab4,L) > ValueWhen(BullCrab4,P1H2)-(ValueWhen(BullCrab4,P1H2)-ValueWhen(BullCrab4,V1L2))*CDmax AND
						HighestSince(BullCrab4,H) <= ValueWhen(BullCrab4,P1H1  ) AND
						LowestSince(bullCrab4,L)==L, True,False);
BullCrab = BullCrab AND LowestSince(BullCrab4,L) < ValueWhen(BullCrab4,V1L2);


BullButterfly = IIf(LowestSince(BullButterfly4,L) < ValueWhen(BullButterfly4,P1H2)-(ValueWhen(BullButterfly4,P1H2)-ValueWhen(BullButterfly4,V1L2))*BtDMin AND
						LowestSince(BullButterfly4,L) > ValueWhen(BullButterfly4,P1H2)-(ValueWhen(BullButterfly4,P1H2)-ValueWhen(BullButterfly4,V1L2))*BtDmax AND
						HighestSince(BullButterfly4,H) <= ValueWhen(BullButterfly4,P1H1   ) AND
						LowestSince(bullButterfly4,L)==L, True,False);
BullButterfly = BullButterfly AND LowestSince(BullButterfly4,L) < ValueWhen(BullButterfly4,V1L2);



// to remove redumbdent lines

BullHar4 = BullGartley4 OR BullButterfly4 OR BullBat4 OR BullCrab4 OR BullShark4;
BullHar = BullGartley OR BullButterfly OR BullBat OR BullCrab OR BullShark ;

Point4 = IIf(BullHar,ValueWhen(BullHar4,bi),Null);
BullHar = IIf(BullHar, IIf(Point4 == ValueWhen(BullHar,point4,0) AND ValueWhen(BullHar,bi,0) > bi ,False,BullHar),BullHar);

X = ValueWhen(BullHar4,V1L2);
Xbar = ValueWhen(BullHar4,V1Bar2);
A = ValueWhen(BullHar4,P1H2);
Abar = ValueWhen(BullHar4,P1bar2);
B = ValueWhen(BullHar4,V1L1);
Bbar = ValueWhen(BullHar4,V1bar1);
C1 = ValueWhen(BullHar4,P1H1);
C1bar = ValueWhen(BullHar4,P1bar1);
D = ValueWhen(BullHar,L);
Dbar = ValueWhen(BullHar,bi);
ABdXA = (A-B)/(A-X);
BCdAB = (C1-B)/(A-B);
ADdXA = (A-D)/(A-X);
BCdCD = (C1-D)/(C1-B);

PlotPattern = Dbar > C1bar;
if(LastValue(PlotPattern) AND bu)
{
Plot( LineArray(LastValue(Xbar),LastValue(X),LastValue(Abar),LastValue(A)),"",colorBlue,styleThick);
Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(Bbar),LastValue(B)),"",colorBlue,styleThick);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(C1bar),LastValue(C1)),"",colorBlue,styleThick);
Plot(LineArray(LastValue(C1bar),LastValue(C1),LastValue(Dbar),LastValue(D)),"",colorBlue,styleThick);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Bbar),LastValue(B)),"",colorBlue,styleDashed);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Abar),LastValue(A)),"",colorBlue,styleThick);
Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(C1bar),LastValue(C1)),"",colorBlue,styleDashed);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(Dbar),LastValue(D)),"",colorBlue,styleDashed);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Dbar),LastValue(D)),"",colorBlue,styleDashed);



PlotText(NumToStr(LastValue(ABdXA),1.2),(LastValue(Bbar)+LastValue(Xbar))/2,(LastValue(B)+LastValue(X))/2,colorBlue);
PlotText(NumToStr(LastValue(BCdAB),1.2),(LastValue(C1bar)+LastValue(Abar))/2,(LastValue(C1)+LastValue(A))/2,colorBlue);
PlotText(NumToStr(LastValue(ADdXA),1.2) ,(LastValue(Dbar)+LastValue(Xbar))/2,(LastValue(D)+LastValue(X))/2,colorBlue);
PlotText(NumToStr(LastValue(BCdCD),1.2),(LastValue(Bbar)+LastValue(Dbar))/2,(LastValue(B)+LastValue(D))/2,colorBlue);
}







// Bearish Patterns

PTvalid = (V1Bar1 > P1Bar1 AND P1Bar1 > V1Bar2 AND V1Bar2 > P1Bar2) AND V1;

// Swing 4

BearGartley4 = PTvalid AND (P1H1-V1L2)/(P1H2-V1L2) > GBmin AND (P1H1-V1L2)/(P1H2-V1L2) < GBmax AND
				(P1H1-V1L1)/(P1H1-V1L2) > GCmin AND (P1H1-V1L1)/(P1H1-V1L2) < GCmax;



BearShark4 = PTvalid AND (P1H1-V1L2)/(P1H2-V1L2) > SBmin AND (P1H1-V1L2)/(P1H2-V1L2) < SBmax AND
				(P1H1-V1L1)/(P1H1-V1L2) > SCmin AND (P1H1-V1L1)/(P1H1-V1L2) < SCmax;



BearBat4 = PTvalid AND (P1H1-V1L2)/(P1H2-V1L2) > BatBmin AND (P1H1-V1L2)/(P1H2-V1L2) < BatBmax AND
				(P1H1-V1L1)/(P1H1-V1L2) > BatCmin AND (P1H1-V1L1)/(P1H1-V1L2) < BatCmax;

BearButterfly4 = PTvalid AND (P1H1-V1L2)/(P1H2-V1L2) > BtBmin AND (P1H1-V1L2)/(P1H2-V1L2) < BtBmax AND
				(P1H1-V1L1)/(P1H1-V1L2) > BtCmin AND (P1H1-V1L1)/(P1H1-V1L2) < BtCmax;

BearCrab4 = PTvalid AND (P1H1-V1L2)/(P1H2-V1L2) > CBmin AND (P1H1-V1L2)/(P1H2-V1L2) < CBmax AND
				(P1H1-V1L1)/(P1H1-V1L2) > CCmin AND (P1H1-V1L1)/(P1H1-V1L2) < CCmax;

// Poin D

BearGartley = IIf(HighestSince(bearGartley4,H) > ValueWhen(BearGartley4,V1L2) + (ValueWhen(BearGartley4,P1H2) - ValueWhen(BearGartley4,V1L2))*GDmin AND
				 HighestSince(bearGartley4,H) < ValueWhen(BearGartley4,V1L2) + (ValueWhen(BearGartley4,P1H2) - ValueWhen(BearGartley4,V1L2))*GDMax AND	
				LowestSince(BearGartley4,L) >= ValueWhen(BearGartley4,V1L1  ) AND
				HighestSince(BearGartley4,H) == H, True, False);
BearGartley = BearGartley AND HighestSince(BearGartley4,H) > ValueWhen(BearGartley4,P1H1);



BearShark = IIf(HighestSince(bearShark4,H) > ValueWhen(BearShark4,V1L2) + (ValueWhen(BearShark4,P1H2) - ValueWhen(BearShark4,V1L2))*SDmin AND
				 HighestSince(bearShark4,H) < ValueWhen(BearShark4,V1L2) + (ValueWhen(BearShark4,P1H2) - ValueWhen(BearShark4,V1L2))*SDMax AND	
				LowestSince(BearShark4,L) >= ValueWhen(BearShark4,V1L1  ) AND
				HighestSince(BearShark4,H) == H, True, False);
BearShark = BearShark AND HighestSince(BearShark4,H) > ValueWhen(BearShark4,P1H1);



BearBat = IIf((HighestSince(BearBat4,H) > ValueWhen(BearBat4,V1L2) + (ValueWhen(BearBat4,P1H2) - ValueWhen(BearBat4,V1L2))*BatDmin AND
				 HighestSince(BearBat4,H) < ValueWhen(BearBat4,V1L2) + (ValueWhen(BearBat4,P1H2) - ValueWhen(BearBat4,V1L2))*BatDMax AND	
				LowestSince(BearBat4,L) >= ValueWhen(BearBat4,V1L1 ) AND
				HighestSince(BearBat4,H) == H), True, False);
BearBat = BearBat AND HighestSince(BearBat4,H) > ValueWhen(BearBat4,P1H1);

BearButterfly = IIf(HighestSince(BearButterfly4,H) > ValueWhen(BearButterfly4,V1L2) + (ValueWhen(BearButterfly4,P1H2) - ValueWhen(BearButterfly4,V1L2))*BtDmin AND
				 HighestSince(BearButterfly4,H) < ValueWhen(BearButterfly4,V1L2) + (ValueWhen(BearButterfly4,P1H2) - ValueWhen(BearButterfly4,V1L2))*BtDMax AND	
				LowestSince(BearButterfly4,L) >= ValueWhen(BearButterfly4,V1L1 ) AND
				HighestSince(BearButterfly4,H) == H, True, False);
BearButterfly = BearButterfly AND HighestSince(BearButterfly4,H) > ValueWhen(BearButterfly4,P1H2);

BearCrab = IIf(HighestSince(BearCrab4,H) > ValueWhen(BearCrab4,V1L2) + (ValueWhen(BearCrab4,P1H2) - ValueWhen(BearCrab4,V1L2))*CDmin AND
				 HighestSince(BearCrab4,H) < ValueWhen(BearCrab4,V1L2) + (ValueWhen(BearCrab4,P1H2) - ValueWhen(BearCrab4,V1L2))*CDMax AND	
				LowestSince(BearCrab4,L) >= ValueWhen(BearCrab4,V1L1 ) AND
				HighestSince(BearCrab4,H) == H, True, False);
BearCrab =BearCrab AND HighestSince(BearCrab4,H) > ValueWhen(BearCrab4,P1H2);


BearHar4 = BearGartley4 OR BearButterfly4 OR BearBat4 OR BearCrab4 OR BearShark4 ;
BearHar = BearGartley OR BearButterfly OR BearBat OR BearCrab OR BearShark;

Point4 = IIf(BearHar,ValueWhen(BearHar4,bi),Null);
BearHar = IIf(BearHar, IIf(Point4 == ValueWhen(BearHar,point4,0) AND ValueWhen(BearHar,bi,0) > bi ,False,BearHar),BearHar);

X = ValueWhen(BearHar4,P1H2);
Xbar = ValueWhen(BearHar4,P1Bar2);
A = ValueWhen(BearHar4,V1L2);
Abar = ValueWhen( BearHar4,V1bar2);
B = ValueWhen(BearHar4,P1H1);
Bbar = ValueWhen(BearHar4,P1bar1);
C1 = ValueWhen(BearHar4,V1L1);
C1bar = ValueWhen(BearHar4,V1bar1);
D = ValueWhen(BearHar,H);
Dbar = ValueWhen(BearHar,bi);

ABdXA = (B-A)/(X-A);
BCdAB = (B-C1)/(B-A);
ADdXA = (D-A)/(X-A);
BCdCD = (D-C1)/(B-C1);

PlotPattern = Dbar > C1bar;

if(LastValue(Plotpattern) AND be)

{
Plot( LineArray(LastValue(Xbar),LastValue(X),LastValue(Abar),LastValue(A)),"",colorRed,styleThick);
Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(Bbar),LastValue(B)),"",colorRed,styleThick);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(C1bar),LastValue(C1)),"",colorRed,styleThick);
Plot(LineArray(LastValue(C1bar),LastValue(C1),LastValue(Dbar),LastValue(D)),"",colorRed,styleThick);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Bbar),LastValue(B)),"",colorRed,styleDashed);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Abar),LastValue(A)),"",colorRed,styleThick);
Plot(LineArray(LastValue(Abar),LastValue(A),LastValue(C1bar),LastValue(C1)),"",colorRed,styleDashed);
Plot(LineArray(LastValue(Bbar),LastValue(B),LastValue(Dbar),LastValue(D)),"",colorRed,styleDashed);
Plot(LineArray(LastValue(Xbar),LastValue(X),LastValue(Dbar),LastValue(D)),"",colorRed,styleDashed);

PlotText(NumToStr(LastValue(ABdXA),1.2),(LastValue(Bbar)+LastValue(Xbar))/2,(LastValue(B)+LastValue(X))/2,colorRed);
PlotText(NumToStr(LastValue(BCdAB),1.2),(LastValue(C1bar)+LastValue(Abar))/2,(LastValue(C1)+LastValue(A))/2,colorRed);
PlotText(NumToStr(LastValue(BCdCD),1.2) ,(LastValue(Dbar)+LastValue(Bbar))/2,(LastValue(D)+LastValue(B))/2,colorRed);
PlotText(NumToStr(LastValue(ADdXA),1.2) ,(LastValue(Dbar)+LastValue(Xbar))/2,(LastValue(D)+LastValue(X))/2,colorRed);

}

LatPattern = bullHar OR bearHar;
Lastpattern = LastValue(ValueWhen(LatPattern,IIf(BullGartley,1,IIf(BearGartley,-1,IIf(BullBat,2,IIf(BearBat,-2,
				IIf(BullButterfly,3,IIf(BearButterfly,-3,IIf(BullCrab,4,IIf(BearCrab,-4,IIf(BullShark,5,IIf(BearShark,-5,Null))))))))))));
PatternName = WriteIf(LastPattern == 1,"Bullish Gartley",WriteIf(LastPattern == -1,"Bearish Gartley",WriteIf(LastPattern == 2,"Bullish Bat",
				WriteIf(LastPattern == -2,"Bearish Bat",WriteIf(LastPattern == 3,"Bullish Butterfly",WriteIf(LastPattern == -3,"Bearish Butterfly",
				WriteIf(LastPattern == 4,"Bullish Crab",WriteIf(LastPattern == -4,"Bearish Crab",WriteIf(LastPattern == 5,"Bullish Shark",WriteIf(LastPattern == -5,"Bearish Shark","None"))))))))));


plotFractals = ParamToggle("Plot Fractals","Off|On",1);
if(PlotFractals)
{
	PlotShapes(shapeSmallCircle*P1,colorRed,0,H,10);
	PlotShapes(shapeSmallCircle*V1,colorBlue,O,L,-10);
}

GfxSetTextColor(IIf(LastPattern > 0, colorGreen,colorRed));
GfxTextOut("Last Pattern : " + PatternName,0,20);

Filter = BullHar OR BearHar;
Bull = BullHar; Bear = BearHar;
Color = IIf(Bull,colorGreen,colorRed);
AddColumn(IIf(Bull,1,IIf(Bear,-1,Null)),"Pattern",1.0,colorRed,Color);


Buy=Bull;
Sell=Bear;
Cover=Buy;
Short=Sell;

//PlotShapes(IIf(Buy, shapeCircle, shapeNone),colorGreen); 
//PlotShapes(IIf(Sell, shapeCircle, shapeNone),colorRed);

shape=Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape,IIf(Buy,colorGreen, colorRed),0,IIf(Buy,Low,High));

/*****
** REGULAR PORTFOLIO mode 
** This sample optimization
** finds what is optimum number of positions open simultaneously
** 
****/

SetOption("InitialEquity", 100000 );
SetTradeDelays(1,1,1,1);
RoundLotSize = 1; 

posqty = Optimize("PosQty", 10, 1, 20, 1 );
SetOption("MaxOpenPositions", posqty);

// desired position size is 100% portfolio equity
// divided by PosQty positions

PositionSize = -100/posqty; 
// now additional score 
// that is used to rank equities 
// when there are more ENTRY signals that available
// positions/cash
PositionScore = 100-RSI(); // prefer stocks that have low RSI;

AlertIf( Buy, "SOUND C:\\Windows\\Media\\Chord.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("EMA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("MA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("MA4");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
_SECTION_END();

_SECTION_BEGIN("Bollinger Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
Plot( BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style ); 
Plot( BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style ); 
_SECTION_END();

9 comments

1. kitika

dera sir gud efforts well done but you can more in it put essege box of level and also from where it change reversal….plz try to do this

2. sharps4570

I wish I could look into the future. I’d be rich.

3. viewofmind

@ kitika… thanks for comments i will accept ur comment and i will try for that and released as soon as possible

@ Sharps45 God bless you…

4. kitika

Dear Sir,
i am waiting for 100%accuracy afl in that we should get all things which is require messege box with its level , support and resistance everything from where reversal trend shows all should include in that u need i will help u i am having some afl that can help u to misk and match ….
Thank u listening me and i hope u will do all the best as i hope

5. Sahul Hameed

THANKS

6. madhavareddy1203

Hi Viewof mind..

This is really excellent formula…

im testing this fromula from last week.. its working fine.. but some times its generating very bad signals…. ( at a time multiple signals.. so near).

Can u or any one plz explai how this formula works… how can i tune this formula to help for better results.

Plz explain what logic behind this formula..

thnaks onceagain..

really excellent formulaa..

7. madhavareddy1203

Hi,

When im using this afl in my ami.. its useing more memory.. and responding slowely..

can anybody make this as light version…. now its very heavy.. plz dont change logic…. use same logic and make light version…

10. bhavin8321

Can anyone ell me how to use this system effectively and what time frame and how to follow signals profit booking targets n all…it will be great to know asap…

11. viewofmind

Thanks all.. sorry for late replay was not able to online regularly here…

but i am back with somany other indicator and useful trading code
Gunjan
Investallign

Leave Comment

Please login here to leave a comment.

Back