Post a new post
Open the left side

程序化交易策略:会换档的交易系统_恒温器Thermostat交易系统

[Copy Link]
451 0

Register now, make more friends, enjoy more functions, and let you play in the community easily.

You need Sign in Can be downloaded or viewed without an account?Register Now Quick login with mobile dynamic code

x
会换档的交易系统_恒温器Thermostat交易系统   


http://www.programtrading.tw/viewtopic.php?f=24&t=464&start=0&st=0&sk=t&sd=a&sid=8f2811a6613e417e3ddc9f64e037b39d

因为市场不会永远存在趋势,所以才会有人想说希望有一种交易系统可以适用在趋势市场和摆荡市场。而Thermostat Trading Strategy(恒温器交易系统)的设计原理,就是在趋势市场中采用顺势系统,在摆荡市场中采用摆荡系统。有点像是换档的感觉,而决定换档时机的指标,就是之前报告过的 ChoppyMarketIndex,这个指标是会介于0-100之间,指数越大,代表现在的市场越有趋势。整个系统的架构,可以简化的写成下面这样:










If ChoppyMarketIndex < 20 then begin


摆荡系统内容;


end;






If ChoppyMarketIndex >= 20 then begin


顺势系统内容;


End;










架构就是这么简单而已,剩下的只是把摆荡系统和顺势系统的内容放进去这个架构里面而已。顺势系统的内容主要是延续使用 Bollinger Bandit系统的内容,而摆荡系统则是加上的简单的型态识别(pattern recognition)的开盘区间突破系统而已。下面分别就这两种系统作报告:










摆荡系统:


在摆荡市场中,通常会存在一种现象,就是如果今天价格上涨的话,那么明天的价格就比较倾向于会下跌。而今天价格如果下跌的话,那么明天的价格就比较倾向于上涨,而这也正是摆荡市场的特性。所以我们定义如果今天的收盘价如果高于昨天的 (The highest price+Lowest price+Closing price) / 3的话,那么明天就会一个 sell easier day,代表明天价格应该会比较倾向下跌。相反的,我们也定义如果今天的收盘价低于昨天的 (The highest price+Lowest price+Closing price) / 3的话,那么明天就会是一个buy easier day,代表明天价格应该会比较倾向上涨。










staybuy easier day的时候,只有代表着价格比较具有上涨的可能性而已,并不是指价格一定会上涨。所以我们必须设定做多和做空这两边的entry,只是这两边entry的门坎不一样而已,做多的门坎比较低,比较容易。反而做空的门坎比较高,比较难。所以在buy easier day的时候,我们会设定进场的规则是这样的:






Initiate a long position at the open price + 50% of the ten-day average true range.


Initiate a short position at the open price - 75% of the ten-day average true range.










而如果是sell easier day的话,那我们则会把进场的规则设为这样:






Initiate a short position at the open price - 50% of the ten-day average true range.


Initiate a long position at the open price + 75% of the ten-day average true range.










而在摆荡市场中,有时候市场会有假的,失败的波动,这种假的波动常常会让我们被巴来巴去,所以这里我们加入了一个简单的滤网来避免这种情形。如果我们的buy stop 低于三天的最低价的平均,则就把buy stop提高到三天的最低价的平均。而如果我们的sell stop高于三天最高价的平均,则把sell stop下降到三天最高价的平均。

顺势系统:

If whenChoppyMarketIndex的指标高于20的时候,代表现在市场进入趋势了,所以我们也跟着改用顺势系统。这里我们所采用的顺势系统就是之前报告过的Bollinger Bandit系统。当价格突破上信道的时候建立多头部位,当价格跌破下信道的时候则建立空头部位。而当有部位在手上的时候,而价格回到50天移动平均线的时候,我们就平仓出场。





而当这个系统在摆荡和趋势这两种模式当中转换的时候,有时候会有部位在手上。当从趋势市场转换成摆荡市场的时候,如果有在趋势市场当中建立的部位,则我们就让摆荡系统的进场讯号发生的时候才来结束这个部位。但是当市场从摆荡市场变成趋势市场的时候,如果我们有在摆荡市场里面建立的部位的话,那么我们就用三倍ATR的保护性停损来保护我们的部位。因为如果要用50天移动平均线才让我们出场的话,那可能会让我们保留这个错误的部位太久而造成太多的损失。





下面就是这个系统的程序代码:







{Thermostat by George Pruitt

Two systems in one. If the ChoppyMarketIndex is less than 20 then we are in a

swing mode. If it is greater than or equal to 20 then we are in a trend mode.

Swing system is an open range breakout incorporating a buy easier/sell easier

concept. The trend following system is based on bollinger bands and is

similar to the Bollinger Bandit program.}



