電子信箱 service [at] bituzi.com
幣圖誌首頁 facebook粉絲團 google plus google plus


程式交易策略庫-停利心法第二章



最近台股一瀉千里,萎靡不振,
不知道大家最近績效如何?
看了一下獵人給大家的交易程式績效,
最近表現還不錯,如果有拿來用的人就恭喜啦!
今天獵人要再來介紹一個新的出場方式,
相信應該可以幫助大家改善一點績效。



上次討論過三種停利方式
結果發現,三種方式都不太好,
但是並不代表停利不好,
只是停利的方式選擇不好,
今天要介紹的這種出場方式,
可以說是停利,但是也不完全是停利,
他比較像大家講的,移動式出場方式,
他會隨著你進場後的高低點而改變出場點。
喔!這就神奇了,
到底要怎麼寫才可以寫出這樣的移動式出場呢?
待獵人慢慢來解釋這個想法。

當我們進場做多時,
我們期望他一路往上走,這樣才會大賺,
但是往往事與願違,常常不會這麼順利,
難道我們要一路抱到停損嗎?
還是抱到收盤,眼睜睜的看著一點點的獲利消失不見。
所以我們期望,當指數從高點往回拉時,
要找機會出場,但是問題來了,
拉回多少出場才好,20點、40點、還是60點。
其實用固定點數會有些缺點,舉例來說:
指數在6000點的時候,20點可能是比較大的一個點數,
但是指數在9000點的時候,20點可能只是小小的點數,
如果指數在不同的位置,而你設定的出場點數相同,
這樣來說是不太合理的,也會讓你很容易就出場了。

移動出場方式


所以在這邊要介紹一種比較相對的出場設定,
那就是,從高點往下拉回了前幾根K棒長度平均值的某個倍數就出場。
相反地,從低點往上拉回了前幾根K棒長度平均值的某個倍數就出場。
這要怎麼寫成程式碼呢?
其實很簡單,不過要先介紹幾個指令,
首先,我們要怎麼描述進場後的最高點,
可能有很多方式,但是最簡單扼要的方式就是,
Highest(high, ,barssinceentry) ,這個函數就是要找進場後的最高點
其中Barssinceentry就是表示進場後過了幾根K棒。
那進場後的最低點就是lowest(low,barssinceentry)。
所以這邊要告訴大家的高低點拉回程式碼就是
exitlong at highest(high,barssinceentry)-average(high-low,10)*5 stop;
exitshort at lowest(low,barssinceentry)+average(high-low,10)*5 stop;

這樣寫有什麼好處,
好處就是你拉回的幅度是由最近幾根K棒的長度來決定,
所以是比較相對的,就由當天的盤勢來決定出場點,
看起來似乎比固定點數出場方式要來的合理一點。
那把這個出場方式加入我們之前介紹的程式裡來看看績效有什麼改變。

回測時間,SHOW TIME!

回測目標:移動出場可以改進績效嗎?

回測標的:用台指5分K線作當沖交易。

回測成本設定:費用來回設定為1000元。

回測時間:從今天往前3000天。

進場方式:(1)當分數超過+3,啟動買進訊號,當價格向上突破前6根K棒高點時進場作多。
(2) 當分數低於-3,啟動賣出訊號,當價格往下突破前6根K棒低點時進場作空。

濾網:(1)限制當天多空都只能各進場一次。

出場方式:(1)設定停損點數為40點。
(2)收盤前1點40分全部出場。

其他出場方式:當指數從高點或是低點拉回過去10根K棒的平均長度的5倍時出場。

我們把報表整理如下:
A代表原來沒有停利的程式
B是加入新的移動出場程式



上圖為每年績效表



上圖為每年績效直方圖



上圖為其他各種報表重要數值



上圖為今年每個月的績效表



上圖為今年每個月的績效直方圖

由上面這些報表,大家可以發現到,
這次介紹的報表似乎比上次的要好,
除了總獲利上升外,DD也降低了。
不過這種出場方式有好處也有壞處,
好處是,如果指數往對你不利的方向發展,你可以提早出場。
但是指數上下在刷的時候,可能就會被掃出場,而失去一些獲利的機會。
不過有一得必有一失嘛,所以就要看你怎麼選擇。

1 意見:

匿名 提到...

Depressive disorders can make you really feel harmful.
Generating some basic lifestyle changes are usually rather beneficial.
Understand and follow the tips and information offered in the following paragraphs to
how the tiniest of changes can make your daily life greater.

You will be happy you look at this item.

It is very important understand that nobody is perfect.
Lots of people who are suffering from major depression started off the downwards spiral
because of thinking that just because they do not generally do or say the right point, there is certainly something wrong using them.
Focus on the features about you that you just and everyone else admires.
Sure, focus on your very good points and use these to form a good opinion of the all round personal.
This easy stage will help you on the road to
rehabilitation.

One of the best ideas to manage depression is actually by receiving a new activity.
A steady lack of interest in pursuits can definitely be considered
a key aspect in the onset of depression. Consider starting up a fresh creative hobby or sign up to a
class to eliminate monotony from the lifestyle.
No matter what suits you, doing something in any way will lower your probability of creating
depression.

You aren't insane. Major depression is an true mental health issues which
should acquire comparable regard with other diseases. Your system is
letting you know that anything isn't appropriate. This issue is simply alert from your body that you are currently working with a great deal and want to handle your emotional status.


To conquer major depression, you should surrounds on your
own with individuals who cherish you. Family, good friends,
or perhaps a loyal animal can fill up this explanation. They will actively try to help you become feel
good during the whole day. Surrounding yourself with optimistic influences is the simplest way to overcome major depression.

Will not be ashamed when your depression has forced you to have
to acquire medication. Often, major depression symptoms are incredibly bad how
the very best things to assist them to are medications.
Talk with a psychiatrist to determine if medication is a good choice to meet your needs and which medicine is greatest.


You ought to know that major depression does not mean you happen to be ridiculous.
As with all other disease, depressive disorders ought not to be
a stigma. If you are stressed out, it is actually a sign of issues like unresolved inner thoughts or perhaps an genuine, bodily chemical discrepancy.

Despression symptoms happens when the body lets you know that it's confused.


Like with nearly anything, the treating of depressive disorders has numerous studies,
methods, and concepts right behind how you can address it.
Also, it is fully dependent on the patient. Hopefully, you might have become the help of the following
tips into how to start with the treating of your despression symptoms so that you can begin experiencing much better
quicker.

my weblog ... émétophobie