AFL Formula Library: DeMarker and Range Expansion Index

DeMarker

The DeMarker indicator is an attempt to overcome the shortcomings of classical overbought / oversold indicators. The DeMarker Indicator identifies potential price bottoms and tops. It accomplishes this by making price comparisons from one bar to the next and measuring the level of price demand. The formula for DeMarker is quite simple - in AFL it looks like this:

/*

** Tom Demark's DeMarker Indicator

** AFL Implementation by Tomasz Janeczko

*/

highm = IIF( H > Ref( H, -1 ), H - Ref( H, - 1), 0 );

lowm = IIF( L < Ref( L, -1 ), Ref( L, - 1 ) - L, 0 );
DeMarker = 100 * Sum( highm, 13 )/( Sum( lowm, 13 ) + Sum( highm, 13 ) );
graph0 = DeMarker;
DeMarker should be interpreted as other overbought / oversold indicators such as RSI with the levels of 30 and 70. Compared to RSI it is smoother but still able to detect tops and bottoms a little bit better.
Range Expansion Index
The DeMark Range Expansion Index is a market-timing oscillator described in DeMark on Day Trading Options, by T.R. DeMark and T.R. Demark, Jr., McGraw Hill, 1999. The oscillator is arithmetically calculated and is designed to overcome problems with exponentially calculated oscillators, like MACD. The TD REI oscillator typically produces values of -100 to +100 with 45 or higher indicating overbought conditions and -45 or lower indicating oversold. Here is how Tom DeMark describes the calculation of Range Expansion Index:
"The first step in calculating the REI is to add together the respective differences between the current day's high and the high two days earlier and the current day's low and the low two days earlier. These values will be positive or negative depending on whether the current day's high and low are greater or less than the high and low two days earlier. To prevent buying or selling prematurely into a steep price decline or advance, two additional conditions should be met to qualify a positive or negative value on a particular day: 1) either the high two days earlier must be greater than or equal to the close seven or eight days ago, or the current day's high must be greater than or equal to the low five or six days ago; 2) either the low two days earlier must be less than or equal to the close seven or eight days ago, or the current day's low must be less than or equal to the high five or six days ago. If either of these conditions are not satisfied, a zero value is assigned to that day. If they both are, the daily values (the differences between the highs and lows) are summed , and the specific value for that next day is determined. Next, all the positives and negative values are added together over a five-day period. This value is then divided by the absolute value price movement of each day over the five-day period. The numerator of the calculation can be either positive, negative or zero, because each day's value is summed for five days, but the denominator is always positive because it is only concerned with the differential price movement itself. This value is then multiplied by 100. Consequently, the REI can fluctuate between +100 and -100."
Following this description I wrote the AFL formula for REI:
/*
** Tom DeMark's Range Expansion Index
** AFL Implementation by Tomasz Janeczko
*/
HighMom = H - Ref( H, -2 );
LowMom = L - Ref( L, -2 );
Cond1 = ( H >= Ref( L,-5) OR H >= Ref( L, -6 ) );

Cond2 = ( Ref( H, -2 ) >= Ref( C, -7 ) OR Ref( H, -2 ) >= Ref( C, -8 ) );

Cond3 = ( L <= Ref( H, -5 ) OR L <= Ref( H, -6) );
Cond4 = ( Ref( L, -2 ) <= Ref( C, -7 ) OR Ref( L, -2 ) <= Ref( C, -8 ) );
Cond = ( Cond1 OR Cond2 ) AND ( Cond3 OR Cond4 );
Num = IIf( Cond, HighMom + LowMom, 0 );
Den = Abs( HighMom ) + Abs( LowMom );
TDREI = 100 * Sum( Num, 5 )/Sum( Den, 5 ) ;
graph0 = TDREI;
DeMark advises against trading in extreme overbought or oversold conditions indicated by six or more bars above or below the 45 thresholds. For more information on calculation and using both TD REI and DeMarker indicator check Tom DeMark's site.

## 21 April 2011

## 14 April 2011

## 06 April 2011

### ZeroLag W%R for Amibroker (AFL)

Williams %R, or just %R, is a technical analysis oscillator showing the current closing price in relation to the high and low of the past N days (for a given N). It was developed by a publisher and promoter of trading materials, Larry Williams. Its purpose is to tell whether a stock or commodity market is trading near the high or the low, or somewhere in between, of its recent trading range.The oscillator is on a negative scale, from -100 (lowest) up to 0 (highest), considered unusual since it is the obverse of the more common 0 to 100 scale found in many Technical Analysis oscillators. Although sometimes altered (by simply adding 100), this scale needn’t cause any confusion. A value of -100 is the close today at the lowest low of the past N days, and 0 is a close today at the highest high of the past N days.

Williams used a 10 trading day period and considered values below -80 as oversold and above -20 as overbought. But they were not to be traded directly, instead his rule to buy an oversold was

R reaches -100.

Five trading days pass since -100% was last reached

R rises above -95 or -85%.

or conversely to sell an overbought condition

R reaches 0.

Five trading days pass since 0% was last reached

R falls below -5 or -15%.

The timeframe can be changed for either more sensitive or smoother results. The more sensitive you make it, though, the more false signals you will get. The “close-position within a range” in the %R indicator is the same as the %K stochastic oscillator, on a different scale.

period1 = Param( "Period 1", 10, 2, 200, 1 );

period2 = Param( "Period 2", 5, 2, 200, 1 );

/*ZeroLag W%R*/

"========";

GraphXSpace = 3;

R = ((HHV(H,14) - C) /(HHV (H,14) -LLV (L,14))) *-100;

MaxGraph=10;

//Period= 10;

EMA1= EMA(R,period1);

EMA2= EMA(EMA1,period2);

Difference= EMA1 - EMA2;

ZeroLagEMA= EMA1 + Difference;

PR=100-abs(ZeroLagEMA);

Graph0=PR;

MoveAvg=MA(PR,5);

Graph1=MoveAvg;

Graph1Color=colorTan;

Graph0Style=4;

upbar= PR>= MoveAvg AND PR>= Ref(PR,-1) ;

downbar=(PR < MoveAvg) OR PR>= MoveAvg AND PR< Ref(PR,-1) ;

barcolor = IIf( downbar,colorRed, IIf( upbar, colorBrightGreen, 7));

Graph0BarColor = ValueWhen( barcolor != 0, barcolor );

Graph2=30;

Graph3=70;

Graph2Style=Graph3Style=Graph4Style=1;

Graph4Color=2;

Graph2Color=5;

Graph3Color=4;

Graph5=0;

Graph6=100;

Graph5Style=Graph6Style=1;

Graph5Color=Graph6Color=2;

Title=Name()+" < ZeroLag W%R :"+WriteVal(PR)+"%";

Williams used a 10 trading day period and considered values below -80 as oversold and above -20 as overbought. But they were not to be traded directly, instead his rule to buy an oversold was

R reaches -100.

Five trading days pass since -100% was last reached

R rises above -95 or -85%.

or conversely to sell an overbought condition

R reaches 0.

Five trading days pass since 0% was last reached

R falls below -5 or -15%.

The timeframe can be changed for either more sensitive or smoother results. The more sensitive you make it, though, the more false signals you will get. The “close-position within a range” in the %R indicator is the same as the %K stochastic oscillator, on a different scale.

period1 = Param( "Period 1", 10, 2, 200, 1 );

period2 = Param( "Period 2", 5, 2, 200, 1 );

/*ZeroLag W%R*/

"========";

GraphXSpace = 3;

R = ((HHV(H,14) - C) /(HHV (H,14) -LLV (L,14))) *-100;

MaxGraph=10;

//Period= 10;

EMA1= EMA(R,period1);

EMA2= EMA(EMA1,period2);

Difference= EMA1 - EMA2;

ZeroLagEMA= EMA1 + Difference;

PR=100-abs(ZeroLagEMA);

Graph0=PR;

MoveAvg=MA(PR,5);

Graph1=MoveAvg;

Graph1Color=colorTan;

Graph0Style=4;

upbar= PR>= MoveAvg AND PR>= Ref(PR,-1) ;

downbar=(PR < MoveAvg) OR PR>= MoveAvg AND PR< Ref(PR,-1) ;

barcolor = IIf( downbar,colorRed, IIf( upbar, colorBrightGreen, 7));

Graph0BarColor = ValueWhen( barcolor != 0, barcolor );

Graph2=30;

Graph3=70;

Graph2Style=Graph3Style=Graph4Style=1;

Graph4Color=2;

Graph2Color=5;

Graph3Color=4;

Graph5=0;

Graph6=100;

Graph5Style=Graph6Style=1;

Graph5Color=Graph6Color=2;

Title=Name()+" < ZeroLag W%R :"+WriteVal(PR)+"%";

Subscribe to:
Posts (Atom)