時限退出付きドンチアン・トレンド
タートルズ流 投資の魔術 からの引用
ドンチアン・トレンド・システムの変形、時限退出付きドンチアン・トレンド・システムは、ブレイクアウトの退出のかわりに時間にもとづいた退出を用いる。80日経てば退出し、どんなストップも使わない。
仕掛けは問題ではなく、手じまいだけが問題だというトレーダーは多い。このシステムがその発言への私の答えだ。このシステムのパフォーマンスを他のシステムのそれと比べると、この非常に単純なシステムがもっと複雑な退出にまったく引けをとらないことがわかるだろう。
ストラテジーを作成
エントリーとイグジット
https://gyazo.com/834e63aa0a4f415870bdde9bce2d9ee4
https://gyazo.com/04a689a199ab3c8c94619d897a832946
バックテスト
期間
2005年1月1日 ~ 2017年12月31日
12年間
銘柄
為替(5):
USDJPY、EURJPY、GBPJPY、CHFJPY、CADJPY
株価指数(5):
NKY 日経225、DJI NYダウ、DAX ドイツ、UKX イギリス、HSI 香港ハンセン
日本株(5):
6098リクルート、4452花王、5711三菱マテリアル、7201日産、9984ソフトバンクグループ
米株(5):
AAPLアップル、AXPアメリカン・エクスプレス、BAボーイング、JNJジョンソン・エンド・ジョンソン、MCDマクドナルド
海外商品(5):
金、白金、原油、コーン、大豆
その他
資金管理:単利
各主要な市場から5銘柄ずつピックアップしてテスト。
テスト1
table:テスト1設定
DC_en EMA_m EMA_l Time_ex Pyramiding
20 25 350 80-days None
本に掲載されていたものとまったく同じテスト(と思われる)
table:テスト1結果
損益 最大DD 取引数 勝数 勝率 RR比 勝ち保有 負け保有
USDJPY 21.26 20.88 36 16 44.44 1.626 80 80
EURJPY 24.12 30.54 34 21 61.76 0.753 80 80
GBPJPY 129.96 27.13 36 21 58.33 1.6 80 80
CHFJPY -22.87 46.33 36 17 47.22 0.848 80 80
CADJPY 17.21 27.39 36 16 44.44 1.536 80 80
NKY 6165.02 7838.22 34 16 47.06 1.454 80 80
DJI 9609.52 3697.51 35 22 62.86 1.231 80 80
DAX 4783.09 3590.56 37 22 39.46 1.062 80 80
UKX -548.50 3116.40 37 20 54.05 0.772 80 80
HSI 10765.38 14060.68 34 18 52.94 1.263 80 80
6098 836.00 305.00 6 4 66.67 1.374 80 80
4452 2827.00 1398.00 33 16 48.48 1.875 80 80
5711 -4950.00 9030.00 35 15 42.86 0.870 80 80
7201 -752.30 800.30 34 14 41.18 0.973 80 80
9984 3019.00 4067.00 33 18 54.55 1.129 80 80
AAPL 117.60 40.69 35 26 74.29 0.843 80 80
AXP 53.47 23.53 35 23 65.71 0.843 80 80
BA 234.97 51.03 35 21 60.00 2.031 80 80
JNJ -8.26 40.38 35 16 45.71 1.077 80 80
MCD 74.99 20.63 34 18 52.94 1.850 80 80
GOLD 110520.00 44680.00 35 22 62.86 1.353 80 80
PLATINUM 20195.00 43480.00 35 19 54.29 0.993 80 80
WTI 45830.00 84110.00 35 17 48.57 1.316 80 80
CORN -16000.00 34762.50 37 15 40.54 1.152 80 80
SOY BEANS -1925.00 44087.50 36 14 38.89 1.539 80 80
TOTAL 848 447 52.71 1.240
破産の確率 0%
期待値/リスク 0.179
収益の見込み 152.12
※ 破産の確率は損失の許容=2%で算出
テスト1考察
期待値の計算式
$ WIN \times RR- | 1-WIN|
利益見込みの計算式
期待値 ✕ 取引回数
テスト2
table:テスト2設定
DC_en EMA_m EMA_l Time_ex Pyramiding
20 25 350 80-days 1-ATR 上限4
本に掲載されていたものとまったく同じテスト(と思われる)
table:テスト2結果
損益 最大DD 取引数 勝数 勝率 RR比 勝ち保有 負け保有
USDJPY 95.98 50.76 112 62 55.36 1.232 65 70
EURJPY 118.32 76.46 114 70 61.40 0.915 67 66
GBPJPY 282.86 111.63 131 69 52.67 1.483 71 66
CHFJPY -48.39 117.94 109 49 44.95 0.984 71 66
CADJPY 10.67 112.01 115 49 42.61 1.396 67 66
NKY 23513.77 25263.58 113 54 47.79 1.472 69 69
DJI 31549.42 8931.50 122 78 63.93 1.283 63 65
DAX 14123.69 12607.59 122 76 62.30 0.92 73 68
UKX -6497.00 13339.20 122 60 49.18 0.724 61 69
HSI 20123.80 52012.49 119 65 54.62 1.013 71 71
6098 3315.00 589.00 20 16 80.00 1.177 72 78
4452 10863.00 2858.00 99 47 47.47 2.331 72 71
5711 -8955.00 23595.00 110 44 40.00 1.145 69 72
7201 -2451.20 2751.20 103 44 42.72 0.892 71 66
9984 13977.00 7393.00 102 53 51.96 1.499 69 69
AAPL 388.41 144.16 126 97 76.98 0.764 69 74
AXP 147.87 70.70 121 71 58.68 1.092 65 63
BA 789.72 154.67 117 67 57.26 2.235 72 64
JNJ -97.67 116.23 110 51 46.36 0.791 64 67
MCD 227.39 68.37 115 61 53.04 1.739 69 67
GOLD 350160.00 120140.00 119 74 62.18 1.446 66 66
PLATINUM 84025.00 159235.00 110 66 60.00 0.843 67 71
WTI 327490.00 160640.00 102 61 59.80 1.223 71 65
CORN 21737.50 47737.50 105 46 43.81 1.457 71 70
SOY BEANS -44925.00 181237.50 111 48 43.24 1.135 67 66
TOTAL 2749 1478 53.77 1.230
破産の確率 0%
期待値/リスク 0.200
収益の見込み 551.16
※ 破産の確率は損失の許容=2%で算出
テスト2考察
テスト3
table:テスト3設定
DC_en EMA_m EMA_l Time_ex Pyramiding
20 25 350 40-days None
本に掲載されていたものとまったく同じテスト(と思われる)
table:テスト3結果
損益 最大DD 取引数 勝数 勝率 RR比 勝ち保有 負け保有
USDJPY 5.03 36.10 64 31 48.44 1.123 40 40
EURJPY 40.68 22.80 62 36 58.06 0.997 40 40
GBPJPY 129.76 28.38 63 36 57.14 1.594 40 40
CHFJPY 6.02 24.96 60 31 51.67 1.001 40 40
CADJPY 11.60 33.75 62 27 43.55 1.455 40 40
NKY 9587.64 5678.06 60 31 51.67 1.354 40 40
DJI 9373.77 5007.23 61 40 65.57 0.892 40 40
DAX -1254.04 6912.10 64 32 50.00 0.92 40 40
UKX -2736.40 4384.80 62 33 53.32 0.609 40 40
HSI 22728.49 10890.90 55 36 65.45 1.088 40 40
6098 799.00 192.00 10 6 60.00 2.442 40 40
4452 1042.00 2346.00 58 26 44.83 1.362 40 40
5711 -760.00 5220.00 58 28 48.28 1.015 40 40
7201 -592.70 1043.70 56 23 41.07 1.086 40 40
9984 2951.00 3194.00 57 28 49.12 1.289 40 40
AAPL 106.22 31.66 59 37 62.71 1.15 40 40
AXP 72.98 15.28 61 34 55.74 1.544 40 40
BA 207.33 35.15 57 36 63.16 1.593 40 40
JNJ -30.85 49.81 60 27 45.00 1.008 40 40
MCD 67.80 28.03 62 35 56.45 1.330 40 40
GOLD 114800.00 24800.00 58 40 68.97 0.993 40 40
PLATINUM 14865.00 46995.00 63 30 47.62 1.218 40 40
WTI -101990.00 196600.00 63 33 52.38 0.625 40 40
CORN -4550.00 67487.50 62 25 40.32 1.343 40 40
SOY BEANS -38187.50 72312.50 62 29 46.77 0.845 40 40
TOTAL 1459 770 52.78 1.15
破産の確率 0%
期待値/リスク 0.135
収益の見込み 196.44
※ 破産の確率は損失の許容=2%で算出
テスト1考察
テスト4
table:テスト4設定
DC_en EMA_m EMA_l Time_ex Pyramiding
20 25 350 120-days None
本に掲載されていたものとまったく同じテスト(と思われる)
table:テスト4結果
損益 最大DD 取引数 勝数 勝率 RR比 勝ち保有 負け保有
USDJPY 8.72 21.82 27 17 62.96 0.668 120 120
EURJPY -59.07 84.59 25 11 44.00 0.716 120 120
GBPJPY 118.73 31.44 26 16 61.54 1.329 120 120
CHFJPY 6.07 36.61 25 11 44.00 1.396 120 120
CADJPY 23.66 21.85 26 13 50.00 1.390 120 120
NKY 3220.28 10689.41 24 13 54.17 0.98 120 120
DJI 5607.98 7838.83 25 17 68.00 0.718 120 120
DAX 5738.46 2402.35 26 16 61.54 1.116 120 120
UKX 2078.50 1581.50 26 17 65.38 0.835 120 120
HSI 19820.57 8754.55 24 16 66.67 1.040 120 120
6098 822.00 237.00 4 3 75.00 1.489 120 120
4452 4987.00 1081.00 24 14 58.33 2.09 120 120
5711 -1320.00 5250.00 24 9 37.50 1.491 120 120
7201 -503.70 1106.70 25 10 40.00 1.109 120 120
9984 4452.00 3872.00 23 12 52.17 1.402 120 120
AAPL 156.79 37.11 24 18 75.00 1.407 120 120
AXP 44.08 23.72 26 16 61.54 0.978 120 120
BA 201.20 66.30 24 14 58.33 1.814 120 120
JNJ 12.08 21.91 24 12 50.00 1.168 120 120
MCD 66.95 21.55 26 15 57.69 1.393 120 120
GOLD 131890.00 17390.00 25 19 76.00 1.182 120 120
PLATINUM -10915.00 68845.00 25 12 48.00 0.994 120 120
WTI -79170.00 149160.00 26 11 42.31 0.898 120 120
CORN -23675.00 30637.50 25 17 32.00 1.295 120 120
SOY BEANS -52337.50 70562.50 25 11 44.00 0.678 120 120
TOTAL 604 340 56.29 1.170
破産の確率 0%
期待値/リスク 0.221
収益の見込み 133.64
※ 破産の確率は損失の許容=2%で算出
テスト4考察
Pineスクリプト
code:Pineスクリプト(js)
//@version=3
strategy("Strategy Turtle Time Exit Donchian Trend"
,default_qty_type=strategy.fixed
,default_qty_value=1
,pyramiding=4
,overlay=true)
src = close
len_dc_entry = input(20 ,minval=1 ,title="length of dc entry")
len_ema_m = input(25 ,minval=1 ,title="length of middle ema")
len_ema_l = input(350 ,minval=1 ,title="length of long ema")
MAX_N = input(1 ,type=integer ,minval=1 ,maxval=4 ,title="maximun num of unit")
LO_len = input(20 ,type=integer ,minval=1 ,title="pyramiding ATR length")
LO_N = input(1 ,type=float ,minval=0.5 ,title="pyramiding ATR*N")
Tm_len = input(80 ,type=integer ,minval=1 ,title="timed exit length")
fromYear = input(2005 ,type=integer ,minval=1900 ,title="test start")
endYear = input(2017 ,type=integer ,minval=1900 ,title="test end")
isWork = timestamp(fromYear ,1 ,1 ,00 ,00) <= time and time < timestamp(endYear+1 ,1 ,1 ,00 ,00)
upper_en = highest(high ,len_dc_entry)1 lower_en = lowest(low ,len_dc_entry)1 ema_m = ema(src ,len_ema_m)
ema_l = ema(src ,len_ema_l)
atr_LO_ = ema(tr ,LO_len)
atr_LO = atr_LO_*LO_N
countTradingDays = na
countNonTradingDays = na
countTradingDays := strategy.position_size==0 ? 0 : countTradingDays1 + 1 countNonTradingDays := strategy.position_size!=0 ? 0 : countNonTradingDays1 + 1 entry1 = close
entry2 = close
entry3 = close
entry4 = close
entry1 := strategy.position_size==0 ? na : entry11 entry2 := strategy.position_size==0 ? na : entry21 entry3 := strategy.position_size==0 ? na : entry31 entry4 := strategy.position_size==0 ? na : entry41 lo2 = close
lo3 = close
lo4 = close
lo2 := strategy.position_size==0 ? na : lo21 lo3 := strategy.position_size==0 ? na : lo31 lo4 := strategy.position_size==0 ? na : lo41 L_EntrySig = strategy.position_size==0 and high >= upper_en and ema_m >= ema_l
S_EntrySig = strategy.position_size==0 and low <= lower_en and ema_m <= ema_l
lo_sig2 = strategy.position_size>0 ? lo2 < high : strategy.position_size<0 ? lo2 > low : na
lo_sig3 = strategy.position_size>0 ? lo3 < high : strategy.position_size<0 ? lo3 > low : na
lo_sig4 = strategy.position_size>0 ? lo4 < high : strategy.position_size<0 ? lo4 > low : na
if(strategy.position_size != 0)
TimedSig = countTradingDays >= Tm_len
strategy.close_all(when = TimedSig)
if(TimedSig)
entry1 := na
entry2 := na
entry3 := na
entry4 := na
lo2 := na
lo3 := na
lo4 := na
if(strategy.position_size > 0)
if(lo_sig2 and MAX_N >= 2)
lo2 := na
strategy.entry("L-Entry2" ,strategy.long ,comment="L-Entry2")
if(lo_sig3 and MAX_N >= 3)
lo3 := na
strategy.entry("L-Entry3" ,strategy.long ,comment="L-Entry3")
if(lo_sig4 and MAX_N >= 4)
lo4 := na
strategy.entry("L-Entry4" ,strategy.long ,comment="L-Entry4")
if(strategy.position_size < 0)
if(lo_sig2 and MAX_N >= 2)
lo2 := na
strategy.entry("S-Entry2" ,strategy.short ,comment="S-Entry2")
if(lo_sig3 and MAX_N >= 3)
lo3 := na
strategy.entry("S-Entry3" ,strategy.short ,comment="S-Entry3")
if(lo_sig4 and MAX_N >= 4)
lo4 := na
strategy.entry("S-Entry4" ,strategy.short ,comment="S-Entry4")
if((L_EntrySig or S_EntrySig) and isWork)
countTradingDays := 1
entry1 := close
if(L_EntrySig)
strategy.entry("L-Entry1" ,strategy.long ,comment="L-Entry1")
lo2 := MAX_N >= 2 ? close + atr_LO : na
lo3 := MAX_N >= 3 ? close + atr_LO * 2 : na
lo4 := MAX_N >= 4 ? close + atr_LO * 3 : na
if(S_EntrySig)
strategy.entry("S-Entry1" ,strategy.short ,comment="S-Entry1")
lo2 := MAX_N >= 2 ? close - atr_LO : na
lo3 := MAX_N >= 3 ? close - atr_LO * 2 : na
lo4 := MAX_N >= 4 ? close - atr_LO * 3 : na
plot(strategy.position_size ,transp=0 ,title="保有ポジションの数")
plot(strategy.openprofit ,transp=0 ,title="未決済の損益")
plot(strategy.netprofit ,transp=0 ,title="決済済みの損益")
plot(strategy.closedtrades ,transp=0 ,title="決済済み取引数")
plot(countTradingDays ,transp=0 ,title="取引日数")
plot(countNonTradingDays ,transp=0 ,title="ノンポジ日数")
plot(entry1 ,title="entry1" ,color=blue ,transp=0 ,style=linebr)
plot(lo2 ,title="lo2" ,color=red ,transp=0 ,style=linebr)
plot(lo3 ,title="lo3" ,color=red ,transp=0 ,style=linebr)
plot(lo4 ,title="lo4" ,color=red ,transp=0 ,style=linebr)
plot(atr_LO ,transp=0 ,title="ATR_LO")
// plot(strategy.max_drawdown ,transp=50 ,title="最大DD")
// plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)
p1 = plot(ema_m ,color=#303F9F ,title="ema_m" ,style=line ,linewidth=1, transp=0)
p2 = plot(ema_l ,color=#4CAF50 ,title="ema_l" ,style=line ,linewidth=1, transp=0)
fill(p1 ,p2 ,color=#2196F3 ,title="fill" ,transp=80)
p3 = plot(lower_en ,color=gray ,title="lower_entry" ,style=linebr ,linewidth=1 ,transp=40)
p4 = plot(upper_en ,color=gray ,title="upper_entry" ,style=linebr ,linewidth=1 ,transp=40)
fill(p3 ,p4 ,color=gray ,title="fill" ,transp=90)