Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

derek2209

Members
  • Content Count

    32
  • Joined

  • Last visited

Everything posted by derek2209

  1. Hi Traderslaboratory In John F Ehlers Book " Cycle-Analytics-for-Traders " The EasyLanguage code to compute the Convolution indicator is given in Code Listing 13-1. EasyLanguage Code to Compute and Display Convolution ///////////////////////////////////////////////////////////////////////////// the line in the book and below is incomplete i.e. <<< If Filt[intPortion(.5*N)] < Filt Convolution[N] = (1 + (ExpValue Blank >>> To get Indicator to run inserted the line below <<< If (IntPortion(.5*N))>Filt then Convolution[N]=(1+ExpValue(N)); >>> Could someone please correct this effort /////////////////////////////////////////////////////////////////////////// See attached pdf " Ehlers Convolution Indicator" for the original code Thank you in advance Derek The EasyLanguage code to compute the Convolution indicator is given in Code Listing 13-1. Code Listing 13-1. EasyLanguage Code to Compute and Display Convolution { Convolution Indicator (c) 2013 John F. Ehlers } Inputs: ShortestPeriod(40), LongestPeriod(80); Vars: alpha1(0), HP(0), a1(0), b1(0), c1(0), c2(0), c3(0), Filt(0), N(0), II(0), X(0), Y(0), Sx(0), Sy(0), Sxx(0), Syy(0), Sxy(0), Color1(0), Color2(0), Color3(0); Arrays: Corr[48](0), Slope[48](0), Convolution[48](0); //HighPass filter cyclic component alpha1 = (Cosine(1.414*360 / Longe HP = (1 - alpha1 / 2)* (1 - alpha1 / 2)* (Close - 2*Close[1] + Close[2]) + (1 - alpha1)*HP[1] - (1 - alpha1)* (1 - alpha1)*HP[2]; //Smooth with a Super Smoother Fil a1 = expvalue(-1.414*3.14159 / Sho b1 = 2*a1*Cosine(1.414*180 / Short c2 = b1; c3 = -a1*a1; c1 = 1 - c2 - c3; Filt = c1* (HP + HP[1]) / 2 + c2*Filt[1] + c3 For N = 1 to 48 Begin Sx = 0; Sy = 0; Sxx = 0; Syy = 0; Sxy = 0; For II = 1 to N Begin X = Filt[iI - 1]; Y = Filt[N - II]; Sx = Sx + X; Sy = Sy + Y; Sxx = Sxx + X*X; Sxy = Sxy + X*Y; Syy = Syy + Y*Y; End; If (N*Sxx - Sx*Sx)* (N*Syy - Sy*Sy) > 0 Then Corr[N] = (N*Syy - Sy*Sy)); Slope[N] = 1; {////////////////////////////////////////////////////////////////////////////////////////// In John F Ehlers Book " Cycle-Analytics-for-Traders" The EasyLanguage code to compute the Convolution indicator is given in Code Listing 13-1. the line in the book and below is incomplete i.e. <<< If Filt[intPortion(.5*N)] < Filt Convolution[N] = (1 + (ExpValue >>> To get Indicator to run substitued the line below <<< If (IntPortion(.5*N))>Filt then Convolution[N]=(1+ExpValue(N)); >>> Could someone please correct this effort /////////////////////////////////////////////////////////////////////////////////////////////} If (IntPortion(.5*N))>Filt then Convolution[N]=(1+ExpValue(N)); End; //Plot as a Heatmap For N = 3 to 48 Begin If Slope[N] > 0 Then Begin Color1 = 255*Convolution[N]; Color2 = 0; End; If Slope[N] < 0 Then Begin Color1 = 0; Color2 = 255*Convolution[N]; End; Color3 = 0; If N = 2 Then Plot2[4] (2, “S2”, RGB(Color1, Color2, Colo If N = 3 Then Plot3[4] (3, “S3”, RGB(Color1, Color2, Colo If N = 4 Then Plot4[4] (4, “S4”, RGB(Color1, Color2, Colo If N = 5 Then Plot5[4] (5, “S5”, RGB(Color1, Color2, Colo If N = 6 Then Plot6[4] (6, “S6”, RGB(Color1, Color2, Colo If N = 7 Then Plot7[4] (7, “S7”, RGB(Color1, Color2, Colo If N = 8 Then Plot8[4] (8, “S8”, RGB(Color1, Color2, Colo If N = 9 Then Plot9[4] (9, “S9”, RGB(Color1, Color2, Colo If N = 10 Then Plot10[4] (10, “S10”, RGB(Color1, Color2, Co If N = 11 Then Plot11[4] (11, “S11”, RGB(Color1, Color2, Co If N = 12 Then Plot12[4] (12, “S12”, RGB(Color1, Color2, Co If N = 13 Then Plot13[4] (13, “S13”, RGB(Color1, Color2, Co If N = 14 Then Plot14[4] (14, “S14”, RGB(Color1, Color2, Co If N = 15 Then Plot15[4] (15, “S15”, RGB(Color1, Color2, Co If N = 16 Then Plot16[4] (16, “S16”, RGB(Color1, Color2, Co If N = 17 Then Plot17[4] (17, “S17”, RGB(Color1, Color2, Co If N = 18 Then Plot18[4] (18, “S18”, RGB(Color1, Color2, Co If N = 19 Then Plot19[4] (19, “S19”, RGB(Color1, Color2, Co If N = 20 Then Plot20[4] (20, “S20”, RGB(Color1, Color2, Co If N = 21 Then Plot21[4] (21, “S21”, RGB(Color1, Color2, Co If N = 22 Then Plot22[4] (22, “S22”, RGB(Color1, Color2, Co If N = 23 Then Plot23[4] (23, “S23”, RGB(Color1, Color2, Co If N = 24 Then Plot24[4] (24, “S24”, RGB(Color1, Color2, Co If N = 25 Then Plot25[4] (25, “S25”, RGB(Color1, Color2, Co If N = 26 Then Plot26[4] (26, “S26”, RGB(Color1, Color2, Co If N = 27 Then Plot27[4] (27, “S27”, RGB(Color1, Color2, Co If N = 28 Then Plot28[4] (28, “S28”, RGB(Color1, Color2, Co If N = 29 Then Plot29[4] (29, “S29”, RGB(Color1, Color2, Co If N = 30 Then Plot30[4] (30, “S30”, RGB(Color1, Color2, Co If N = 31 Then Plot31[4] (31, “S31”, RGB(Color1, Color2, Co If N = 32 Then Plot32[4] (32, “S32”, RGB(Color1, Color2, Co If N = 33 Then Plot33[4] (33, “S33”, RGB(Color1, Color2, Co If N = 34 Then Plot34[4] (34, “S34”, RGB(Color1, Color2, Co If N = 35 Then Plot35[4] (35, “S35”, RGB(Color1, Color2, Co If N = 36 Then Plot36[4] (36, “S36”, RGB(Color1, Color2, Co If N = 37 Then Plot37[4] (37, “S37”, RGB(Color1, Color2, Co If N = 38 Then Plot38[4] (38, “S38”, RGB(Color1, Color2, Co If N = 39 Then Plot39[4] (39, “S39”, RGB(Color1, Color2, Co If N = 40 Then Plot40[4] (40, “S40”, RGB(Color1, Color2, Co If N = 41 Then Plot41[4] (4 , “S4 ”, RGB(Color1, Color2, Co If N = 42 Then Plot42[4] (4 , “S4 ”, RGB(Color1, Color2, Co If N = 43 Then Plot43[4] (4 , “S4 ”, RGB(Color1, Color2, Co If N = 44 Then Plot44[4] ( 4, “S 4”, RGB(Color1, Color2, Co If N = 45 Then Plot45[4] (4 , “S4 ”, RGB(Color1, Color2, Co If N = 46 Then Plot46[4] (4 , “S4 ”, RGB(Color1, Color2, Co If N = 47 Then Plot47[4] (4 , “S4 ”, RGB(Color1, Color2, Co If N = 48 Then Plot48[4] (4 , “S4 ”, RGB(Color1, Color2, Co End; Ehlers Convolution.pdf
  2. Hi Traderslaboratory, Attached should be a Screenshot of the Butterfly Pattern, TradeStation Butterfly Pattern ELD and the code for the Butterfly Pattern as a text file Best regards Derek BUTTERFLY PATTERN.ELD Butterfly Pattern.txt
  3. Hi Trader Laboratory Thank you to zdo Market Wizard for his referring to the work of Marsalla Marceau and to Marsalla Marceau for his great work on code writing of Auto Harmonics I have attached the TS ELD using the original name "2014123002314120121230 AUTOHARMONICS " and a text file Auto Harmonics.txt I used TradeStation 9.1 to verify the code and draw the Charts If you do not get a plot of the indicator try loading more price bars Also a screen shot of Formating the Indicator Parameters I would like someone to advise on setting up the Indicator Parameters And three screen shots of the Indicator I hope that the attachments travel ok Best regards Derek 2014123002314120121230 AUTOHARMONICS.ELD Auto Harmonics.txt
  4. Hello Traders Laboratory The http Link that I just pasted seems to have got corrupted with try again trying again Derek https://community.tradestation.com/discussions/SearchResult.aspx?txtAll=&txtExact=&txtOr=&txtNot=&txtAuthor=MarsallaMarceau&radioAuthor=0&selAuthor=0&radioScope=0&selForum=0&selSortField=1&SelSortOrder=1&cbArchive=1&selFrom=-1&RadioResult=0&selResultCount=200&Session_ID=163816-00000000
  5. Hi Traders Laboratory Mr zdo Thank you again for your time and patiance with this question If anyone has access to the TradeStation Forum the original artical is there re Marsella Marceau code pages1,2.3 ref:: Easylanguage Library Link below: https://community.tradestation.com/discussions/SearchResult.aspx?txtAll=&txtExact=&txtOr=&txtNot=&txtAuthor=MarsallaMarceau&radioAuthor=0&selAuthor=0&radioScope=0&selForum=0&selSortField=1&SelSortOrder=1&cbArchive=1&selFrom=-1&RadioResult=0&selResultCount=200&Session_ID=163816-00000000 Best regards Derek
  6. Hi Thank you for your reply As you say the text file was corrupted I have posted the code below I hope that this helps Derek { 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 ' } { Revision History: 2013-01-10: Initial release (MarsallaMarceau) } {0 q% G$ V( X% i/ W$ j% } input: zigfac(2); input: ShoBat(true); input: ShoButterfly(false); input: ShoGartley(false); ) input: ShoCrab(false); input: ShoDeepCrab(false); input: ShoFiveOh(false); input: ShoABeCD(false{AB=CD}); input: ShoBars(true); input: ShoFibLabel(false); input: ShoZigZag(true); input: ShoZZBands(false); input: BearishColor(darkred); input: BullishColor(darkgreen); var: zigback(14 * zigfac); array: p[10](0), pb[10](0), patrn[10](0), confrm[10](0); , f. [* R# _) V9 m8 `) ~ const: bat.bullish(1), gartley.bullish(2), crab.bullish(3), deepcrab.bullish(4), butterfly.bullish(5), fiveoh.bullish(6); const: bat.bearish(-1), gartley.bearish(-2), crab.bearish(-3), deepcrab.bearish(-4), butterfly.bearish(-5), fiveoh.bearish(-6); const: pattern.confirmed(1), pattern.failed(2), pattern.limbo(3); $ b& d5 m% x5 ?( M var: XX(0), AA(0), BB(0), CC(0), DD(0), EE(0); 9 F6 d. R5 D1 n! u) p4 O var: XXb(0), AAb(0), BBb(0), CCb(0), DDb(0), EEb(0); var: Pattern(0); 8 M- w4 \; h, K# v var: targI(0), targO(0), targCD(0), bestConfirm(0); i" t6 k7 h& b& m# k- e3 g ///////////////////////////////////////////////////////////////////////////// // BAT ///////////////////////////////////////////////////////////////////////////// 9 D6 J9 N" |; K6 ?- S5 i% ] 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; ///////////////////////////////////////////////////////////////////////////// // BUTTERFLY ///////////////////////////////////////////////////////////////////////////// 6 h0 ^3 J- {* D+ t+ p 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; } }
  7. Hi Trader Laboratory When I try to Verify the attached TradeStation code for Harmonic Patterns I get an error........ " } " was expected before end of file Could you please tell me where the missing " } " bracket(s) should be placed Thank you in advance Hoping you can oblige Derek Harmonic Patterns.txt HARMONIC PATTERNS.ELD
  8. Hi johnnydaymon, Thank you very much for opening the ELD and posting the Code Best regards Derek
  9. Hi, Hopefully the Link below should give you a screenshot of " johnnydaymon " TTM ABC Waves https://www.sendspace.com/file/aplgj5 Derek
  10. Hi zdo, Thank you for your help opening the TS ELD file and sending me the text file of the contents It is much appreciated Thank you also to "johnnydaymon" for the original ELD file Derek
  11. Hi Could someone Open attached TradeStation ELD File name: " 20110116171505TTM-ABC-WAVES.ELD " And post the contents of this ELD file as Text on this Traderslaboratory site (Link below http://cdn3.traderslaboratory.com/forums/attachments/46/37150d1380685556-ttm-wave-20110116171505ttm-abc-waves.eld With thanks to " johnnydaymon " for the original File Thank you in advance Derek 37150d1380685556-ttm-wave-20110116171505ttm-abc-waves.eld
  12. Hi, Could you please open the Tradestation ELD file below " 20110116171505TTM ABC WAVES.ELD " and convert and display it as text file of that indicator on Traderslaboratory.com Website http://cdn3.traderslaboratory.com/forums/attachments/46/37150d1380685556[[ http://www.traderslaboratory.com/forums/trading-indicators/16938-ttm-wave.html See attached screenshot of indicator Thank you in advance Derek 37150d1380685556-ttm-wave-20110116171505ttm-abc-waves.eld
  13. Try this Link Download TTM Squeeze Indicator For Amibroker (AFL) //~~~~~~~~~~~~~~~~~~~~~ John Carter's TTM Squeeze Indicator~~~~~~~~~~~~~~~~~~~~~ // Description: Bollinger Bands AND Keltner Channel define the market // conditions, i.e. when BB is narrower than KC then we have // a market squeeze. When BB break Outside the KC then trade // in the direction of the smoothed Momentum(12). // Parameters: // * chanPeriod - Bollinger Bands AND Keltner Channel length // * bolBandStdDev - width of the Bollinger Bands // * keltStdDev - width of the Keltner Bands // * momPeriod - # of bars for Momentum indicator // * momEMA - EMA of the Momentum indicator // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Source : John Carter, www.TradeTheMarkets.com // Interpretation : Kris Tokarzewski, Johannesburg, 15-Dec-2006 // AmiBroker Conversion: Levent Pancuk, 22 Feb-2008 // lpancuk@yahoo.com //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _SECTION_BEGIN("TTM Squeeze"); function Momentum( array, period ) { return array - Ref( array, -period ); } chanPeriod = Param("Channel Period", 20); bolBandStdDev = Param("Bollinger Band StdDev",2); keltStdDev = Param("Keltner Band StdDev",1.5); momPeriod = Param("Momemtum Period", 12 ); momEMA = Param("Momentum EMA Period", 5); highBBChl = BBandTop( C, chanPeriod, bolBandStdDev); lowBBChl = BBandBot( C, chanPeriod, bolBandStdDev); centerLine = MA( C, chanPeriod ); highKeltn = centerLine + keltStdDev * ATR(chanPeriod); lowKeltn = centerLine - keltStdDev * ATR(chanPeriod); momHist = EMA(Momentum(C, momPeriod),momEMA); BBUp = IIf(highBBChl > highKeltn AND momHist > 0, momHist, 0); BBDo = IIf(lowBBChl < lowKeltn AND momHist < 0, momHist, 0); BBMid = IIf(BBUp == 0 AND BBDo == 0, momHist, 0); Buy = BBUp; Sell = BBDo; Buy = ExRem(Buy,Sell)AND Volume>25000; Sell = ExRem(Sell,Buy)AND Volume>25000; Plot(BBUp, "TTM Squeeze - Momentum Up", colorBlue,styleHistogram | styleThick); Plot(BBDo, "Momentum Down", colorOrange, styleHistogram | styleThick); Plot(BBMid, "Momentum Mid", IIf(BBMid > 0, colorLightBlue, colorBrown), styleHistogram | styleThick); PlotShapes( shapeSmallCircle*Buy, colorGreen,0, 0, 0); PlotShapes( shapeSmallCircle*Sell, colorRed,0, 0, 0); AlertIf( Buy, "", "Simple text alert", 2 ); _SECTION_END();
  14. Hi Inputs: Period(5); vars: MidLine(0),UpperBand(0),LowerBand(0); UpperBand=Average(Highest(High,Period),Period); LowerBand=Average(Lowest(Low,Period),Period); MidLine=(UpperBand+LowerBand)/2; Plot1(MidLine,"MidLine"); if MidLine >= MidLine[1] then setplotcolor(1,Cyan) else setplotcolor(1,red); Plot2(UpperBand,"UpperBand",LightGray); Plot3(LowerBand,"LowerBand",DarkGray); Derek
  15. Hello Below is a Link for a screensot of the Sliding Range Indicator: Derek ????????? Rj_SlidingRange ?? ?????? ??????
  16. Hello, Would anyone be kind enough the convert the mq4 formula for the Sling Range into Tradestation Code Hoping that you can oblige Thank you in advance Derek //+------------------------------------------------------------------+ //| Rj_SlidingRange.mq4 | //| Copyright © 2011,RJ Rjabkov Alexander | //| rj-a@mail.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2011,RJ Rjabkov Alexander" #property link "rj-a@mail.ru" #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 Aqua #property indicator_color2 Red #property indicator_color3 Aqua #property indicator_color4 Red #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 2 #property indicator_width4 2 #property indicator_style1 2 #property indicator_style2 2 extern int CalcPeriodRange = 5; double UpperLimit[]; double LowerLimit[]; double AwlUpper[]; double AwlLower[]; double Current[]; int init() { IndicatorBuffers(5); SetIndexBuffer(0, UpperLimit); SetIndexBuffer(1, LowerLimit); SetIndexBuffer(2, AwlUpper); SetIndexBuffer(3, AwlLower); SetIndexBuffer(4, Current); SetIndexStyle(0, DRAW_LINE); SetIndexStyle(1, DRAW_LINE); SetIndexStyle(2, DRAW_LINE); SetIndexStyle(3, DRAW_LINE); return(0); } int deinit() {return(0);} int start() { int i, cb; int counted_bars = IndicatorCounted(); if (counted_bars < 0) return(-1); if (counted_bars > 0) counted_bars--; cb=Bars-counted_bars; while(cb>=0) { i=cb+CalcPeriodRange-1; double b1=0, b2=0; while(i>=cb) { b1 += High[iHighest(NULL, 0, MODE_HIGH, CalcPeriodRange, i)]; b2 += Low[iLowest(NULL, 0, MODE_LOW, CalcPeriodRange, i)]; i--; } UpperLimit[cb]=b1/CalcPeriodRange; LowerLimit[cb]=b2/CalcPeriodRange; Current[cb]=NormalizeDouble((UpperLimit[cb]+LowerLimit[cb])/2, 5); AwlUpper[cb]=EMPTY_VALUE; AwlLower[cb]=EMPTY_VALUE; if(Current[cb]>Current[cb+1]) {AwlUpper[cb]=Current[cb]; AwlUpper[cb+1]=Current[cb+1];} if(Current[cb]<Current[cb+1]) {AwlLower[cb]=Current[cb]; AwlLower[cb+1]=Current[cb+1];} if(Current[cb]==Current[cb+1] && AwlLower[cb+1]!=EMPTY_VALUE) {AwlLower[cb]=Current[cb];} if(Current[cb]==Current[cb+1] && AwlUpper[cb+1]!=EMPTY_VALUE) {AwlUpper[cb]=Current[cb];} cb--; } return(0); } //+------------------------------------------------------------------+
  17. Link below for the code of John F. Ehlers Autocorrelation Periodogram for Amibroker (AFL) with thanks to : < Ilya > for the translation to Amibroker (AFL) Download John F. Ehlers Autocorrelation Periodogram For Amibroker (AFL) Derek
  18. HI See attached PNG screenshot file of BB-MACD for Dax Sept 02 Best regards Derk BB-MACD Created by KelvinHand.txt
  19. Hi

    Could the Administrator remove the Duplicates of this Thread

     

    Derek

  20. Hi Using Amibroker I would like to Plot the "BB-MACD" Created by KelvinHand for a Variable time period Dominant Cycle as calculated by "Ehlers Autocorrelation Periodogram" code below I have only able to plot the "BB-MACD" Created by KelvinHand using the fixed time period of the last value of "Ehlers Autocorrelation Periodogram" Hoping that you can help Thanking you in advance Best regards Derek /////////////////////////////////////////////// //Ehlers Autocorrelation Periodogram for Amibroker (AFL) /* Autocorrelation Periodogram 2013 John F. Ehlers */ SetBarsRequired(sbrAll); LPeriod = Param("Low-pass Period", 10, 3, 20); HPeriod = Param("High-pass Period", 48, 22, 80); IsPlotHeatMap = ParamToggle("Show HeatMap?", "No|Yes", 1); IsPlotDominantCycle = ParamToggle("Show Dom. Cycle?", "No|Yes"); pi=3.1415926; function RoofingFilter(lpPeriod, hpPeriod) { alpha1 = (cos(0.707*2*pi / hpPeriod) + sin(0.707*2*pi / hpPeriod) - 1) / cos(0.707*2*pi / hpPeriod); a1 = exp(-1.414*pi / lpPeriod); b1 = 2*a1*cos(1.414*pi / lpPeriod); c2 = b1; c3 = -a1*a1; c1 = 1 - c2 - c3; HP = Close; Filt = HP; for(i = 2; i < BarCount; i++) { HP[i] = ((1 - alpha1 / 2)^2)*(Close[i] - 2*Close[i-1] + Close[i-2]) + 2*(1 - alpha1)*HP[i-1] - ((1 - alpha1)^2)*HP[i-2]; Filt[i] = c1*(HP[i] + HP[i-1]) / 2 + c2*Filt[i-1] + c3*Filt[i-2]; } return Filt; } function AGC(lowerCutoff, higherCutoff, acceptableSlope) { factor = 0; accSlope = -acceptableSlope; //acceptableSlope = 1.5 dB halfLC = lowerCutoff / 2; halfHC = higherCutoff / 2; ratio = 10^(accSlope/20); if(halfHC - halfLC > 0) factor = ratio^(1/(halfHC - halfLC)); return factor; } function AutocorrelationPeriodogram(data, isHeatMap, isDomCyc) { avgLength = 3; dominantCycle = 0; //Pearson correlation for each value of lag for(lag = 0; lag <= 48; lag++) { //Set the average length as M M = avgLength; if(avgLength == 0) M = lag; //Initialize correlation sums Sx = 0; Sy = 0; Sxx = 0; Syy = 0; Sxy = 0; //Advance samples of both data streams and sum Pearson components for(count = 0; count <= M-1; count++) { X = Ref(data, -count); Y = Ref(data, -(lag + count)); Sx += X; Sy += Y; Sxx += X^2; Syy += Y^2; Sxy += X*Y; } var1 = (M*Sxx - Sx^2)*(M*Syy - Sy^2); VarSet("corr" + lag, IIf(var1 > 0, (M*Sxy - Sx*Sy)/sqrt(var1), 0)); //Compute correlation for each value of lag //VarSet("corrScale" + lag, IIf(var1 > 0, 0.5*((M*Sxy - Sx*Sy)/sqrt(var1) + 1), 0)); //Scale each correlation to range between 0 and 1 } /*//Plot as a Heatmap (for scale each correlation to range between 0 and 1) for(period = 3; period <= 48; period++) { corr = VarGet("corrScale" + period); Red = IIf(corr > 0.5, 255*(2 - 2*corr), 255); Green = IIf(corr > 0.5, 255, 2*255*corr); PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel); }*/ /* The DFT is accomplished by correlating the autocorrelation at each value of lag with the cosine and sine of each period of interest. The sum of the squares of each of these values represents the relative power at each period. */ for(period = 10; period <= 48; period++) { cosinePart = 0; sinePart = 0; for(n = 3; n <= 48; n++) { cosinePart += VarGet("corr" + n)*cos(2*pi*n / period); sinePart += VarGet("corr" + n)*sin(2*pi*n / period); } VarSet("sqSum" + period, cosinePart^2 + sinePart^2); } //EMA is used to smooth the power measurement at each period for(period = 10; period <= 48; period++) VarSet("r" + period, AMA((VarGet("sqSum" + period))^2, 0.2)); //Find Maximum Power Level for Normalization K = AGC(10, 48, 1.5); for(period = 10; period <= 48; period++) { if(period == 10) VarSet("maxPwr", 0); VarSet("maxPwr", IIf(VarGet("r" + period) > VarGet("maxPwr"), K*VarGet("r" + period), VarGet("maxPwr"))); } //Normalization power for(period = 10; period <= 48; period++) VarSet("pwr" + period, VarGet("r" + period)/VarGet("maxPwr")); //Compute the dominant cycle using the CG of the spectrum Spx = 0; Sp = 0; for(period = 10; period <= 48; period++) { Spx += IIf(VarGet("pwr" + period) >= 0.5, period*VarGet("pwr" + period), 0); Sp += IIf(VarGet("pwr" + period) >= 0.5, VarGet("pwr" + period), 0); } dominantCycle = IIf(Sp != 0, Spx / Sp, 0); dominantCycle =(dominantCycle); if(isHeatMap) { //Plot as a Heatmap for(period = 10; period <= 48; period++) { pwr = VarGet("pwr" + period); Red = IIf(pwr > 0.5, 255, 2*255*pwr); Green = IIf(pwr > 0.5, 255*(2*pwr - 1), 0); PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel, Null, Null, 0, 0); } } if(isDomCyc) Plot(LastValue(dominantCycle,1), "Dominant Cycle", colorBlue, styleThick, Null, Null, 0, 1); pds=LastValue(dominantCycle,1); //"BB-MACD") Created by KelvinHand SetChartBkColor( ParamColor("background",colorBlack) ); A1=EMA(C,pds/2)-EMA(C,pds); BBtop=BBandTop(A1,10,1); BBbot=BBandBot(A1,10,1); Color=IIf(a1<0 AND a1>Ref(a1,-1), colorLime,IIf(a1>0 AND a1>Ref(a1,-1),colorBrightGreen,IIf(a1>0 AND a1<Ref(a1,-1),colorCustom12,colorRed))); Plot(a1,"MACD",color,styleThick+styleLine); Plot(BBtop,"BBtop",colorWhite,styleDashed); Plot(BBbot,"BBbot",colorWhite,styleDashed); Plot(0,"",colorWhite,1); AddColumn(round(dominantCycle), " DominantCycle", 2.0 , colorRed, colorLightYellow,50) ; return dominantCycle; } filtData = RoofingFilter(LPeriod, HPeriod); AutocorrelationPeriodogram(filtData, IsPlotHeatMap, IsPlotDominantCycle);
  21. Hi Using Amibroker I would like to Plot the "BB-MACD" Created by KelvinHand for a Variable time period Dominant Cycle as calculated by "Ehlers Autocorrelation Periodogram" code below I have only able to plot the "BB-MACD" Created by KelvinHand using the fixed time period of the last value of "Ehlers Autocorrelation Periodogram" Hoping that you can help Thanking you in advance Best regards Derek /////////////////////////////////////////////// //Ehlers Autocorrelation Periodogram for Amibroker (AFL) /* Autocorrelation Periodogram 2013 John F. Ehlers */ SetBarsRequired(sbrAll); LPeriod = Param("Low-pass Period", 10, 3, 20); HPeriod = Param("High-pass Period", 48, 22, 80); IsPlotHeatMap = ParamToggle("Show HeatMap?", "No|Yes", 1); IsPlotDominantCycle = ParamToggle("Show Dom. Cycle?", "No|Yes"); pi=3.1415926; function RoofingFilter(lpPeriod, hpPeriod) { alpha1 = (cos(0.707*2*pi / hpPeriod) + sin(0.707*2*pi / hpPeriod) - 1) / cos(0.707*2*pi / hpPeriod); a1 = exp(-1.414*pi / lpPeriod); b1 = 2*a1*cos(1.414*pi / lpPeriod); c2 = b1; c3 = -a1*a1; c1 = 1 - c2 - c3; HP = Close; Filt = HP; for(i = 2; i < BarCount; i++) { HP[i] = ((1 - alpha1 / 2)^2)*(Close[i] - 2*Close[i-1] + Close[i-2]) + 2*(1 - alpha1)*HP[i-1] - ((1 - alpha1)^2)*HP[i-2]; Filt[i] = c1*(HP[i] + HP[i-1]) / 2 + c2*Filt[i-1] + c3*Filt[i-2]; } return Filt; } function AGC(lowerCutoff, higherCutoff, acceptableSlope) { factor = 0; accSlope = -acceptableSlope; //acceptableSlope = 1.5 dB halfLC = lowerCutoff / 2; halfHC = higherCutoff / 2; ratio = 10^(accSlope/20); if(halfHC - halfLC > 0) factor = ratio^(1/(halfHC - halfLC)); return factor; } function AutocorrelationPeriodogram(data, isHeatMap, isDomCyc) { avgLength = 3; dominantCycle = 0; //Pearson correlation for each value of lag for(lag = 0; lag <= 48; lag++) { //Set the average length as M M = avgLength; if(avgLength == 0) M = lag; //Initialize correlation sums Sx = 0; Sy = 0; Sxx = 0; Syy = 0; Sxy = 0; //Advance samples of both data streams and sum Pearson components for(count = 0; count <= M-1; count++) { X = Ref(data, -count); Y = Ref(data, -(lag + count)); Sx += X; Sy += Y; Sxx += X^2; Syy += Y^2; Sxy += X*Y; } var1 = (M*Sxx - Sx^2)*(M*Syy - Sy^2); VarSet("corr" + lag, IIf(var1 > 0, (M*Sxy - Sx*Sy)/sqrt(var1), 0)); //Compute correlation for each value of lag //VarSet("corrScale" + lag, IIf(var1 > 0, 0.5*((M*Sxy - Sx*Sy)/sqrt(var1) + 1), 0)); //Scale each correlation to range between 0 and 1 } /*//Plot as a Heatmap (for scale each correlation to range between 0 and 1) for(period = 3; period <= 48; period++) { corr = VarGet("corrScale" + period); Red = IIf(corr > 0.5, 255*(2 - 2*corr), 255); Green = IIf(corr > 0.5, 255, 2*255*corr); PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel); }*/ /* The DFT is accomplished by correlating the autocorrelation at each value of lag with the cosine and sine of each period of interest. The sum of the squares of each of these values represents the relative power at each period. */ for(period = 10; period <= 48; period++) { cosinePart = 0; sinePart = 0; for(n = 3; n <= 48; n++) { cosinePart += VarGet("corr" + n)*cos(2*pi*n / period); sinePart += VarGet("corr" + n)*sin(2*pi*n / period); } VarSet("sqSum" + period, cosinePart^2 + sinePart^2); } //EMA is used to smooth the power measurement at each period for(period = 10; period <= 48; period++) VarSet("r" + period, AMA((VarGet("sqSum" + period))^2, 0.2)); //Find Maximum Power Level for Normalization K = AGC(10, 48, 1.5); for(period = 10; period <= 48; period++) { if(period == 10) VarSet("maxPwr", 0); VarSet("maxPwr", IIf(VarGet("r" + period) > VarGet("maxPwr"), K*VarGet("r" + period), VarGet("maxPwr"))); } //Normalization power for(period = 10; period <= 48; period++) VarSet("pwr" + period, VarGet("r" + period)/VarGet("maxPwr")); //Compute the dominant cycle using the CG of the spectrum Spx = 0; Sp = 0; for(period = 10; period <= 48; period++) { Spx += IIf(VarGet("pwr" + period) >= 0.5, period*VarGet("pwr" + period), 0); Sp += IIf(VarGet("pwr" + period) >= 0.5, VarGet("pwr" + period), 0); } dominantCycle = IIf(Sp != 0, Spx / Sp, 0); dominantCycle =(dominantCycle); if(isHeatMap) { //Plot as a Heatmap for(period = 10; period <= 48; period++) { pwr = VarGet("pwr" + period); Red = IIf(pwr > 0.5, 255, 2*255*pwr); Green = IIf(pwr > 0.5, 255*(2*pwr - 1), 0); PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel, Null, Null, 0, 0); } } if(isDomCyc) Plot(LastValue(dominantCycle,1), "Dominant Cycle", colorBlue, styleThick, Null, Null, 0, 1); pds=LastValue(dominantCycle,1); //"BB-MACD") Created by KelvinHand SetChartBkColor( ParamColor("background",colorBlack) ); A1=EMA(C,pds/2)-EMA(C,pds); BBtop=BBandTop(A1,10,1); BBbot=BBandBot(A1,10,1); Color=IIf(a1<0 AND a1>Ref(a1,-1), colorLime,IIf(a1>0 AND a1>Ref(a1,-1),colorBrightGreen,IIf(a1>0 AND a1<Ref(a1,-1),colorCustom12,colorRed))); Plot(a1,"MACD",color,styleThick+styleLine); Plot(BBtop,"BBtop",colorWhite,styleDashed); Plot(BBbot,"BBbot",colorWhite,styleDashed); Plot(0,"",colorWhite,1); AddColumn(round(dominantCycle), " DominantCycle", 2.0 , colorRed, colorLightYellow,50) ; return dominantCycle; } filtData = RoofingFilter(LPeriod, HPeriod); AutocorrelationPeriodogram(filtData, IsPlotHeatMap, IsPlotDominantCycle);
  22. Hi Using Amibroker I would like to Plot the "BB-MACD" Created by KelvinHand for a Variable time period Dominant Cycle as calculated by "Ehlers Autocorrelation Periodogram" code below I have only able to plot the "BB-MACD" Created by KelvinHand using the fixed time period of the last value of "Ehlers Autocorrelation Periodogram" Hoping that you can help Thanking you in advance Best regards Derek /////////////////////////////////////////////// //Ehlers Autocorrelation Periodogram for Amibroker (AFL) /* Autocorrelation Periodogram 2013 John F. Ehlers */ SetBarsRequired(sbrAll); LPeriod = Param("Low-pass Period", 10, 3, 20); HPeriod = Param("High-pass Period", 48, 22, 80); IsPlotHeatMap = ParamToggle("Show HeatMap?", "No|Yes", 1); IsPlotDominantCycle = ParamToggle("Show Dom. Cycle?", "No|Yes"); pi=3.1415926; function RoofingFilter(lpPeriod, hpPeriod) { alpha1 = (cos(0.707*2*pi / hpPeriod) + sin(0.707*2*pi / hpPeriod) - 1) / cos(0.707*2*pi / hpPeriod); a1 = exp(-1.414*pi / lpPeriod); b1 = 2*a1*cos(1.414*pi / lpPeriod); c2 = b1; c3 = -a1*a1; c1 = 1 - c2 - c3; HP = Close; Filt = HP; for(i = 2; i < BarCount; i++) { HP[i] = ((1 - alpha1 / 2)^2)*(Close[i] - 2*Close[i-1] + Close[i-2]) + 2*(1 - alpha1)*HP[i-1] - ((1 - alpha1)^2)*HP[i-2]; Filt[i] = c1*(HP[i] + HP[i-1]) / 2 + c2*Filt[i-1] + c3*Filt[i-2]; } return Filt; } function AGC(lowerCutoff, higherCutoff, acceptableSlope) { factor = 0; accSlope = -acceptableSlope; //acceptableSlope = 1.5 dB halfLC = lowerCutoff / 2; halfHC = higherCutoff / 2; ratio = 10^(accSlope/20); if(halfHC - halfLC > 0) factor = ratio^(1/(halfHC - halfLC)); return factor; } function AutocorrelationPeriodogram(data, isHeatMap, isDomCyc) { avgLength = 3; dominantCycle = 0; //Pearson correlation for each value of lag for(lag = 0; lag <= 48; lag++) { //Set the average length as M M = avgLength; if(avgLength == 0) M = lag; //Initialize correlation sums Sx = 0; Sy = 0; Sxx = 0; Syy = 0; Sxy = 0; //Advance samples of both data streams and sum Pearson components for(count = 0; count <= M-1; count++) { X = Ref(data, -count); Y = Ref(data, -(lag + count)); Sx += X; Sy += Y; Sxx += X^2; Syy += Y^2; Sxy += X*Y; } var1 = (M*Sxx - Sx^2)*(M*Syy - Sy^2); VarSet("corr" + lag, IIf(var1 > 0, (M*Sxy - Sx*Sy)/sqrt(var1), 0)); //Compute correlation for each value of lag //VarSet("corrScale" + lag, IIf(var1 > 0, 0.5*((M*Sxy - Sx*Sy)/sqrt(var1) + 1), 0)); //Scale each correlation to range between 0 and 1 } /*//Plot as a Heatmap (for scale each correlation to range between 0 and 1) for(period = 3; period <= 48; period++) { corr = VarGet("corrScale" + period); Red = IIf(corr > 0.5, 255*(2 - 2*corr), 255); Green = IIf(corr > 0.5, 255, 2*255*corr); PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel); }*/ /* The DFT is accomplished by correlating the autocorrelation at each value of lag with the cosine and sine of each period of interest. The sum of the squares of each of these values represents the relative power at each period. */ for(period = 10; period <= 48; period++) { cosinePart = 0; sinePart = 0; for(n = 3; n <= 48; n++) { cosinePart += VarGet("corr" + n)*cos(2*pi*n / period); sinePart += VarGet("corr" + n)*sin(2*pi*n / period); } VarSet("sqSum" + period, cosinePart^2 + sinePart^2); } //EMA is used to smooth the power measurement at each period for(period = 10; period <= 48; period++) VarSet("r" + period, AMA((VarGet("sqSum" + period))^2, 0.2)); //Find Maximum Power Level for Normalization K = AGC(10, 48, 1.5); for(period = 10; period <= 48; period++) { if(period == 10) VarSet("maxPwr", 0); VarSet("maxPwr", IIf(VarGet("r" + period) > VarGet("maxPwr"), K*VarGet("r" + period), VarGet("maxPwr"))); } //Normalization power for(period = 10; period <= 48; period++) VarSet("pwr" + period, VarGet("r" + period)/VarGet("maxPwr")); //Compute the dominant cycle using the CG of the spectrum Spx = 0; Sp = 0; for(period = 10; period <= 48; period++) { Spx += IIf(VarGet("pwr" + period) >= 0.5, period*VarGet("pwr" + period), 0); Sp += IIf(VarGet("pwr" + period) >= 0.5, VarGet("pwr" + period), 0); } dominantCycle = IIf(Sp != 0, Spx / Sp, 0); dominantCycle =(dominantCycle); if(isHeatMap) { //Plot as a Heatmap for(period = 10; period <= 48; period++) { pwr = VarGet("pwr" + period); Red = IIf(pwr > 0.5, 255, 2*255*pwr); Green = IIf(pwr > 0.5, 255*(2*pwr - 1), 0); PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel, Null, Null, 0, 0); } } if(isDomCyc) Plot(LastValue(dominantCycle,1), "Dominant Cycle", colorBlue, styleThick, Null, Null, 0, 1); pds=LastValue(dominantCycle,1); //"BB-MACD") Created by KelvinHand SetChartBkColor( ParamColor("background",colorBlack) ); A1=EMA(C,pds/2)-EMA(C,pds); BBtop=BBandTop(A1,10,1); BBbot=BBandBot(A1,10,1); Color=IIf(a1<0 AND a1>Ref(a1,-1), colorLime,IIf(a1>0 AND a1>Ref(a1,-1),colorBrightGreen,IIf(a1>0 AND a1<Ref(a1,-1),colorCustom12,colorRed))); Plot(a1,"MACD",color,styleThick+styleLine); Plot(BBtop,"BBtop",colorWhite,styleDashed); Plot(BBbot,"BBbot",colorWhite,styleDashed); Plot(0,"",colorWhite,1); AddColumn(round(dominantCycle), " DominantCycle", 2.0 , colorRed, colorLightYellow,50) ; return dominantCycle; } filtData = RoofingFilter(LPeriod, HPeriod); AutocorrelationPeriodogram(filtData, IsPlotHeatMap, IsPlotDominantCycle);
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.