Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

ADVANCED Strategies

THE VELOCITY SYSTEM


TABLE 1 TEST-SAMPLE PERFORMANCE SUMMARY
FOR LEAST SQUARES VELOCITY SYSTEM
The initial sample test period produced the following results using
the optimized parameter values.

The rate of price


movement in a stock can
be thought of as

QQQ five-minute bars Oct. 9 Nov. 8, 2002

velocity. Increasing

Performance summary: All trades


Total net profit
Gross profit
Total # of trades
Number winning trades
Largest winning trade
Average winning trade
Ratio avg. win/avg. loss
Max. consec. winners
Avg. # bars in winners

$4,400.00
$8,150.00
42
25
$1,140.00
$326.00
1.48
6
46

Open position P/L


Gross loss
Percent profitable
Number losing trades

$0.00
($3,750.00)
59.52%
17

Largest losing trade


($530.00)
Average losing trade
($220.59)
Avg. trade (win & loss) $104.76
Max. consec. losers
Avg. # bars in losers

Max. intraday drawdown ($1,450.00)


Profit factor
2.17
Max. # contracts held

3
27
1

Performance summary: Long trades


Total net profit
Gross profit
Total # of trades
Number winning trades
Largest winning trade
Average winning trade
Ratio avg. win/avg. loss
Max. consec. winners
Avg. # bars in winners
Max. intraday drawdown
Profit factor

$4,320.00
$6,560.00
28
17
$1,140.00
$385.88
1.89
5
56
($780.00)
2.93

Open position P/L


Gross loss
Percent profitable
Number losing trades

$0.00
($2,240.00)
60.71%
11

Largest losing trade


($510.00)
Average losing trade
($203.64)
Avg. trade (win & loss) $154.29
Max. consec. losers
Avg. # bars in losers
Max. # contracts held

2
37
1

Performance summary: Short trades


Total net profit
Gross profit
Total # of trades
Number winning trades
Largest winning trade
Average winning trade
Ratio avg. win/avg. loss
Max. consec. winners
Avg. # bars in winners

$80.00
$1,590.00
14
8
$380.00
$198.75
.79
3
24

Open position P/L


Gross loss
Percent profitable
Number losing trades

57.14%
6

Largest losing trade


($530.00)
Average losing trade
($251.67)
Avg. trade (win & loss)
$5.71
Max. consec. losers
Avg. # bars in losers

Max. intraday drawdown ($1,170.00)


Profit factor
1.05
Max. # contracts held
Source: TradeStation Platform by TradeStation Group

36

$0.00
($1,510.00)

3
9
1

positive velocity sets up


long trades, while
growing negative velocity
sets up short trades.
To filter out noise and
decrease whipsaws, you
can use a least-squares
trendline to measure
velocity and determine
entry points.
BY DENNIS MEYERS, PH.D.

n a chart, price moves


along a path relative to
time. In other words, it
has velocity, which is
defined as the change of position per
unit of time. If a stock moves sideways,
the velocity is low and there are no real
trading opportunities. However, if
velocity begins to rise, an opportunity
may occur.
There are a number of ways to measure velocity. The simplest measurement
is the difference between the current
price and the price x bars ago. However,
there is always a large amount of
noise (i.e., irrelevant fluctuations) in

www.activetradermag.com July 2003 ACTIVE TRADER

TABLE 2 OUT-OF-SAMPLE PERFORMANCE SUMMARY


FOR LEAST-SQUARES VELOCITY SYSTEM
Testing the optimized system parameters from the first test on out-of-sam ple price data produced better results in some respects.
price movement, which creates false
buy and sell signals for many trading
systems.
To better capture meaningful price
movement, we will use another technique to measure velocity: monitoring
the slope of a best-fit (or leastsquares) trendline. The change in the
slope will indicate the price velocity.
The least-squares velocity acts as a
price noise inhibitor or filter that identifies the underlying trend and its velocity. As a result, its logical to create a system that requires the velocity be greater
than some threshold before buying or
selling. (For more information on calculating a least-squares line, see The
least-squares line, p. 38.)
The resulting Least-Squares Velocity
(LSV)system is a cousin of the Next Bar
Forecast (NBF) system described in the
May 2003 issue of Active Trader (p. 46).
Like the NBF, the LSV system will be
tested on five-minute bars of the
Nasdaq 100 index-tracking stock
(QQQ). The results of the LSV test will
be compared to those of the NBF and
the Maximum Likelihood Range system (MLR), presented in Range roving, Active Trader, March 2003, p. 58.

