Ton,
The intent appears to be to split the BP[1] values into peaks
and valleys such that the two averages can be calculated independent of the
other.
Mike
--- In amibroker@xxxxxxxxxps.com,
"Ton Sieverding" <ton.sieverding@...> wrote:
>
> Hi
John. It's not that I cannot translate lines 29 thru 36 in AFL. My problem is
that I do not understand the code :
>
> 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] ;
>
>
What's the difference between Peak and Valley in the above code ? For me they
always have the same value because whatever happens this value is BP[1]
...
>
> BTW BP is an array and AFL handles this with the double
if.( Iff( BP<Ref(BP,-1) etc. ) ...
>
> Regards, Ton.
>
>
> ----- Original Message -----
> From: bbands
>
To: amibroker@xxxxxxxxxps.com
> Sent: Wednesday, March 03, 2010 5:01 PM
> Subject: [amibroker]
Re: Empirical Mode Decomposition
>
>
>
> 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" ) ;
>