Inputs: bollingerLengths(50),trendLiqLength(50),numStdDevs(2),swingPrcnt1(0.50),swingPrcnt2(0.75),atrLength(10),swingTrendSwitch(20);



Vars:cmiVal(0),buyEasierDay(0),sellEasierDay(0),trendLokBuy(0),trendLokSell(0),keyOfDay(0),swingBuyPt(0),swingSellPt(0),trendBuyPt(0),trendSellPt(0),swingProtStop(0);



cmiVal = ChoppyMarketIndex(30);

buyEasierDay = 0;

sellEasierDay = 0;



trendLokBuy = Average(Low,3);

trendLokSell= Average(High,3);



keyOfDay = (High + Low + Close)/3;



if(Close > keyOfDay) then sellEasierDay = 1;

if(Close <= keyOfDay) then buyEasierDay = 1;



if(buyEasierDay = 1) then

begin

swingBuyPt = Open of tomorrow + swingPrcnt1*AvgTrueRange(atrLength);

swingSellPt = Open of tomorrow - swingPrcnt2*AvgTrueRange(atrLength);

end;



if(sellEasierDay = 1) then

begin

swingBuyPt = Open of tomorrow + swingPrcnt2*AvgTrueRange(atrLength);

swingSellPt = Open of tomorrow - swingPrcnt1*AvgTrueRange(atrLength);

end;



swingBuyPt = MaxList(swingBuyPt,trendLokBuy);

swingSellPt = MinList(swingSellPt,trendLokSell);



trendBuyPt = BollingerBand(Close,bollingerLengths,numStdDevs);

trendSellPt = BollingerBand(Close,bollingerLengths,- numStdDevs);



if(cmiVal < swingTrendSwitch)then

begin

if (MarketPosition <> 1) then Buy("SwingBuy") next bar at swingBuyPt stop;

if(MarketPosition <> -1) then SellShort("SwingSell") next bar at swingSellPt stop;

end

else

begin

swingProtStop = 3*AvgTrueRange(atrLength);

Buy("TrendBuy") next bar at trendBuyPt stop;

SellShort("TrendSell") next bar at trendSellPt stop;

Sell from Entry("TrendBuy") next bar at Average(Close,trendLiqLength) stop;

BuyToCover from Entry("TrendSell") next bar at Average(Close,trendLiqLength) stop;

Sell from Entry("SwingBuy") next bar at EntryPrice – swingProtStop stop;

BuyToCover from Entry("SwingSell") next bar at EntryPrice + swingProtStop stop;

end;



而下面则是这个系统在1982-2002this20年的绩效表现,看来比之前报告的King KelthnerandBollinger Bandit系统绩效来的好。



thermostat.JPG (87.89 KiB) 被浏览 586 second




有兴趣的朋友可以拿来测试一下看看,不过我自己测试了最近几年的foreign exchange,指数,金属,能源,农产品等等。发现绩效还好而已,所以想要直接拿来套用的人可能会失望了。不过这样的系统开发的逻辑,倒是可以值得我们学习的。谢谢。


判断趋势盘or摆荡盘的指标
http://www.programtrading.tw/viewtopic.php?f=24&t=404
今天报告另一个简单的指标,则是George & John在书中所提出的一个指标,叫做 ChoppyMarketIndex。这个指标也是用来判断目前盘势的方法之一。计算方式如下:



ChoppyMarketIndex = (Abs(Close-Close[29]) / (Highest(High,30)-Lowest(Low,30)) * 100)



分母是最近30天最高价 – lately30天的最低价。分子则是今天的收盘价-29天前的收盘价,然后再取绝对值。ChoppyMarketIndex的数值也是会介于0-100之间,数值越大,代表市场趋势越明显。数值越小,则代表目前市场可能陷入摆荡状况。





ChoppyMarketIndexthisFunction的程序代码如下:



{Choppy Market Index Function

This function returns a value from 0 to 100.

A lower value denotes higher market indecisiveness (choppiness),

whereas a higher value denotes a trending market.

The only input is the number of bars that we look back.}



Inputs: periodLength(Numeric);



Vars: num(0),denom(1);



if(periodLength<>0) then

begin

denom = Highest(High,periodLength) - Lowest(Low,periodLength);

num = Close[periodLength-1]- Close;

num = AbsValue(num);

ChoppyMarketIndex = 0.0;