QQQ five-minute bars Nov. 11 Nov. 22, 2002


Performance summary: All trades
Total net profit
Gross profit
Total # of trades
Number winning trades
Largest winning trade
Average winning trade
Ratio avg. win/avg. loss
Max. consec. winners
Avg. # bars in winners

$2,760.00
$3,470.00
17
11
$970.00
$315.45
2.67
3
46

Max. intraday drawdown ($470.00)


Profit factor
4.89
Total net profit
Gross profit
Total # of trades
Number winning trades
Largest winning trade
Average winning trade
Ratio avg. win/avg. loss
Max. consec. winners
Avg. # bars in winners
Max. intraday drawdown
Profit factor

$2,670.00
$3,010.00
11
8
$970.00
$376.25
3.32
4
56
($340.00)
8.85

Performance summary: Short trades

The slope (m) of a straight line can also


be called velocity. Recall that velocity is
defined as the position change per time
unit. Using the formula for a straight
line provided in The least-squares
line, velocity would be defined as:

Total net profit


Gross profit

The least-squares velocity will be calculated at each bar. When velocity is


positive and high, it indicates upward
momentum and a long-trade opportunity; reverse the scenario for negative
continued on p. 39

Percent profitable
Number losing trades

$0.00
($710.00)
64.71%
6

Largest losing trade


($270.00)
Average losing trade
($118.33)
Avg. trade (win & loss)
$162.35
Max. consec. losers
Avg. # bars in losers
Max. # contracts held

2
30
1

Performance summary: Long trades

Building a velocity system

Velocity = [b+m*(x+1)] [b+m*x] = m

Open position P/L


Gross loss

Total # of trades
Number winning trades
Largest winning trade
Average winning trade
Ratio avg. win/avg. loss
Max. consec. winners
Avg. # bars in winners

$90.00
$460.00
6
3
$280.00
$153.33
1.24
2
19

Max. intraday drawdown ($380.00)


Profit factor
1.24

Open position P/L


Gross loss
Percent profitable
Number losing trades

$0.00
($340.00)
72.73%
3

Largest losing trade


($150.00)
Average losing trade
($113.33)
Avg. trade (win & loss)
$242.73
Max. consec. losers
Avg. # bars in losers
Max. # contracts held
Open position P/L
Gross loss
Percent profitable
Number losing trades

1
49
1
$0.00
($370.00)
50.00%
3

Largest losing trade


($270.00)
Average losing trade
($123.33)
Avg. trade (win & loss)
$15.00
Max. consec. losers
Avg. # bars in losers
Max. # contracts held

2
12
1

Source: TradeStation Platform by TradeStation Group

ACTIVE TRADER July 2003 www.activetradermag.com

37

Least-squares line

inear regression is a way to calculate a straight


line that best fits a series of data points that
is, a line that most accurately reflects the slope,
or trend, of that data. In terms of price analysis, a linear
regression line is used to determine the trend of closing
prices over a given time period. Because it is mathematically derived, a regression line, or best-fit line, is not
based on subjective, visual analysis, as are standard
trendlines.
Figure 1 (right) shows a group of five closing prices on a
price chart. A straight line that goes through the middle
of those five prices a line for which the difference
between it and each of the zigzagging prices is as small as
possible is a regression line.

