All for whom want to be Richer.
沒有經過學習就直接去交易,就像是沒經過外科訓練就直接去開刀。
如果不知道怎麼交易獲利,應該先學習和思考成功交易者的作法。
站內的程式碼僅供Tradestation與Multicharts學習使用,不代表獲利保證,直接用於交易者請自己承擔盈虧責任。
(程式碼) THE DYNAMIC BREAK OUT II STRATEGY
George Pruitt for Futures Magazine designed the original Dynamic Break Out
system in 1996. This version has done well since it was released for public consumption
in 1996. This version will be included in Appendix B. The newer
version of the Dynamic Break Out is just like the original, except we have
incorporated an additional adaptive filter.
The key to the Dynamic Break Out II system is its ability to adapt its
parameters to current market conditions. This system is based on the triedand-
tested Donchian channel system. Remember how the Donchian system
works; buy when the high of the day penetrates the highest high price of x bars
back, and sell when the low of the day penetrates the lowest low of x bars back.
If you optimize the number of bars to determine your best entry and exit levels,
you will discover that different markets work better with different parameters.
You will also discover that a particular market goes through different
cycles and works better with different parameters through time. For example,
the Japanese Yen may have performed better with a look back of 40 days in the
1980s, but now works better with a look back of 20 days. That is the major
problem with using a static parameter for all markets. The Dynamic Break Out
II system allows the number of look back days to change with the current market.
Instead of using a static parameter, this system changes the parameters
based on an aspect of the current market.
Before you can use an adaptive parameter, you must come up with a function
or adaptive engine that automatically changes the value of the once static
parameter. The input of this adaptive engine should be some form of market
statistic. In the case of the Dynamic Break Out II, we used market volatility.
When market volatility expands, so does the number of look back days in
our break out calculation. Increased market volatility usually equates to market
indecisiveness. By increasing the number of look back days when market
volatility increases, we make it more difficult for the system to initiate a trade.
When market volatility decreases, we reduce the number of look back days.
Low market volatility equates to a trending market. By decreasing the number
of look back days, we encourage the system to initiate a trade. This helps the
Dynamic Break Out II to lock into long-term profits and be on the look out
for a change in the long-term trend. We used market volatility to fuel our
adaptive engine, but you could use any market characteristic. We can visualize
an engine that uses a market’s overbought/oversold state. If we had a long
position in a market, and it became overbought, we could use an overbought/
oversold indicator to adapt the parameter that determines the sell point.
Once an adaptive engine is dreamed up and it is pumping out values, you
must maintain the values in an acceptable range. The Dynamic Break Out II
system will not let the look back days go above 60 or below 20. Through optimization,
we discovered that look back lengths that fell beyond these bound-
aries did not generate acceptable expectations. An adaptive engine that generates
useless values is useless in itself.
The Dynamic Break Out II initially looks back 20 days to determine its
buy and sell levels. So when you start trading this system, your first buy point
is the highest high of the past 20 days and your sell point is the lowest low of
the past 20 days. At the end of each day, you measure the current market
volatility by calculating the standard deviation of the past 30 day’s closing
prices. Market volatility can be measured using different calculations: average
range, average true range, standard deviation of change in closing prices, and
others. Once we determine today’s market volatility, we compare it with yesterday’s.
If the volatility increases, then the number of look back days also
increases. We change the number of look back days to the exact amount of the
change in market volatility; if volatility increases by ten percent, then so does
the number of look back days and vice versa.
The original Dynamic Break Out made its buying and selling decisions
solely based on the highest high and lowest low values that were generated by
our volatility-based adaptive engine. Once a position was initiated, a simple,
yet effective, $1500 money management stop was put into place. The newer
version uses the same entry technique in concert with an adaptive Bollinger
Band. The length of the Bollinger Band calculation is the same number of look
back days that is generated by the adaptive engine. The close of yesterday must
be above the upper band and today’s high must be greater than or equal to the
highest high of x bars back before a long position can be initiated (x bars back
is equal to our adaptive look back days value). Yesterday’s close must be below
the lower band and today’s low must be less than or equal to the lowest low of
x bars back before a short position can be taken. Instead of the simple money
management stop, we incorporated a dynamic trailing stop. As we have discussed,
the number of look back days changes on a daily basis. The adaptive
engine decides the amount of change. The liquidation point of an existing
trade is determined by calculating a simple moving average of closing prices for
the past look back days. The sell liquidation would be just the opposite of the
buy liquidation.
Dynamic Break Out II Pseudocode
If BarNumber = 1 then lookBackDays = 20
Else do the following
Today's market volatility = StdDev(Close,30)
Yesterday's market volatility = StdDev(Close[1],30)
deltaVolatility = (today's volatility - yesterday's
volatility)/today's volatility
lookBackDays = (1 + deltaVolatility) * lookBackDays
lookBackDays = MinList(lookBackDays,60)
lookBackDays = MaxList(lookBackDays,20)
upBand = Average(Close,lookBackDays) + StdDev(Close,lookBackDays) *2.00
dnBand = Average(Close,lookBackDays) - StdDev(Close,lookBackDays) *2.00
buyPoint = Highest(High,lookBackDays)
sellPoint = Lowest(Low,lookBackDays)
longLiqPoint = Average(Close,lookBackDays)
shortLiqPoint = Average(Close,lookBackDays)
If Close of yesterday > upBand) then initiate a long position if today's
market action >= buyPoint
If (Close of yesterday < dnBand) then initiate a short position if today's
market action <= sellPoint
Liquidate long position if today's market action <= longLiqPoint
Liquidate short position if today's market action >= shortLiqPoint
Dynamic Break Out II Program
{Dynamic Break Out II by George Pruitt
This system is an extension of the original Dynamic Break Out system written
by George for Futures Magazine in 1996. In addition to the channel break out
methodology, DBS II incorporates Bollinger Bands to determine trade entry.}
Inputs: ceilingAmt(60),floorAmt(20),bolBandTrig(2.00);
Vars: lookBackDays(20),todayVolatility(0),yesterDayVolatility(0),
deltaVolatility(0);
Vars: buyPoint(0),sellPoint(0),longLiqPoint(0),shortLiqPoint(0),upBand(0),
dnBand(0);
todayVolatility = StandardDev(Close,30,1);
yesterDayVolatility = StandardDev(Close[1],30,1); {See how I offset the
function call to get yesterday's value}
deltaVolatility = (todayVolatility - yesterDayVolatility)/todayVolatility;
lookBackDays = lookBackDays * (1 + deltaVolatility);
lookBackDays = Round(lookBackDays,0);
lookBackDays = MinList(lookBackDays,ceilingAmt); {Keep adaptive engine within
bounds}
lookBackDays = MaxList(lookBackDays,floorAmt);
upBand = BollingerBand(Close,lookBackDays,+bolBandTrig);
dnBand = BollingerBand(Close,lookBackDays,-bolBandTrig);
buyPoint = Highest(High,lookBackDays);
sellPoint = Lowest(Low,lookBackDays);
longLiqPoint = Average(Close,lookBackDays);
shortLiqPoint = Average(Close,lookBackDays);
if(Close > upBand) then Buy("DBS-2 Buy") tomorrow at buyPoint stop;
if(Close < dnBand) then SellShort("DBS-2 Sell") tomorrow at sellPoint stop;
if(MarketPosition = 1) then Sell("LongLiq") tomorrow at longLiqPoint stop;
if(MarketPosition = -1) then BuyToCover("ShortLiq") tomorrow at shortLiqPoint
stop;
The Dynamic Break Out II program demonstrates how to:
• Measure market volatility by using the standard deviation of closing
prices.
• Create a dynamic parameter using an adaptive engine
Dynamic Break Out II Summary
Yet again, another successful long-term trading approach. We guess we let the
cat out of the bag . . .and what an ugly cat it is. The majority of successful trading
systems are of the long-term trend following variety. Almost all traders
realize this fact, but it doesn’t stop them from searching out a shorter-term
approach. See, the trend-following systems require diversification, which
requires hefty capitalization. Also, trend-following systems can have substantial
draw downs and go for years without making any money. The typical trader
cannot persevere through these bad attributes, even though they know they
will probably be rewarded in the long run.
Even this dynamic approach couldn’t capture a profit in the soybean market.
The continual failure of trend-following systems in the grain markets begs
the question, “Why don’t these systems work in the soybean or grain markets?”
These markets move in a cyclical fashion due to the seasonality aspect of
their underlying fundamentals. If we know ahead of time that these markets
have this cyclical nature, then why can’t we capture their movements? Cycles
are very difficult to calculate and determine and, therefore, are usually overlooked.
The two most predominant methods for finding cycles are trigonometric
curve fitting and Fourier (spectral) analysis. The mathematics behind
these two methods is relatively complex and detailed. We personally have
never seen a pure mathematically-based, cycle-finding trading system outperform
the typical trend follower. If you do have any interest in this area, we refer
you to John Ehlers, Rocket Science for Traders (John Wiley, 2001).
Before we move on, let’s use our TradeStation for two different experiments.
The first experiment will deal with the Dynamic Break Out II system
and the soybean market. We saw how virtually useless the system was for capturing
the trends in the soybean market. What would happen if we faded the
trade signals? What we mean by fade is to do just the opposite. So, instead of
buying at our long entry point, we will sell and vice versa. If the soybean market
moves in cycles, which is countertrend, then we should be able to improve
our performance by entering against the prevalent trend. Table 6.5 shows
the performance of our countertrend soybean system.
No question that it did better, but overall it is still nothing to write home
about. This somewhat proves that soybeans and other grain markets cannot be
successfully traded by a longer-term trend-following approach. Since we are on
the subject of cycles and seasonality, why don’t we program a strategy that
incorporates a seasonality filter? We will demonstrate how to use the keyword
date to determine the current month and day. This system will trade the soybeans
and will only take long signals from March 1 to July 1 and will only take
short signals from July 2 to February 28. These dates were derived from cyclical
analysis of historical data on soybeans.
Inputs: goLongStart(301),goLongEnd(701),goShortStart(702),goShortEnd(228);
Vars: monthAndDay(0);
{The inputs represent the months and days that we can enter long and short
trades}
{301 is March 01 >> can only go long from this date and up to
701 is July 01 >> this date
702 is July 02 >> can only go short from this date and up to
228 is February 28 >> this date}
{Let's use the date and extract the information that we need from it to
determine the month and the day}
{If we divide the date by 10000, the remainder is the month and day. We can
use the modulus function}
monthAndDay = Mod(Date of tomorrow,10000);
if(monthAndDay >= goLongStart and monthAndDay <= goLongEnd) then
begin
buy("Seasonal Buy") tomorrow at Open;
end;
if(monthAndDay >= goShortStart or monthAndDay <= goShortEnd) then
{Notice that we had to use "or" instead of "and"—this is due
to the goShortEnd date is less than the goShortStart date}
begin
sellShort("Seasonal Sell") tomorrow at Open;
end;