klynn55 747 posts msg #61904 - Ignore klynn55 |
4/28/2008 7:04:42 PM
riggs: amibroker has this:
AMIBROKER: Bull And Bear Balance Indicator
In "Bull And Bear Balance Indicator," Vadim Gimelfarb presents a new indicator that tries to provide good estimation of bull and bear power balance without having the drawbacks of similar well-known indicators such as Elder-ray (by Alexander Elder) and balance of market power (by Igor Livshin). Bull and bear balance indicator (BBB) can be easily reproduced in AmiBroker using its native Afl language.
Listing 1 shows ready-to-use code that can be applied in the AmiBroker Indicator Builder. As suggested by the author, the code first calculates bull and bear powers, then smooths them separately with a 20-day moving average, and then smooths their difference (bull and bear balance) with a 30-day moving average. The smoothing periods can be changed on the fly without modifying the code using the parameters window.
LISTING 1
/* Bull-Bear Balance indicator */
BullPower =
IIf( C < O,
IIf( Ref( C, -1 ) < O,
Max( H - Ref( C, -1 ), C - L ),
Max( H - O, C - L ) ),
IIf( C > O,
IIf( Ref( C, -1 ) > O,
H - L,
Max( O - Ref( C, -1 ), H - L ) ),
IIf( H - C > C - L,
IIf( Ref( C, -1 ) < O,
Max( H - Ref( C, -1 ), C - L ),
H - O ),
IIf( H - C < C - L,
IIf( Ref( C, -1 ) > O,
H - L,
Max( O - Ref( C, -1 ), H - L ) ),
IIf( Ref( C, -1 ) > O,
Max( H - O, C - L ),
IIf( Ref( C, -1 ) < O,
Max( O - Ref( C, -1 ), H - L ),
H - L ) ) ) ) ) );
BearPower =
IIf( C < O,
IIf( Ref( C, -1 ) > O,
Max( Ref( C, -1 ) - O, H - L ),
H-L ),
IIf( C > O,
IIf( Ref( C, -1 ) > O,
Max( Ref( C, -1 ) - L, H - C ),
Max( O - L, H - C ) ),
IIf( H - C > C - L,
IIf( Ref( C, -1 ) > O,
Max( Ref( C, -1 ) - O, H - L ),
H - L ),
IIf( H - C < C - L,
IIf( Ref( C, -1 ) > O,
Max( Ref( C, -1 ) - L, H - C ),
O - L ),
IIf( Ref( C, -1 ) > O,
Max( Ref( C, -1 ) - O, H - L ),
IIf( Ref( C, -1 ) < O,
Max( O - L, H - C ),
H - L ) ) ) ) ) );
s1=Param("Smooth 1", 20, 1, 100 );
s2=Param("Smooth 2", 30, 1, 100 );
SmoothBBB= MA(EMA( BullPower,s1)-EMA( BearPower,s1),s2);
Caption = "Smoothed BBB ( " + s1 + ", " + s2 + " ) ";
Plot( SmoothBBB, Caption, colorBlue, styleHistogram );
|