Calculation
A regression line is calculated using the least-squares
method, which refers to finding the minimum squared
(x*x, or x2) differences between price points and a
straight line. For example, if two closing prices are 2 and
3 points away (the distance being calculated vertically)
from a straight line, the squared differences between the
points and the line are 4 and 9, respectively.
Why are the squared differences used, instead of just
the differences? Figure 1 shows that some differences
are negative (for points below the line) and others are
positive (for points above the line). This makes it necessary to square all the differences, creating all positive
values and making it possible to calculate a formula for
the straight line.
The best-fit line is the line for which the sum of the
squared differences between each price and the straight
line are minimized.
The formula for a straight line (y) is:
y = b + m*x
where
x = the time of the price (the x-axis value)
b = the initial value of the line when x is equal to
zero (the intercept value i.e., the point at which the
line intercepts the vertical axis);
m = the slope of the line, which is the rate at which the
line rises or falls. In other words, b is how much y changes
for a one-unit change in x (e.g., .75 points per day).

38

As prices change, the slope of the line also changes.


When a market is rising sharply the slope (b) has a high
value and the line will be steep. As the market slows
down, the slope value decreases and the line will slope
upward more gently.
When calculating a straight line to N prices, the bestfit coefficients b and m can be solved for by:
N

b = [(4N+2)/(N 2-N)] p(x) + [6/(N2-N)] x*p(x)


x=1

x=1

x=1

x=1

m = [12/(N 3N)] x*p(x) [6/(N 2-N)]p(x)


where
p(x) is the price at point x.
N is the number of prices used to calculate the coefficients e.g., N = 5 for a five-day regression calculation.
In this case, the first day p(1) in the price series is 1 and
the last price p(N) in the series is 5.
N

p(x) is the sum of the prices for p(1) through p(N).


For example, if N = 5 and the prices for days 1
and 2 are 10, 11, 12, 13 and 14, respectively, the sum is
60.
x=1

x*p(x) is the sum of the products of time (x) and


price (p). For example, the products of the
prices used in the previous calculation are 10
(1*10), 22 (2*11), 36 (3*12), 52 (4*13) and 70 (5*14), and
the sum of those products is 190.
x=1

Figure 2 (right) shows the calculations and chart of three


five-day regression lines calculated at different points over
a 10-day period: Line A covers days 1 through 5; line B represents days 4 through 8; and line C is days 6 through 10.
The linear regression estimates for the slopes (b) and
intercept values (a) are listed in the third and fourth
columns. The values for each of the five points that make
up regression lines A, B and C are in the final three columns
The slope for line A (days 1-5), which accompanies an
upward trend, is 0.60. Price continued to rally higher in
days 6 through 8, but at a slower rate, which resulted in
a slope of .43 for line B. For line C, when price moved
sideways to lower, the slope was -0.07.

www.activetradermag.com July 2003 ACTIVE TRADER

FIGURE 1 FITTING A STRAIGHT LINE TO PRICES


A regression or best-fit line is calculated to minimize the
difference between price points and the line. In doing so, the line
approximates the slope (trend) of the prices.
20

Price

18
16
14

1. Buy rule: If velocity is greater than


the threshold amount vup, buy QQQ at
the market.

Straight line

12

Differences

2. Sell rule: If velocity is less than the


threshold amount -vdn, sell QQQ at the
market.

10
8

3. Intraday bars exit rule: Close the


position five minutes before the close
(no trades are carried overnight).

FIGURE 2 REGRESSION LINES


The following calculations resulted in the three different five-day
regression lines on the chart below.
Day
1
2
3
4
5
6
7
8
9
10
25.00
24.50
24.00
23.50
23.00
22.50
22.00
21.50
21.00
20.50
20.00

Price
21.25
20.50
21.00
22.50
23.25
24.20
23.25
24.66
23.00
24.00

Slope (m)

Intercept (b) Line A


20.50
21.10
21.70
22.30
19.90
22.90

0.60

0.43

22.28

-0.07

24.02

Line B

Line C

23.95
23.89
23.82
23.76
23.69

A
Y=24.02-0.07*X
Y=22.28+0.43*X
Y=19.90+0.60*X
2

4. Intraday bars first trade of day


entry rule: Ignore all trade signals
before 10 a.m. ET (30 minutes after the
open). Opening gaps that create trigger
trades are often closed quickly, creating
losing whipsaw trades. This rule is
designed to avoid the problem.

Testing the system

22.71
23.14
23.57
24.00
24.44

Price

velocity and short trades. One of the