if(denom<>0) then ChoppyMarketIndex = num/denom*100;

end;





所以不管用的是ADX,或是ChoppyMarketIndex,我们只要有了这种可以判断目前盘势的指标之后,就可以用来接着开发后续要报告的会换文件的交易系统了。谢谢。


http://karime.blog.hexun.com/3232156_d.html
[thermostat]
if the cmi function returns a value of less than 20,then use
the short-term swing approach.
atr10=averagetruerange(10)
keyofday=(high+low+close)/3
buyeasierday=0
selleasierday=0
if(close>keyofday) then selleasierday=1
if(close<=keyofday) then buyeasierday=1
avg3hi=average(high,3)
avg3lo=average(low,3)
if(buyeasierday=1) then
       longentrypoint=open+atr10*0.5
       shortentrypoint=open-atr10*0.75
if(selleasierday=1) then
       longentrypoint=open+atr10*0.75
       shortentrypoint=open-atr10*0.5
longentrypoint=maxlist(longentrypoint,avg3lo)
shortentrypoint=minlist(shortentrypoint,avg3hi)
initiate a long position of today's market action>=longentrypoint
initiate a short position of today's market action<=shortentrypoint


..................................
  字号:大 in Small
if the cmi function returns a value greater than or equal to 20,
then use the long-term trend following approach.
     if have a short position that was initiated by the short-term swing approach then
     shortliqpoint=entryprice+3*atr10
     liquidate short position if today's market action>=shortliqpoint
if have a long position that was initiated by the short-term swing
approach then
     longliqpoint=entryprice-3*atr10
     liquidate long position if today's market action<=longliqpoint
upband=average(close,50)+stddev(close,50)*2.00
dnband=average(close,50)-stddev(close,50)*2.00
avg50=average(close,50)
initiate a long position if today's market action>=upband
initiate a short position if today's market action<=dnband
liquidate long position if today's market action<=avg50
liquidate short position if today's market action>=avg50
[ts code]
inputs:bollingerlengths(50),trendliqlength(50),numstddevs(2),
swingprcnt1(0.50),swingprcnt2(0.75),atrlength(10),
swingtrendswitch(20);
vars:cmival(0),buyeasierday(0),selleasierday(0),trendlokbuy(0),
trendloksell(0),keyofday(0),swingbuypt(0),swingsellpt(0),
trendbuypt(0),trendsellpt(0),swingprotstop(0);
cmival=choppymarketindex(30);
buyeasierday=0;
selleasierday=0;
trendlokbuy=average(low,3);
trendloksell=average(high,3);
keyofday=(high+low+close)/3;
if(close>keyofday) then selleasierday=1;
if(close<=keyofday) then buyeasierday=1;
if(buyeasierday=1) then
begin
   swingbuypt=open of tomorrow + swingprcnt1*avgtruerange(atrlength);
   swingsellpt=open of tomorrow - swingprcnt2*avgtruerange(atrlength);
end;
if(selleasierday=1) then
begin
   swingbuypt=open of tomorrow + swingprcnt2*avgtruerange(atrlength);
   swingsellpt=open of tomorrow - swingprcnt1*avgtruerange(atrlength);
end;
swingbuypt=maxlist(swingbuypt,trendlokbuy);
swingsellpt=minlist(swingsellpt,trendloksell);
trendbuypt=bollingerband(close,bollingerlengths,numstddevs);
trendsellpt=bollingerband(close,bollingerlengths,-numstddevs);
if(cmival
begin
    if(marketposition<>1) then buy("swingbuy") next bar at swingbuypt
       stop;
    if(marketposition<>-1) then sellshort("swingsell") next bar at
       swingsellpt stop;
end
else
begin
   swingprotstop=3*avgtruerange(atrlength);
   buy("trendbuy") next bar at trendbuypt stop;
   sellshort("trendsell") next bar at trendsellpt stop;
   sell from entry("trendbuy") next bar at average(close,trendliqlenth)
      stop;
   buytocover from entry("trendsell") next bar at
      average(close,trendliqlength) stop;
   sell from entry("swingbuy") next bar at entryprice - swingprotstop
      stop;
   buytocover from entry("swingsell") next bar at entryprice +
      swingprotstop stop;
end;
"Small gifts, come to Huiyi to support me"
No one has offered a reward yet. Give me some support
comiis_nologin
You need to log in before you can reply Sign in | Register Now Quick login with mobile dynamic code

Point rules of this version

more

Customer Service Center

238-168-2638 QQcustomer service Monday to Friday 20:00-24:00
Quick reply Back to top Back to list