I've included the TradeStation code below. It is lines 29 through 36 that I
am having trouble realizing in AB.
TIA,
John
1.
Indicator: EmpiricalMode
2. inputs:
3. Price( 0.5 * ( High + Low )
),
4. Period( 20 ),
5. Delta1( 0.5 ),
6. Fraction( 0.1 ) ;
7.
variables:
8. Beta1( 0 ),
9. Gamma1( 0 ),
10. Alpha( 0 ),
11.
HalfAlphaDiff( 0 ),
12. Beta1OnePlusAlpha( 0 ),
13. BP( 0 ),
14.
Trend( 0 ),
15. Peak( 0 ),
16. Valley( 0 ),
17. AvgPeak( 0 ),
18.
FracAvgPeak( 0 ),
19. AvgValley( 0 ),
20. FracAvgValley( 0 )
;
21. Beta1 = Cosine( 360 / Period ) ;
22. Gamma1 = 1 / Cosine( 720
* Delta1 / Period ) ;
23. Alpha = Gamma1 - SquareRoot( Square( Gamma1 ) - 1
) ;
24. HalfAlphaDiff = 0.5 * ( 1 - Alpha ) ;
25. Beta1OnePlusAlpha =
Beta1 * ( 1 + Alpha ) ;
26. BP = HalfAlphaDiff * ( Price - Price[2] )
+
27. Beta1OnePlusAlpha * BP[1] - Alpha * BP[2] ;
28. Trend = Average(
BP, 2 * Period ) ;
29. if BP[1] > BP and BP[1] > BP[2] then
30. Peak = BP[1]
31. else if BP[1] < BP and BP[1] < BP[2] then
32. Valley = BP[1] ;
33. AvgPeak = Average( Peak, 50 ) ;
34.
FracAvgPeak = Fraction * AvgPeak ;
35. AvgValley = Average( Valley, 50 )
;
36. FracAvgValley = Fraction * AvgValley ;
37. Plot1( Trend,
"Trend" ) ;
38. Plot2( FracAvgPeak, "AvgPeak" ) ;
39. Plot3(
FracAvgValley, "AvgValley" ) ;