goals, therefore, is determining what
constitutes strong upward and downward velocity.
Using this basic velocity principle,
when velocity exceeds a certain threshold (to be determined later through
optimization), we will go long. When
velocity is less than a certain threshold,
we will go short. These are the rules:

10

We will use historical testing to determine the best systems parameters,


which are defined as the values that
produce the highest average per-trade
net profit and the highest total winning
bars to total losing bars ratio, with the
smallest drawdown, largest losing trade
value and no more than four losses in a
row (because of the psychological difficulty of trading a system that produces
more consecutive losers than this).
In addition, these parameters should
produce stable results, which means the
profit, winning percentage and drawdown figures should not change by
much as the parameters are adjusted a
small amount either way.
A walk-forward optimization test
was used consisting of an initial test on
a sample data set (used to determine
continued on p. 40

ACTIVE TRADER July 2003 www.activetradermag.com

39

FIGURE 1 QQQ FIVE-MINUTE BARS LEAST-SQUARES VELOCITY SYSTEM


Trades from the out-of-sample test are shown along with the bar-by-bar prof it or loss (below the price series). Overall, the system was effective at catch ing intraday trends during this period.
Nasdaq 100 index-tracking stock (QQQ), five-minute

26.20
26.00
25.80
25.60

Exit
Sell

Sell

25.40

Buy

25.20

Sell

25.00
24.80

Buy

Buy

Exit

Exit

24.60
24.40

Buy

Buy

24.20
0.060

Velocity

0.040
0.020
0.000
-0.020
11/11

11:30 13:05

11/12

11:05 12:40

11/13

10:40 12:15

-0.040

11/14 10:15 11:50

Nasdaq 100 index-tracking stock (QQQ), five-minute


Exit

26.80
26.60

Sell

Exit

26.40

the optimal system values i.e., the


best parameters for that period)
and a second test on an out-of-sample
data set using the optimal parameters,
which will allow us to verify their value.
The sample data period consisted of one
month of five-minute QQQ bars (Oct. 9
to Nov. 8, 2002), and the out-of-sample
data was two weeks of five-minute QQQ
bars (Nov. 11 to Nov. 22, 2002).
The sample portion of such a test is
likely to produce favorable results, but
this does not mean the system will perform well in real trading. Only successful performance on out-of-sample data
can provide any indication a system will
work in the future.
There are three system parameters to
determine in the optimization:

26.20

Buy

26.00

Exit Sell
Buy

Sell 25.80
25.60

Buy

25.40

Buy

25.20

1. Len, the lookback period to calculate


velocity;
2. vup, the threshold amount velocity
has to be greater than to issue a buy signal; and
3. vdn, the threshold amount velocity
has to be less than to issue a sell signal.

0.060

Velocity

0.040
0.020
0.000

The optimal system parameters


derived from the initial sample-test data
are shown below:

-0.020
11/14 11:50 13:25

11/15

11:25 13:00

11/18

11:00 12:35

Start
date

27.00

10/9/02

11/19 10:35 12:10

Exit

Nasdaq 100 index-tracking stock (QQQ),


five-minute

-0.040

Exit

26.80
26.60

Buy

Exit

26.40

Buy

26.20
26.00

Sell

25.80

Exit

25.60

Buy

Buy
Short

25.40

Velocity

0.060
0.040
0.020

10:35 12:10 13.:45 11/20 10:10 11:45 13:20

11/21

11:20 12:55

Source: TradeStation Platform by TradeStation Group

11/22

10:55 12:30

0.000
-0.020
-0.040

End
date

Len

11/8/02

16

vup

vdn

0.001 0.023

Table 1 (p. 36) shows the performance


summary of the sample test segment.
These parameters were then tested on
the out-of-sample data to simulate the
experience of trading in real-time on
new price data. Table 2 (p. 37) shows the
performance summary of the out-ofsample test. Slippage and commissions
are not included in any of the test results.

Live vs. Memorex


As it turned out, a comparison of Tables
1 and 2 shows the out-of-sample results
were better than the in-sample results.
The average win/loss ratio, drawdown
and profit factor were all better in the

