Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I have found in my archive this formula in Easylanguage, which allows to identify different Harmonic Patterns: Butterfly, ABeCD, Gartley, Crab, etc ..., but Tradestation reports some errors that I do not know how to solve;
if someone can correct the formula,.....I thank you in advance.
{ Indicator style settings: }
p4 Right tic 9
p5 Bar high
p6 Bar low
p7 point
p8 point
p41-p56: line, with checked "Don't automatically connect plot lines
p80 bar high
p81 bar low
p82 bar high
p83 bar low
using elsystem.collections;
using elsystem; 8
{ The pattern rules are from Harmonic Trading Vol 1 & 2, Scott Carney '
}
Method int BatSetup()
var: int setup, double near_r; 6 e) [5 O% J2 l2 j6 t" T
begin " F% g8 a; i) ]: G# d0 ?6 v. K
if patrn[1] <> 0 then return patrn[1]; // another pattern already snagged 3 r$ }% K8 m: |$ {8 F+ J1 r; F
setup = 0;
near_r = NearestFib(ratio("AB","XA")); 1 ?& [7 y' x: Y
If near_r >= .382 and near_r <= .5 then begin
near_r = NearestFib(ratio("BC","AB"));
If near_r >= .382 and near_r <= .886 then begin # g8 L/ H4 T: P% c$ e+ M& W% Y3 l
If True then begin
setup = oo_iff(AA>XX,bat.bullish,bat.bearish) astype int;
targI = CC - 1.618 * (CC - BB);
targO = CC - 2.618 * (CC - BB);
bestConfirm = AA - .886 * (AA - XX);
If ShoABeCD then
targCD = DD-(CC-BB);
end;
end; 8 m7 {; k: Z! p5 ~ v# ]
end; + G, h& m! k8 {' _
Return setup;
end;
Method int BatConfirm()
var: double near_r; , Z$ ?; @( c4 A4 C; i0 R1 O
begin
If Pattern = 0 then return 0; / n. D- p6 _$ G5 Z, z9 g, k! S7 j d
near_r = NearestFib(ratio("CD","BC"));
If near_r >= 1.618 and near_r <= 2.618 then begin ( S; h! u5 J! g, @5 P
//print(date:9:0,time:5:0," ...confirmed Bat");
Return pattern.confirmed;
End else begin
If (DDb - BBb) > 1.5 * (BBb - XXb) then return pattern.failed; // rhs to wide 0 a) ~2 [& ]0 I9 V
Switch pattern begin
Case bat.bullish: 0 ~1 T: _3 i3 E2 v6 F7 k
If CC > AA then return pattern.failed; // might happen after limbo + ]8 o/ n( d/ V) Q& y
If DD < targO then return pattern.failed;
Return pattern.limbo;
Case bat.bearish:
If CC < AA then return pattern.failed; // might happen after limbo & D% T* E! b3 B3 o% o' B
If DD > targO then return pattern.failed;
Return pattern.limbo; ( Q O0 z: O: t
end; % d9 {6 [2 n" p$ @( X' O
end; 9 o$ r4 y3 k9 r* q
Return 0; . Y3 m, M+ Y9 ]: ^2 ~9 V* |7 g
end;
Method int ButterflySetup() : U# h# J: A3 |' Z8 O* w* r
var: int setup, double near_r, double targ; 6 X6 p6 S6 x! S8 P, a
begin
if patrn[1] <> 0 then return patrn[1]; // another pattern already snagged
setup = 0; 2 u" W J* m/ O4 S
near_r = NearestFib(ratio("AB","XA")); + ^ ^/ D4 v, l( P$ U, }
If near_r = .786 then begin ; @5 L- k% _: H0 L# {% Y8 h' Q
near_r = NearestFib(ratio("BC","AB")); 1 G. T* \+ y' S7 q
If near_r >= .382 and near_r <= .886 then begin ) v1 c; \ s1 V) s v9 |
targ = CC - 1.618 * (CC - BB); & X$ x; ^* l& M2 d8 Q, u
If absvalue(AA-XX) < absvalue(AA-targ) then begin 1 s y3 T& ^8 P# T2 B
setup = oo_iff(AA>XX,Butterfly.bullish,Butterfly.bearish) astype int; - r) B; d' I+ I* {
targI = targ;
targO = CC - 2.24 * (CC - BB); & B- y" `8 d/ W' c3 w) G
bestConfirm = AA - 1.27 * (AA - XX);
If ShoABeCD then 9 q" h5 w; z. ~2 }# _, n
targCD = DD-(CC-BB); + C4 p" n+ Q& y# N$ V) y% `: `- F
end;
end;
end;
Return setup;
end; , J* e5 |9 L u
Method int ButterflyConfirm() 1 L$ V+ d+ u9 k: h6 c8 A# Q/ F
var: double near_r;
begin
If Pattern = 0 then return 0;
) c5 J) ^; v$ W8 n( A
near_r = NearestFib(ratio("CD","BC")); ! I2 u/ J- b' k: Y5 @
If near_r >= 1.618 and near_r <= 2.24 then begin ' l7 K1 y; m3 q
//print(date:9:0,time:5:0," ...confirmed Butterfly"); 0 t1 c1 F+ a% H2 k
Return pattern.confirmed; ! Z, a! `! c( a& O3 r
End else begin
If (DDb - BBb) > 1.5 * (BBb - XXb) then return pattern.failed; // rhs to wide , B4 H/ m" c' o2 p% k
Switch pattern begin ' _4 m: W$ [: m! u6 H# ]8 v
Case Butterfly.bullish:
If CC > AA then return pattern.failed; // might happen after limbo
If DD < targO then return pattern.failed;
Return pattern.limbo;
Case Butterfly.bearish:
If CC < AA then return pattern.failed; // might happen after limbo
If DD > targO then return pattern.failed; S4 @4 P7 ]* ~
Return pattern.limbo;
end; - l0 j [1 i' ?; z! X6 Q$ E9 m& T
end;
Return 0;
end;
& x/ Q3 f; C& e; W$ q2 N' s
/////////////////////////////////////////////////////////////////////////////
// GARTLEY 1 ^; l( L" j2 o4 u0 w( {
///////////////////////////////////////////////////////////////////////////// 3 t+ {% L4 w7 i- w* z R, c
e+ M/ Q% e* K X+ y" F
Method int GartleySetup()
var: int setup, double near_r;
begin / V2 T! ?5 l2 t2 K7 g
if patrn[1] <> 0 then return patrn[1]; // another pattern already snagged : G) U; O( E& ^1 Z3 Z
setup = 0; 9 |+ G+ y. Y; q9 T/ | b x
near_r = NearestFib(ratio("AB","XA")); . O6 M& `+ R1 f. T
If near_r = .618 then begin - F. K0 h0 `3 o5 u1 N9 f
near_r = NearestFib(ratio("BC","AB")); 4 m, U( X0 U, |# T9 x
If near_r >= .382 and near_r <= .886 then begin
If True then begin
//print(date:9:0,time:5:0," gartley setup"); & C1 P, }0 a) A
setup = oo_iff(AA>XX,gartley.bullish,gartley.bearish) astype int; 4 }2 ~7 E8 `5 Q% y& z% m
targI = CC - 1.13 * (CC - BB);
targO = CC - 1.618 * (CC - BB);
bestConfirm = AA - .786 * (AA - XX); ! j0 T; S5 }$ B7 m: s7 D9 Y
If ShoABeCD then
targCD = DD-(CC-BB); ( T2 i; g4 Q4 k( F) p+ [ z
end; # K$ z( E3 g$ k
end;
end; , s% _; Y1 S/ q7 q, w
Return setup;
end;
Method int GartleyConfirm()
var: double near_r;
begin
If Pattern = 0 then return 0;
near_r = NearestFib(ratio("CD","BC"));
If near_r >= 1.13 and near_r <= 1.618 then begin
//print(date:9:0,time:5:0," ...confirmed gartley");
Return pattern.confirmed; & O: |/ F! _2 r6 v \
End else begin - H( V: w& V$ F" a: Y! V! S) X
If (DDb - BBb) > 1.5 * (BBb - XXb) then return pattern.failed; // rhs to wide
Switch pattern begin
Case gartley.bullish: " K% a+ j ~# F% d: J' x
If CC > AA then return pattern.failed; // might happen after limbo
If DD < targO then return pattern.failed;
Return pattern.limbo; 9 Q2 U# w4 Q% W; y% `
Case gartley.bearish: , m Y' e7 {6 s0 P
If CC < AA then return pattern.failed; // might happen after limbo ; Y6 k" u) M+ f2 h4 H. I
If DD > targO then return pattern.failed; ( e4 _1 ?( Q& ]6 X h: b" C0 o
Return pattern.limbo; ( p: m, j& t$ e" h1 ?4 [
end; 1 ~9 H( K3 |9 O3 T2 e
end; 2 c1 ~ Y9 T2 R6 D: N; |
Return 0; : }3 H$ `1 D, Q/ I9 G
end;
/////////////////////////////////////////////////////////////////////////////
// CRAB : g7 b, U3 f6 f4 z* i' E
///////////////////////////////////////////////////////////////////////////// : ~# I) N, C. v3 z" p2 A
Method int CrabSetup()
var: int setup, double near_r, double targ; + L/ E }4 u6 {' ^6 {) n& r
begin 0 z2 l) m# r, C& O7 R5 u& y
if patrn[1] <> 0 then return patrn[1]; // another pattern already snagged D( G+ m y% A3 r, [( Z! C$ z
setup = 0; " a5 E% `3 w; f% f' i
near_r = NearestFib(ratio("AB","XA"));
If near_r >= .382 and near_r <= .618 then begin
near_r = NearestFib(ratio("BC","AB"));
If near_r >= .382 and near_r <= .886 then begin " S: r+ N# f' x! c, E2 q4 c6 F$ s( l/ c
targ = CC - 2.618 * (CC - BB);
If absvalue(AA-XX) < absvalue(AA-targ) then begin
//print(date:9:0,time:5:0," crab setup"); - H) ?% ~8 h7 P
setup = oo_iff(AA>XX,crab.bullish,crab.bearish) astype int; . j% Y$ ^$ |/ Q0 k# y% P% {
targI = targ; //CC - 2.618 * (CC - BB); 7 B7 r. Z: g# S+ k8 x; G' ]
targO = CC - 3.618 * (CC - BB); * X# ?% t: y4 j! X% k8 W1 D3 {4 n
bestConfirm = AA - 1.618 * (AA - XX); 9 |4 g* Q3 U, ~0 Z" n+ s% G
If ShoABeCD then 8 q8 K2 A; j0 g" g
targCD = DD-(CC-BB); b3 H5 v* H; ~8 |6 D2 P" N. H
end; - f$ B) i- Y6 w# C
end; 7 _2 e, R- d* ^; [( w+ W
end;
Return setup;
end;
Method int CrabConfirm() - W" W6 G, ~0 L5 s5 B! v
var: double near_r; 5 l- U* }( }; O% G) z
begin
If Pattern = 0 then return 0; 2 l" q: Q7 G* F# d1 X& T
. \+ y6 l9 p6 I" h; W: b9 V
near_r = NearestFib(ratio("CD","BC"));
If near_r >= 2.618 and near_r <= 3.618 then begin
//print(date:9:0,time:5:0," ...confirmed crab");
Return pattern.confirmed;
End else begin ; V5 g/ w) O, T
If (DDb - BBb) > 1.5 * (BBb - XXb) then return pattern.failed; // rhs to wide
Switch pattern begin
Case crab.bullish: 2 j$ {" W& Z, _9 K8 W
If CC > AA then return pattern.failed; // might happen after limbo ! U m) U1 L6 Q: A, o- b
If DD < targO then return pattern.failed; " e/ [2 D. `2 A6 g: j' {8 @
Return pattern.limbo;
Case crab.bearish: " a1 u$ q$ @5 ~0 I7 f! E- P
If CC < AA then return pattern.failed; // might happen after limbo
If DD > targO then return pattern.failed; ' L% a% \$ h) Q2 W
Return pattern.limbo;
end; 6 }% [2 P& G" I
end; * I( } {' E J3 V5 ]0 n
Return 0;
end;
///////////////////////////////////////////////////////////////////////////// 4 _3 L5 S) i7 [: D
// DEEP CRAB
/////////////////////////////////////////////////////////////////////////////
Method int DeepCrabSetup() 9 Z w* Q" S$ S9 h) q' R
var: int setup, double near_r, double targ;
begin
if patrn[1] <> 0 then return patrn[1]; // another pattern already snagged
setup = 0; 5 @ u, b+ u9 O5 N U/ ~" ^' J2 O
near_r = NearestFib(ratio("AB","XA")); 0 C$ {5 b& v i/ _" w$ e6 F; D) c; g
If near_r = .886 then begin 0 @+ h" {% W a3 p0 I- s" Z
near_r = NearestFib(ratio("BC","AB")); 1 }9 m7 ^6 B: [; m
If near_r >= .382 and near_r <= .886 then begin 5 v; W3 U1 K8 T# e
targ = CC - 2.24 * (CC - BB); ( ]9 U/ s$ z& I7 i/ }
If absvalue(AA-XX) < absvalue(AA-targ) then begin ! m0 v7 B/ s/ Q- l4 I% b
setup = oo_iff(AA>XX,DeepCrab.bullish,DeepCrab.bearish) astype int; % w6 k8 r( u2 V
targI = targ; //CC - 2.618 * (CC - BB); 5 o# z0 H# @4 H c, M0 f- C2 v
targO = CC - 3.618 * (CC - BB);
bestConfirm = AA - 1.618 * (AA - XX);
If ShoABeCD then / k+ y. Z; }8 u9 P: v
targCD = DD-(CC-BB);
end; 2 [# S$ J# f1 z N. @6 g
end; / s. h& W V3 N8 ]
end;
Return setup; ( a; X+ `+ u- s# r6 ~) D
end;
Method int DeepCrabConfirm() ; ^. V- P& \6 a3 @; F5 R* g9 a' {" z, d
var: double near_r; 5 F( c5 x8 S9 D+ n2 b Q
begin
If Pattern = 0 then return 0;
near_r = NearestFib(ratio("CD","BC"));
If near_r >= 2.24 and near_r <= 3.618 then begin # L& \0 i6 h* e1 T( `5 E
//print(date:9:0,time:5:0," ...confirmed DeepCrab");
Return pattern.confirmed; 9 ?! T: L. U* I% v* Q: ^
End else begin
If (DDb - BBb) > 1.5 * (BBb - XXb) then return pattern.failed; // rhs to wide 8 G. s; Z4 \* @- a6 w
Switch pattern begin + q. b2 F3 D( x# G9 L
Case DeepCrab.bullish: " N7 V) A. w$ A; I3 N
If CC > AA then return pattern.failed; // might happen after limbo ' C8 I* i _, B P" X8 K
If DD < targO then return pattern.failed; ; C. h t/ _% h0 Z0 W4 W4 D# C
Return pattern.limbo; 1 v6 Y. Z/ V. X! T
Case DeepCrab.bearish:
If CC < AA then return pattern.failed; // might happen after limbo ) \* h9 X9 g1 H5 z7 I n3 V5 |
If DD > targO then return pattern.failed;
Return pattern.limbo;
end;
end; 0 K! H* X* Y- s3 C8 v" T- [
Return 0;
end; + r9 T# W7 _/ l# R% b' s6 |! D
* N* b8 K; z" v, {5 N+ p
///////////////////////////////////////////////////////////////////////////// [/ H2 e$ T5 O
// FIVE OH 6 }* v1 f0 t. |6 s$ R
///////////////////////////////////////////////////////////////////////////// % g% q F4 n* Q3 u# h2 A
Method int FiveOhSetup() ! K0 G$ [4 |* z& H
var: int setup, double near_r;
begin " l) d! \7 \8 i5 H! s3 S& ^9 t
if patrn[1] <> 0 then return patrn[1]; // another pattern already snagged
setup = 0;
near_r = NearestFib(ratio("AB","XA"));
If near_r >= 1.13 and near_r <= 1.618 then begin / B% E' d6 Y" ~1 `0 T
near_r = NearestFib(ratio("BC","AB")); 0 W4 U) h. V) h; N
If near_r >= 1.618 and near_r <= 2.4 then begin
If True then begin + z" Y m1 |' C7 p. R2 f G& e
setup = oo_iff(CC>BB,FiveOh.bullish,FiveOh.bearish) astype int; - H ^: d) g/ x6 J! c
targI = CC - .5 * (CC - BB); 3 N4 ~1 e D( R# I# o U; U0 x: ^' ^
targO = 0; 8 ` O" Q8 S) b* T
bestConfirm = 0; //CC - .5 * (BB - CC); % X: P0 _/ d: z' B* |
If ShoABeCD then : S9 ^+ p' d& t" n/ e2 ?
targCD = 0; . D W( B4 J. A+ j) y& @. K5 u, Z
end;
end; 9 D8 l* P) P4 M5 O$ M |) ]/ \- K
end; 9 T8 ?' T# R- l. R& S& O# L# P
Return setup; . z2 M3 N- ~) O) `* K, T) ?
end; ! H* e. C; [9 X) N! F# ?" G
Method int FiveOhConfirm()
var: double near_r;
begin ! R8 M. P1 T/ I) Z$ ]0 \9 c
If Pattern = 0 then return 0;
near_r = NearestFib(ratio("CD","BC")); 9 J: P2 v( r5 w& w! W
//If near_r = .5 then begin BOOK VALUE 1 a" B- n+ n3 z# Z
If near_r >= .382 and near_r <= .618 then begin // TESTING VALUE
//print(date:9:0,time:5:0," ...confirmed FiveOh"); 2 V& ^$ c" _3 c2 g; e
Return pattern.confirmed; . D' U' O6 u0 Y
End else begin
If (DDb - BBb) > 1.5 * (BBb - XXb) then return pattern.failed; // rhs to wide 7 m1 g" h- h0 Z; t0 D! p/ V
Switch pattern begin
Case FiveOh.bullish:
If CC > AA then return pattern.failed; // might happen after limbo
If DD < targO then return pattern.failed;
Return pattern.limbo; , \: W- A& e, S) o
Case FiveOh.bearish: $ L( p5 R3 n7 [# }
If CC < AA then return pattern.failed; // might happen after limbo 0 R5 G* W. J6 f4 V
If DD > targO then return pattern.failed;
Return pattern.limbo; . m! A4 d/ i8 `
end;
end; ) r) v0 A l( V+ h* k3 u" s" p4 z
Return 0;
end; ; k$ T, l5 h1 C
. h4 b! k+ `+ g
/////////////////////////////////////////////////////////////////////////////
// COMMON METHODS 3 U6 `+ j, g4 a0 ?1 V, k$ w
///////////////////////////////////////////////////////////////////////////// - P7 R5 F0 q5 u
Method double oo_iff( bool q, double valu1, double valu2 ) , t: d( h. b- U4 z
begin 1 q9 [& r' ^7 S! _: x
if q then return valu1 else return valu2; 6 I+ a: P4 `) Z- a$ j
end;
Method int oo_dark(int colr, double darkfac)
var: int oRed, int oGreen, int oBlue; " m% z" m" U) ^. M$ i$ n |
begin
if colr = -1 then return colr;
oRed = GetRValue(colr);
oGreen = GetGValue(colr);
oBlue = GetBValue(colr); $ }( c! [9 ?+ a3 T$ C' ]% {
if darkfac <= 1 then return rgb( darkfac * oRed, darkfac * oGreen, darkfac * oBlue ) ^: \4 x' f( s+ B1 I4 ?5 D. D
else return rgb(oRed+(darkfac-1)*(255-oRed),oGreen+(darkfac-1)*(255-oGreen),oBlue+(darkfac-1)*(255-oBlue));
end; 1 L3 _4 i9 B1 g& }" O2 A* W5 i( u
Method int oo_PlotString( double price, string ss, int colr, int barsb, int han ) - t3 V. \) S/ {7 f6 ~2 O- E
var: int newhan; / Q, l! B0 Z" K: I
begin , T8 N/ @1 ^" d, U1 a+ s
newhan = -1; * ^" w! ~1 Q, t, t
If han = -1 then begin
newhan = text_new( date[barsb], time[barsb], price, ss ); + N+ E2 ]; I% [
text_setcolor( newhan, colr );
text_setstyle( newhan, 1, 2 );
return newhan; 3 ?- x9 N' S0 s3 L+ P- n7 K' A) }
End else begin
text_setstring( han, ss ); 7 \( `0 E7 f% l! b! w& a
Text_setlocation( han, date[barsb], time[barsb], price ); 0 J& t1 @7 c& x9 O o& V8 [1 J
text_setcolor( han, colr ); 1 Y7 s( u* |" M1 X3 ~
text_setstyle( han, 1, 2 );
return han; ' b3 H- ^) J7 G$ m
end; * y) d) T* _: c$ S3 ]* T, ?
end;
Method void PlotLine(int lin, double y1, int x1, double y2, int x2, int colr, int siz)
var: int ii, int xii, int dx, double valu, int vcolr; 6 W& ^9 f9 x6 V. l
begin 3 @9 \$ ^; T; B3 S9 ?. r
dx = x2 - x1; / M) Y& R3 ~# r4 R1 c1 N: D
vcolr = colr;
for ii = 0 to dx begin 1 A% u/ S) ~: E# t+ {3 i) B
xii = ii + (currentbar - x2);
valu = y2-ii*(y2-y1)/dx; + d- `7 i C( ~' t* U' V Z g
switch lin begin 8 S; ]5 x+ Z" ^/ y7 g) k7 C
case 0: plot41[xii](valu,"p41",vcolr,default,siz); ) a: `1 [1 s0 y; d
case 1: plot42[xii](valu,"p42",vcolr,default,siz);
case 2: plot43[xii](valu,"p43",vcolr,default,siz);
case 3: plot44[xii](valu,"p44",vcolr,default,siz);
case 4: plot45[xii](valu,"p45",vcolr,default,siz); : b' E' `; v* a5 K6 b% ]+ A+ A
case 5: plot46[xii](valu,"p46",vcolr,default,siz);
end; 7 D$ y, p: o7 h3 B( N% s7 `: S; M2 ~' S8 X
end;
end;
var: max_B(500); ' y# \4 d+ L+ \3 G) b) F
var: IsTriangle(true); ; }) f' a& R! L% _; R& W( _7 U
var: chkShowBars.Checked(true); * h/ Z/ _7 h& s* N4 Z7 O
Method void FillTriangle(int fil, double y3, int x3, double y2, int x2, double y1, int x1, int colr) }# c7 c5 Z/ c
var: double dy12, double dy13, double dy23, int ii, int ij, int vcolr, int siz,
int bb, double minl, double maxl;
begin
siz = GetAppInfo(aibarspacing) astype int - 1;
vcolr = colr;
if colr = black then return;
if x2-x1 > 0 then dy12 = (y2-y1)/(x2-x1);
if x3-x1 > 0 then dy13 = (y3-y1)/(x3-x1); ' p, V, C( J8 d; @! v
if x3-x2 > 0 then dy23 = (y3-y2)/(x3-x2);
switch fil begin
case 0:
for ii = 0 to x2-x1 begin . |8 m3 b" H$ f$ S& T! d! v
bb = currentbar-x1-ii;
plot80[bb](y1+ii*dy13,"p80",vcolr,default,siz);
plot81[bb](y1+ii*dy12,"p81");
If chkShowBars.Checked then begin 6 b) u( n5 r& ~2 [+ t/ z: u
Minl = minlist(y1+ii*dy12, y1+ii*dy13);
Maxl = maxlist(y1+ii*dy12, y1+ii*dy13); $ N# O7 E/ G1 ^2 ?
If ShoBars then begin
If c[bb] > minl and c[bb] < maxl then
plot4[bb](c[bb],"p4");
If L[bb] < maxl And h[bb] > minl then begin
plot5[bb](minlist(maxl,h[bb]),"p5");
plot6[bb](maxlist(minl,l[bb]),"p6"); $ T2 J a' h; K( ]- `' i% u- v. n, r
end; 5 h2 B8 t% V+ h
end;
end; 7 N; D- b1 k6 c, J
end; ?* v. ?8 H" d% b: T$ h* h% k Z
for ii = 0 to x3-x2 begin
bb = currentbar-x3+ii;
plot80[bb](y3-ii*dy13,"p80",vcolr,default,siz);
plot81[bb](y3-ii*dy23,"p81");
If chkShowBars.Checked then begin
Minl = minlist(y3-ii*dy13, y3-ii*dy23);
Maxl = maxlist(y3-ii*dy13, y3-ii*dy23);
If ShoBars then begin 4 I/ P- m4 J$ H' j
If c[bb] > minl and c[bb] < maxl then / G% V" F8 w6 S% S; }
plot4[bb](c[bb],"p4");
If L[bb] < maxl And h[bb] > minl then begin
plot5[bb](minlist(maxl,h[bb]),"p5"); - P; p/ T0 c% o+ a* F
plot6[bb](maxlist(minl,l[bb]),"p6");
end;
end; " q* z3 W1 ^ R9 E6 m
end; / L# A# Q+ H; a+ h5 ^
end;
case 1: ;
for ii = 0 to x2-x1 begin 8 d& z1 _7 z# K* \1 h# ]" H
bb = currentbar-x1-ii;
plot82[bb](y1+ii*dy13,"p82",vcolr,default,siz);
plot83[bb](y1+ii*dy12,"p83"); $ o* p+ {1 X/ ]3 ]: N0 a
If chkShowBars.Checked then begin , {+ L, g P% _% g) X
Minl = minlist(y1+ii*dy13, y1+ii*dy12); " m u6 l" {# O6 t" q& B) d
Maxl = maxlist(y1+ii*dy13, y1+ii*dy12);
If ShoBars then begin
If c[bb] > minl and c[bb] < maxl then 3 b) q( e0 S) F& J3 e9 x; r
plot4[bb](c[bb],"p4"); 7 E! @4 i* @1 h2 `, m! Z
If L[bb] < maxl And h[bb] > minl then begin
plot5[bb](minlist(maxl,h[bb]),"p5"); - I) M6 S- N6 N t- ^. ?# ?5 i
plot6[bb](maxlist(minl,l[bb]),"p6"); $ ]+ B- \' D) m. l J8 N
end; 6 l: Z$ P; v; L2 m' c
end; ) q' E! U6 g; D
end;
end; # \) T" K" \1 H) J. F {
for ii = 0 to x3-x2 begin
plot82[currentbar-x3+ii](y3-ii*dy13,"p82",vcolr,default,siz);
plot83[currentbar-x3+ii](y3-ii*dy23,"p83");
end;
end;
end;
///////////////////////////////////////////////////////////////////////////// ( L' o- p& G4 B! r: X
// LOCAL METHODS & V. _, r- S" y4 B& f; U% ~
/////////////////////////////////////////////////////////////////////////////
Method double Ratio(string top, string bot) % e$ g4 o' n# ~* \. B3 t; [
var: double dtop, double dbot, double rat; 7 k% u0 Y1 ]( D) g- Z4 n
Begin
rat = 0; ' j0 q2 Q8 d: q
Switch top begin 2 v2 @( J9 N! e# ]& A
Case "XA","AX": dtop = XX - AA;
Case "AB","AB": dtop = AA - BB; & n' A5 T5 C2 s, b" T
Case "BC","CB": dtop = BB - CC;
Case "CD","DC": dtop = CC - DD;
Case "AC","CA": dtop = AA - CC;
Case "XD","DX": dtop = XX - DD;
end;
Switch bot begin
Case "XA","AX": dbot = XX - AA;
Case "AB","AB": dbot = AA - BB;
Case "BC","CB": dbot = BB - CC; ; I7 S& K6 O( b& J" D0 s
Case "CD","DC": dbot = CC - DD;
Case "AC","CA": dbot = AA - CC;
Case "XD","DX": dbot = XX - DD;
end;
If dbot <> 0 then rat = absvalue(dtop/dbot); / m. I" I% R5 ?9 m% b4 s
Return rat;
end;
* ]+ G9 |& z2 l) ?
array: fibs[100](0);
var: fibs.count(0); 1 s; {/ |# q, {" n. y) J
method void InitFibs() , B( P7 J5 p6 M( O$ ~
var: int ii, int ij; : {0 `6 a9 c3 z3 w! Z* d4 r
begin
ii = 0;
// primary $ a: ^; _3 S7 L6 l* w' ]* {
fibs[ii] = .618; ii += 1;
fibs[ii] = 1.618; ii += 1;
// primary derived 4 K. m2 ~- A5 V" ~) a7 @% Q5 O
fibs[ii] = .786; ii += 1; 9 V, n( l/ M* X0 z) O ^
fibs[ii] = .886; ii += 1; & u% u" j3 ~2 [$ g. K0 x4 A: r, | j
fibs[ii] = 1.13; ii += 1; 2 E9 l4 r/ K$ N
fibs[ii] = 1.27; ii += 1; 7 Q5 q5 A0 W# x
// complementary derived
fibs[ii] = .382; ii += 1; 5 z4 C4 A- t% b* M- t3 H! i
fibs[ii] = .500; ii += 1;
fibs[ii] = .707; ii += 1; 7 R) w+ Q0 s% L$ K
fibs[ii] = 1.41; ii += 1;
fibs[ii] = 2.0; ii += 1;
fibs[ii] = 2.24; ii += 1; 3 Z u7 ?' n( [/ e+ |, |4 C
fibs[ii] = 2.618; ii += 1; * q7 b7 B( B' P8 \4 E; ^
fibs[ii] = 3.14; ii += 1; * q i- `2 D( u* g% M, t4 A& z* G
fibs[ii] = 3.618; ii += 1; . b& `2 H, B3 X7 m( d
fibs[ii] = 4.618; ii += 1; 0 p3 I7 j- a0 C
fibs.count = ii; 3 U! A* u- w: D7 l' U, K
end;
const: fnear(.07);
method double NearestFib(double valu)
var: int ii;
begin
for ii = 0 to fibs.count - 1 begin % f. u' Q# p- t# E/ s) C
if valu < fibs[ii] * (1+fnear) and valu > fibs[ii] * (1-fnear) then begin
return fibs[ii]; 1 ]3 w& D) W6 C
end;
end; 6 @* F& d! C% r( `5 W
return valu; 0 S" D' W2 R' ~/ K7 c& ~
end; * v. `7 X6 n4 X9 v9 R" d7 q" _3 J
///////////////////////////////////////////////////////////////////////////// 0 C: Q$ i2 d7 a7 @7 J( [ Z& T
// FOR DEBUGING ) }8 a# L2 p3 _: K
///////////////////////////////////////////////////////////////////////////// 9 A8 L" s# I; q/ N9 F% a( {5 p
once begin
var: handl(0), ss(""), itxt(0);
array: date1[20](0), time1[20](0), price1[20](0), MyDir[20](0);
handl = text_getfirst(2);
while handl >= 0 begin
ss = upperstr(text_getstring(handl)); 6 k0 \: A, I3 `0 `( n! N# _
if ss = "BREAK" then begin 6 M- s9 A* d9 i7 z- }
date1[itxt] = text_getdate(handl); + b: @7 M E9 Y3 P, T
time1[itxt] = text_gettime(handl);
price1[itxt] = text_getvalue(handl); # t5 s6 u/ ?. n$ L% o3 w
itxt = itxt + 1; 9 T" [4 K+ J5 \, R
end;
handl = text_getnext(handl,2); { IMPORTANT -- infinite loop if this is missing! }
end; " C) }; D* N. B7 i- F9 G
end; 7 i* Z; n6 j9 u3 q& A% N4 A) y
var: ok2plotsys(false); ok2plotsys = date1[0] = 0 or Date < date1[0] or (Date = date1[0] and time <= time1[0]);
IF OK2PLOTSYS THEN BEGIN
0 ?' U$ F1 y! V, w ~5 ~
///////////////////////////////////////////////////////////////////////////// 0 g5 T/ y/ v# l' C
// CONTINUE
/////////////////////////////////////////////////////////////////////////////
2 |4 f. I+ Q4 n, A V
Once Begin n7 X- m) P( `
InitFibs();
Value1 = c[max_b]; ; S4 c. Z* S+ F, g& _( q2 R
end;
9 o( F- ^7 O* f. B" F. f
var: zighh(0); zighh = highestFC(h,zigback);
var: zigll(0); zigll = lowestFC(l,zigback);
var: zigdir(0); If H > zighh[1] then zigdir = 1; If L < zigll[1] then zigdir = -1; + b! _6 k% x, p! w5 O3 ? I
var: ii(0);
var: r(0);
var: near_r(0);
If zigdir <> zigdir[1] then begin 7 W2 Y) J. j) @. \- w
For ii = 10 downto 1 begin 9 S7 S5 q' i2 R' F; b
p[ii] = p[ii-1];
pb[ii] = pb[ii-1];
patrn[ii] = patrn[ii-1];
confrm[ii] = confrm[ii-1]; 3 Y: o- g6 N) N8 Q2 |' @/ P
end;
Switch zigdir begin
Case 1:
p[0] = zighh; ! ?' O, K2 z# n5 H+ d
pb[0] = currentbar; : O+ C3 L5 r ?
patrn[0] = 0; 4 D- m: G5 S9 T- T
confrm[0] = 0;
Case -1: . u3 \/ T G# b) t
p[0] = zigll;
pb[0] = currentbar;
patrn[0] = 0;
confrm[0] = 0; # [% S( C# r( h- R/ Z
end;
XX = p[4]; XXb = pb[4];
AA = p[3]; AAb = pb[3];
BB = p[2]; BBb = pb[2];
CC = p[1]; CCb = pb[1];
If ShoZigZag then . y5 t: T* M5 u# i8 C# F& Q+ X
If BB > 0 then
plotline(5, BB,BBb, CC,CCb, darkcyan, 1);
) E: I3 g# v0 M$ X+ U1 Q7 l
r = ratio("AB","XA"); 0 k/ n! @" |: i% m8 P s0 F
near_r = NearestFib(r);
If ShoFibLabel then , H! L }9 N- d. Q( w
oo_plotstring(BB,numtostr(near_r,3),oo_iff(near_r=r,darkcyan,cyan),currentbar-BBb,-1); ) W* E6 `% N/ R( t9 i( |; d
7 P5 X7 I( u4 U. ~8 u5 m
// HARMONIC SETUPS
. C* z: a. Q9 L/ r& N& T
// The order here reflects the priority of which supersedes which . P! V1 w0 c% n0 d( U) p
If ShoBat then , L4 I! M v: x6 n0 t+ X" V
patrn[1] = BatSetup(); 3 Q' {) h% O$ s+ K
If ShoButterfly then
patrn[1] = ButterflySetup();
If ShoGartley then : @/ Y2 H, t% N/ I
patrn[1] = GartleySetup(); " n& I5 F# G( T1 W+ Y$ R c; A7 b& g
If ShoCrab then
patrn[1] = CrabSetup();
If ShoDeepCrab then $ d1 P0 [5 R9 \$ \# z
patrn[1] = DeepCrabSetup(); - [$ _) u. [$ O1 E1 p# a
If ShoFiveOh then $ u8 D; B( B! g% J6 Z
patrn[1] = FiveOhSetup(); 0 J) J1 h/ ?0 h, `* _( X
0 g: p I; o9 |% p
If patrn[1] <> 0 then begin
plot7[currentbar-BBb](BB,"p7",black,default,3);
plot8[currentbar-BBb](BB,"p8",cyan,default,5); # G% O" }% o) _" I$ ]3 I2 ~: d' {
PlotLine(1, XX,XXb, AA,AAb, cyan, 1); ' R: i; k: w; _ F) ?" _* Y
PlotLine(1, AA,AAb, BB,BBb, cyan, 1);
PlotLine(2, XX,XXb, BB,BBb, cyan, 1); ! _0 V- i) w6 ?
FillTriangle( 1, BB,BBb, AA,AAb, XX,XXb, Darkcyan ); ) X/ J! }" z& l' B B4 V$ b
; t: {9 H* Q6 e @ R8 K+ M
PlotLine(1, BB,BBb, CC,CCb, cyan, 1);
1 l+ K% X8 y- e- U* N
oo_plotstring(targI,"Inner entry ->",cyan,1,-1);
oo_plotstring(targO,"Outer entry ->",cyan,1,-1);
oo_plotstring(bestConfirm,"Best confirm ->",cyan,1,-1);
var: tcolr(getplotcolor(55)); ! g: Q6 h' H6 ~; ]* k5 x
oo_plotstring(targCD,"AB=CD ->",tcolr,1,-1); 6 |! h n2 Q! u9 c# J) }4 w
Switch patrn[1] begin 7 i+ D0 h0 E* P9 M
case bat.bullish: oo_plotstring(DD,"Bullish Bat ->",cyan,currentbar-DDb,-1); . w0 @3 _9 T& ]. G
case bat.bearish: oo_plotstring(DD,"Bearish Bat ->",cyan,currentbar-DDb,-1); : D3 q# x0 w! r6 U h" Q
case butterfly.bullish: oo_plotstring(DD,"Bullish Butterfly ->",cyan,currentbar-DDb,-1); ! J0 K9 h' l/ Y+ X
case butterfly.bearish: oo_plotstring(DD,"Bearish Butterfly ->",cyan,currentbar-DDb,-1); ( l, d. R6 |# L" I- g! T
case gartley.bullish: oo_plotstring(DD,"Bullish Gartley ->",cyan,currentbar-DDb,-1);
case gartley.bearish: oo_plotstring(DD,"Bearish Gartley ->",cyan,currentbar-DDb,-1); : v7 z3 i4 M& i+ Y
case crab.bullish: oo_plotstring(DD,"Bullish Crab ->",cyan,currentbar-DDb,-1); y$ f& _/ i" O; ]
case crab.bearish: oo_plotstring(DD,"Bearish Crab ->",cyan,currentbar-DDb,-1);
case deepcrab.bullish: oo_plotstring(DD,"Bullish Deep Crab ->",cyan,currentbar-DDb,-1); ( n n8 D; ~* q
case deepcrab.bearish: oo_plotstring(DD,"Bearish Deep Crab ->",cyan,currentbar-DDb,-1); 4 B; T5 r4 F+ ?! w4 R2 u6 @7 I7 u
case fiveoh.bullish: oo_plotstring(DD,"Bullish 5-O ->",cyan,currentbar-DDb,-1);
case fiveoh.bearish: oo_plotstring(DD,"Bearish 5-O ->",cyan,currentbar-DDb,-1);
end; * ?6 R# W, _0 m: w3 J2 ]# W/ l
end; 8 p3 M& M, M7 K5 {% v
6 `! Q" a! r) d& A, B
// HARMONIC CONFIRMATIONS
XX = p[5]; XXb = pb[5]; , K( Q5 n5 j' ?) G$ I0 D, Y4 X
AA = p[4]; AAb = pb[4]; [- E9 x4 o3 n. r) Z5 B# f- W6 O
BB = p[3]; BBb = pb[3];
CC = p[2]; CCb = pb[2];
DD = p[1]; DDb = pb[1]; 5 I. E! [ i2 Q1 _- h7 T
EE = p[0]; EEb = pb[0];
% f) @3 v, m/ M; N" e
If confrm[4] = pattern.limbo then begin // special continuation case
var: XX2(0), XX2b(0); XX2 = p[7]; XX2b = pb[7];
var: AA2(0), AA2b(0); AA2 = p[6]; AA2b = pb[6];
var: BB2(0), BB2b(0); BB2 = p[5]; BB2b = pb[5];
var: CC2(0), CC2b(0); CC2 = p[4]; CC2b = pb[4];
var: Pattern2(0); Pattern2 = patrn[4]; F+ [9 k+ @' @: M' y9 f* t! S4 E
6 B# K3 _+ J+ R
For ii = 1 to 8 begin
p[ii] = p[ii+2];
pb[ii] = pb[ii+2]; % {2 B7 T( r# k' B# ^7 S
patrn[ii] = patrn[ii+2];
confrm[ii] = confrm[ii+2];
end; ; i5 Z. Z. v( ~! q/ N
" x6 {) w k' `' O1 {1 b8 x, A1 P
If Pattern2 > 0 then begin // bullish
If BB < DD then begin p[1] = BB; pb[1] = BBb; end + [% A6 G5 [) x0 e5 ]* k
Else begin p[1] = DD; pb[1] = DDb; end;
If CC > AA then begin p[2] = CC; pb[2] = CCb; end 1 H5 ~) X! ^( i/ _: j/ s ]
Else begin p[2] = AA; pb[2] = AAb; end; ) |% U" u( B/ E, I$ \! g/ o& P/ ^
plotline(3, p[2],pb[2], p[1],pb[1], darkcyan,2); * f. L, p% a- @4 F2 ?
End else if Pattern2 < 0 then begin // bearish
If BB > DD then begin p[1] = BB; pb[1] = BBb; end 9 K& m5 B# Q5 p0 {; t+ s: r/ a2 Q: G" t
Else begin p[1] = DD; pb[1] = DDb; end; 0 d/ ~# `1 j2 f. B# l5 I
If CC < AA then begin p[2] = CC; pb[2] = CCb; end ' b% l% l' | x5 K/ J8 `% v
Else begin p[2] = AA; pb[2] = AAb; end;
plotline(3, p[2],pb[2], p[1],pb[1], darkcyan,2); - ]. A# ~( ]5 S; }
End else print("!!!error"); . R- ^! C; z9 \( z) h$ c
% Q! s4 [7 H9 [& s' G
end; ( T1 L/ J3 @% D7 J
XX = p[5]; XXb = pb[5];
AA = p[4]; AAb = pb[4];
BB = p[3]; BBb = pb[3];
CC = p[2]; CCb = pb[2]; : b: Z2 g- W* P @! Q: z% r! _
DD = p[1]; DDb = pb[1]; 1 V& e) N( k2 l% P" A8 k
EE = p[0]; EEb = pb[0]; 3 D y. f% h& j1 ] n3 y) h/ Z, u
Pattern = patrn[2]; 0 |( t2 v9 e8 I' J+ m
Switch Pattern begin 6 U# [. U' T W9 P8 Z4 I. \
Case bat.bullish,bat.bearish: confrm[2] = BatConfirm(); ' z5 f) M/ ~1 Z( n! S
Case butterfly.bullish,butterfly.bearish: confrm[2] = ButterflyConfirm();
Case gartley.bullish,gartley.bearish: confrm[2] = GartleyConfirm(); ' r: |2 J. i4 F
Case crab.bullish,crab.bearish: confrm[2] = CrabConfirm(); 2 h6 T, J2 A9 } f# N9 T8 U9 Q9 r
Case deepcrab.bullish,deepcrab.bearish: confrm[2] = DeepCrabConfirm(); 5 S8 f6 N3 n* l; M: I1 s
Case fiveoh.bullish,fiveoh.bearish: confrm[2] = FiveOhConfirm();
end; 1 e( k, S8 n; f/ J+ a
$ @0 T) o x/ @' q/ ^0 D
If confrm[2] <> 0 then 0 v& ?* g; H9 d7 A
Switch confrm[2] begin
Case pattern.failed: - D; d( d+ |5 T, a! }5 p2 N
Value1 = oo_plotstring(EE,"pattern failure ->",cyan,currentbar-EEb,-1); 2 o, i' [2 M, m4 V& K% f( r
targI = 0;
targO = 0; , \$ D+ q( S- p5 S6 x9 a
targCD = 0; # t+ M8 y1 k" J; ?2 q- ?
bestConfirm = 0;
Case pattern.limbo: * I* o6 G0 }: M# v9 I
Value1 = oo_plotstring(EE,"pattern continuing ->",cyan,currentbar-EEb,-1);
Case pattern.confirmed: ; . d5 h' s' I( t8 B3 d. g7 f
PlotLine(3, CC,CCb, DD,DDb, cyan, 1); ) O. {; c$ B6 T, s% \$ S7 g, q L& c
PlotLine(3, BB,BBb, CC,CCb, cyan, 1); ) E6 O( d; v, i1 [$ {0 {4 f
PlotLine(4, BB,BBb, DD,DDb, cyan, 1);
FillTriangle( 0, DD,DDb, CC,CCb, BB,BBb, oo_iff(pattern<0,BearishColor,BullishColor) ); : r# W! B; `* Z, R7 r! Q7 _" w
5 g* G0 x& h% m% k3 Y0 C( [
targI = 0; 4 O& Z, R% K; Z k' N N3 w7 G
targO = 0; / a4 Z9 {& L v& C' T
targCD = 0;
bestConfirm = 0; 5 Z* B5 I" `# E% X4 E) o2 j& X7 o
default: ; O" Z5 {; a; `
Value1 = oo_plotstring(EE,"???",cyan,currentbar-EEb,-1); 5 d' Z- k& T. n$ }# }) j
print("pattern ???");
end;
end; 1 ?: w6 G; X( T/ \* T5 E& d7 x4 N
Switch zigdir begin
Case 1: If p[0] < H then begin p[0] = h; pb[0] = currentbar; end; 1 X$ K* m& t7 r, G
Case -1: If p[0] > l then begin p[0] = l; pb[0] = currentbar; end;
end;
}
If ShoZZBands then begin
plot51(zighh,"p51",oo_iff(zigdir=1,green,red)); 6 y( U8 Y) `" `4 l3 P3 _
plot52(zigll,"p52",oo_iff(zigdir=1,green,red)); ; i, ^4 T) K: O% Y, u
end; 4 o3 h7 N" Q: F8 ^
& f- e9 o/ B! O6 P4 J
if targI > 0 then plot53(targI,"p53",cyan);
if targO > 0 then plot54(targO,"p54",cyan);
if targCD > 0 then plot55(targCD,"p55");
if bestConfirm > 0 then plot56(bestConfirm,"p56"); 2 @# F [0 V, }$ i3 W . y! \; ^ G! @8 E2 o$ oEND;
} }
In this image you can see the error that Tradestation reports, and the code is green
because there are several open curly brackets: { that have not been closed and therefore exclude most of the code;
if someone can correct the formula, I can reciprocate with several Technical Analysis books (pdf and epub).
There are many, many multiple errors so rather than try to correct them I grabbed off the TradeStation forum (the better place to ask these questions, really don't know what bigmike is trying accomplish??) this code which hopefully posts without any unwanted extraneous characters that can foul things up. If you can deal with an ELD better shout back. That is if futures.io accepts tagging posts with ELD's:-
I thank you for having inserted a formula of Harmonic Patterns, but unfortunately this one contains errors too;
the first error is the word: BatSetup() that Tradestation reports as: "Word not recognized by Easylanguage" (see image), and then
I think that also the other words: