home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
t
/
tas501.zip
/
DMI.TAS
< prev
next >
Wrap
Text File
|
1993-02-25
|
7KB
|
204 lines
#TITLE Wilder's Directional Movement Trading System
#MAX_QUOTES 150
#OUTPUT_FILE 'DMI.LST+'
{ DMI.TAS :
Script to implement Wilder's Directional Movement Trading
System.
Source : "DMI Trading Rules",Jim Summers,
Technical Analysis of Stocks and Commodities, Dec 1988
and "New Concepts in Technical Trading Systems", Wilder
--------------------Rules----------------------------
Enter Position if all of the following are true:
1) +DI and -DI cross
if +DI > -DI enter LONG
if +DI < -DI enter SHORT
2) ADXR > 25
3) ADX not below both +DI and -DI
4) ADX not above both +DI and -DI
Set Extreme Point on entry to position as follows:
if LONG, Extreme Point is LOW
if SHORT, Extreme Point is HIGH
Exit Position and either of the following:
1) ADX above both DI lines and then turns down
2) If DI lines cross against entry position AND
HIGH > Extreme Point (SHORT) or
LOW < Extreme Point (LONG)
------------SCRIPT IMPLEMENTATION DETAILS-------------
This script is somewhat complex, because Wilder's system
itself is complex. We are starting at the "current"
day, in each ticker file. If the entry conditions are
true, we put out a message indicating which position
we should take.
If, on the other hand, either of the Exit conditions are
true, the script does something you probably haven't
seen before. Imagine the ticker data is displayed on a
price bar chart. Using the pre-defined variable
"QUOTE_RANGE", it "slides" the "right" edge to the
left, one day at a time, until it finds an Entry
condition as shown in rules 1-4 of the Entry rules (above).
Each day is checked using a "subroutine" implemented using
GOSUB to the CHECKRULES routine.
This version works with TAS 3.62 or later only.
}
pdi_a : array; { +DI array }
mdi_a : array; { -DI array }
adx_a : array; { ADX array }
adxr_a : array; { ADXR array }
avg_adx : number; { Average ADX value across all tickers}
buy_signal : number;
sell_signal : number;
dmi_days = 14; { Number of days in ADX and DI calculations }
ADXR_limit = 20; { lower limit for ADX }
i : number; { Index for backing up in time }
j : number; { Another index for backing up in time }
rule1 : number; { +/-DI crossing}
rule2 : number; { ADX >= 20}
rule3 : number; { ADX not below both +/-DI}
rule4 : number; { ADX not above both +/-DI}
postype : number; { Position type LONG(+1), SHORT(-1) none(0)}
opostype : number; {Open position type}
epostype : number; {Exit position type}
extreme_point : number; { Extreme Point Rule value}
oextreme_point : number; { Open Extreme Point Rule value}
warning : number;
if first_ticker then
begin
writeln(
'--------------------------------------------------------------');
writeln(
'Signals based on Welles Wilders Directional Movement System');
writeln(
' ');
writeln(
'Action Description ');
writeln(
'------ --------------------------------------------------');
writeln(
'Open ADXR > 25, +DI crossed -DI, and ADX between +/-DI');
writeln(
'Exit (ExP) +DI crossed -DI and Extreme Point violated');
writeln(
'Exit (ADX) ADX above +DI and -DI and turned down');
writeln(
'Warning +DI and -DI crossed, but Extreme Point not ');
writeln(
' violated');
writeln(
'--------------------------------------------------------------');
writeln(
' EXTREME CURRENT OPEN');
writeln(
'TICKER ACTION POSITION POINT CLOSE DATE');
end;
if quote_count < dmi_days * 3 then return;
ticker_count = ticker_count + 1;
pdi_a = pdi(dmi_days);
mdi_a = mdi(dmi_days);
adx_a = adx(dmi_days);
adxr_a = adxr(dmi_days);
postype = 0;
warning = 0;
opostype = 0;
epostype = 0;
j = quote_range; { short name for index back in time}
{ check if adx has turned down}
if adx_a > pdi_a and adx_a > mdi_a and
adx_a[0] < adx_a[-1] and adx_a[-1] > adx_a[-2] then begin
epostype = 2;
end;
if epostype = 2 then { adx turned down..see if we had open pos}
goto BACKCHECK;
GOSUB CHECKRULES;
:RETURN1 { this is where CHECKRULES returns if
switch = 1}
opostype = postype;
oposition = position;
oextreme_point = extreme_point;
postype = 0;
{ Not entering a position..see if we should exit a prior one }
IF rule1 = 0 THEN GOTO TICKDONE; { DI lines did not cross today }
{ DI lines crossed..see if this is the time to exit a prior position}
i = 1;
:BACKCHECK
quote_range = quote_count - i; { lower top of array }
j = quote_range; { short name for index back in time}
{Stop when we have less than twice the DMI period days left}
if quote_range <= dmi_days * 2 then goto NOPRIOR;
if isect(pdi_a,mdi_a) < 0 then goto NOPRIOR;
GOSUB CHECKRULES;
:RETURN2
if postype <> 0 then GOTO EXITRULE;
i = i + 1;
GOTO BACKCHECK;
:EXITRULE
{ we have found entry position }
quote_range = quote_count; { reset quote range back to present}
if epostype = 2 then { exit because of adx turning down}
goto TICKDONE;
if postype = -1 then
if extreme_point < H then
epostype = postype
else
warning = 1;
if postype = 1 then
if extreme_point > L then
epostype = postype;
else
warning = 1;
:NOPRIOR
GOTO TICKDONE;
{ This is a "subroutine" to check if a position should be entered.
It sets variable "position" to either LONG or SHORT if so}
:CHECKRULES
position = ' ';
postype = 0;
rule1 = isect(pdi_a,mdi_a) = 0; { if +DI intersected -DI today}
rule2 = adxr_a[j] > ADXR_limit;
rule3 = adx_a[j] >= pdi_a[j] OR adx_a[j] >= mdi_a[j];
rule4 = adx_a[j] <= pdi_a[j] OR adx_a[j] <= mdi_a[j];
IF rule1 AND rule2 AND rule3 AND rule4 THEN
BEGIN
IF pdi_a[j] > mdi_a[j] THEN
BEGIN
position = 'LONG ';
postype = 1;
extreme_point = l[j]; { if long, extreme point is low}
END
ELSE
BEGIN
position = 'SHORT';
postype = -1;
extreme_point = h[j]; { if short, extreme point is high}
END;
END;
RETURN; { to caller of CHECKRULES}
:TICKDONE
if warning <> 0 then { If giving a warning, don't open position}
opostype = 0;
if warning = 1 then
writeln(TICKER,'Warning ',position ,' ',extreme_point,' ',C,
' ',datestr(dates[j]));
if epostype <> 0 then
if epostype = 2 then
if postype <> 0 then
begin
emsg = 'Exit (ADX) '
eposition = position;
epostype = postype;
end
else
epostype = 0
else
emsg = 'Exit (ExP) ';
if epostype <> 0 then
writeln(TICKER,emsg,position ,' ',extreme_point ,' ',C,
' ',DATESTR(DATES[j]));
if opostype <> 0 then
writeln(TICKER,'Open ',oposition,' ',oextreme_point,' ',C,
' ',DATE);
avg_adx = avg_adx + adx_a;
IF last_ticker then
BEGIN
writeln('Average ADX is ',avg_adx/ticker_count);
END;