out-of-sample data.
However, there was a more trending
price action in the out-of-sample period,
and much of the superior performance
can likely be attributed to that.
Specifically, Table 2 shows the system
did much better on long trades than
short trades, the result of a long uptrend
in the out-of-sample period.
The average trade (on 1,000 shares of
QQQ) resulted in a $105 profit in the test
section and $162 in the out-of-sample
section. The profit factor in the out-ofsample section was twice as high as the
comparable figure in the test section.
Also, during every up day from Nov. 11
to Nov. 22, the system remained in one
long trade all day, showing the system
was able to avoid getting knocked out
of the market and having to re-enter,
resulting in whipsaw losses. Also, the
system produced no big winners or big
losers, which means the system did not
rely on a few exceptional trades that are
not representative of the systems basic
characteristics.
Figures 1a-1c (opposite page) are
five-minute price charts of QQQ from
Nov. 11 to Nov. 22 (the out-of-sample
period). The Least-Squares Velocity
indicator is plotted along with price.
(The buy and sell signals can be viewed
as part of the trade-by-trade summary
of the out-of-sample trades in the Web
Extra for this article at www.activetradermag.com from June 10 to June 30.)
These charts show the system produced
steady returns, which is all anyone can
ask of a trading system.

System comparison
One reason for choosing these particular test periods was to compare the LSV
out-of-sample results with the out-ofsample results of the Next Bar Forecast
system (NBF) and the Maximum
Likelihood Range system (MLR).
Tables 3 (right) and 4 (p. 45) show the
performance summary of the MLR system and the NBF system, respectively,
on the out-of-sample data segment from
Nov. 11 to Nov. 22, 2002.
continued on p. 45

TABLE 3 OUT-OF-SAMPLE PERFORMANCE SUMMARY


FOR MAXIMUM LIKELIHOOD RANGE SYSTEM
The net profit of the LSV system was similar to that of the Maximum
Likelihood Range system. However, the drawdown and largest losing trade
were much less for the LSV.
QQQ five-minute bars Nov. 11 Nov. 22, 2002
Performance summary: All trades
Total net profit
Gross profit
Total # of trades
Number winning trades

$2,680.00
$3,570.00
11
7

Open position P/L


Gross loss
Percent profitable
Number losing trades

$0.00
($890.00)
63.64%
4

Largest winning trade


$1,110.00
Average winning trade
$510.00
Ratio avg. win/avg. loss
2.29

Largest losing trade


($490.00)
Average losing trade
($225.50)
Avg. trade (win & loss)
$246.64

Max. consec. winners


Avg. # bars in winners

Max. consec. losers


Avg. # bars in losers

4
71

Max. intraday drawdown ($910.00)


Profit factor
4.01

Max. # contracts held

3
52
1

Performance summary: Long trades


Total net profit
Gross profit
Total # of trades
Number winning trades

$2,760.00
$3,570.00
10
7

Open position P/L


Gross loss
Percent profitable
Number losing trades

$0.00
($810.00)
70.00%
3

Largest winning trade


$1,110.00
Average winning trade
$510.00
Ratio avg. win/avg. loss
0.89

Largest losing trade


($490.00)
Average losing trade
($270.00)
Avg. trade (win & loss)
$276.00

Max. consec. winners


Avg. # bars in winners

Max. consec. losers


Avg. # bars in losers

Max. intraday drawdown


Profit factor

4
71

($830.00)
4.41
Max. # contracts held

2
66
1

Performance summary: Short trades


Total net profit
Gross profit
Total # of trades
Number winning trades
Largest winning trade
Average winning trade
Ratio avg. win/avg. loss
Max. consec. winners
Avg. # bars in winners

($80.00)
$0.00
1
0
$0.00
$0.00
(0.00)
0
0

Max. intraday drawdown ($220.00)


Profit factor
(0.00)

Open position P/L


Gross loss
Percent profitable
Number losing trades
Largest losing trade
Average losing trade
Avg. trade (win & loss)

$0.00
($80.00)
0.00%
1
($80.00)
($80.00)
($80.00)

Max. consec. losers


Avg. # bars in losers

1
8

Max. # contracts held

Source: TradeStation Platform by TradeStation Group

ACTIVE TRADER July 2003 www.activetradermag.com

41

Advanced Strategies
continued from p. 41
The LSV system produced an out-ofsample net profit of $2,760, while the
MLR produced a net profit of $2,680.
However, the LSVs slightly higher net
profits were produced with about 50
percent more trades. The LSV system
had a per-trade net profit of $162 compared to the MLR systems $243.
If $50 for slippage and commission
were subtracted from each system for
each trade, the total net profits of each
system would still be approximately the
same. However, in looking at the out-ofsample drawdowns and largest losing
trades, the LSV system has a clear
advantage. In both cases, the MLR figures are almost twice those of the LSV.
In comparison with the NBF system,
the LSV system produced a net profit of
$470 less than the NBF ($2,760 vs.
$3,230). The NBFs higher profits were
produced with more trades. The LSV
system had an average profit-per-trade
of $162; the average profit-per-trade for
the MLR system was $134. Again, subtracting $50 for slippage and commission per trade would make these figures
much closer.
Looking at the out-of-sample drawdowns and largest losing trades of each
system, the NBF has a clear advantage.
Its results in those categories are half of
what the LSV system produced. In addition, the NBF system was able to generate short trade profits while LSV system
was only minimally effective in this
regard and the MLR lost money on the
short side.
Overall, the NBF system performed
much better on the out-of-sample data
than the Maximum Likelihood Range system or the Least-Square Velocity system.
At least 20 more tests on different sets
of sample and out-of-sample data would
be necessary to confirm the viability of
the results shown here. Both test periods
were dominated by uptrending conditions; down markets have different intraday characteristics that could significantly affect system performance.
For information on the author see p. 10.

TABLE 4 OUT-OF-SAMPLE PERFORMANCE SUMMARY


FOR NEXT BAR FORECAST SYSTEM
Overall, the Next Bar Forecast system did a better job of trading the QQQs
than the LSV system.
QQQ five-minute bars Nov. 11 Nov. 22, 2002
Performance summary: All trades
Total net profit
Gross profit
Total # of trades
Number winning trades
Largest winning trade
Average winning trade
Ratio avg. win/avg. loss
Max. consec. winners
Avg. # bars in winners

$3,230.00
$4,160.00
24
14
$970.00
$297.14
3.20
7
39

Max. intraday drawdown ($420.00)


Profit factor
4.47

Open position P/L


Gross loss
Percent profitable
Number losing trades

$0.00
($930.00)
58.33%
10

Largest losing trade


($190.00)
Average losing trade
($93.00)
Avg. trade (win & loss) $134.58
Max. consec. losers
Avg. # bars in losers
Max. # contracts held

3
17
1

Performance summary: Long trades


Total net profit
Gross profit
Total # of trades
Number winning trades
Largest winning trade
Average winning trade
Ratio avg. win/avg. loss
Max. consec. winners
Avg. # bars in winners
Max. intraday drawdown
Profit factor

$2,860.00
$3,400.00
15
9
$970.00
$377.78
4.20
5
51
($380.00)
6.30

Open position P/L


Gross loss
Percent profitable
Number losing trades

$0.00
($540.00)
60.00%
6

Largest losing trade


($190.00)
Average losing trade
($90.00)
Avg. trade (win & loss) $190.64
Max. consec. losers
Avg. # bars in losers
Max. # contracts held

3
24
1

Performance summary: Short trades


Total net profit
Gross profit
Total # of trades
Number winning trades
Largest winning trade
Average winning trade
Ratio avg. win/avg. loss
Max. consec. winners
Avg. # bars in winners

($370.00)
$760.00
9
5
$240.00
$152.00
1.56
2
18

Max. intraday drawdown ($230.00)


Profit factor
1.95

Open position P/L


Gross loss
Percent profitable
Number losing trades

$0.00
($390.00)
55.56%
4

Largest losing trade


($140.00)
Average losing trade
($97.50)
Avg. trade (win & loss) ($41.11)
Max. consec. losers
Avg. # bars in losers

1
6

Max. # contracts held

Source: TradeStation Platform by TradeStation Group

ACTIVE TRADER July 2003 www.activetradermag.com

45

You might also like