每個人總有不只一個的進場標準,如何讓多個標準協同作業? 大家都有不同的自由心證法,透過程式語法,我們可以把不同的進場標準在K線圖中標示出來,從圖上進場點的標示分佈及密度來作決策。
有些程式交易者,認為交易愈簡單愈好,所以找出一個進場的標準就夠了,剩下的交給交易紀律及資金管理即可,加上其他的濾網往往僅是為了回測的最佳化,甚至可能過度最佳化。
我個人的經驗則是,如果有幾個彼些不相關的進場標準,都同時或相繼出現交易訊號,其可信度是會提高的,最常舉的例子是當我們感冒的時候,可能發燒,喉嚨痛,流鼻涕,咳嗽,全身無力,冒冷汗,如果只是發燒,或只是咳嗽,那麼不一定是感冒,但如果上面的症狀都相繼發作,那麼感冒的機率就大增了。
基於這樣的思考,我在三週學會程式交易這本書的實戰篇裡,提出了一個”個股儀表板”的概念,透過自訂指標的程式撰寫,在個股的K線圖上,把不同的進場訊號標示出來,讓我們可以隨時檢視,那些股票相繼且密集的出現進場訊號。
我在書裡舉了以下的例子
{
指標說明
個股儀表板演化的交易策略
收錄於「三週學會程式交易:打造你的第一筆自動化交易」 330頁
https://www.ipci.com.tw/books_in.php?book_id=724
}
condition1=false;
condition2=false;
condition3=false;
condition4=false;
condition5=false;
condition6=false;
condition7=false;
condition8=false;
condition9=false;
condition10=false;
switch(close)
begin
case >150: value5=low*0.9;
case <50 : value5=low*0.98;
default: value5=low*0.95;
end;
//==========日KD黃金交叉================
input: _TEXT1("===============","KD參數");
input: Length_D(9,"日KD期間");
variable:rsv_d(0),kk_d(0),dd_d(0),c5(0);
stochastic(Length_D, 3, 3, rsv_d, kk_d, dd_d);
c5=barslast(kk_d crosses over dd_d);
if c5=0 and c5[1]>20 then
condition1=true;
if condition1 then
plot1(value5,"月KD高檔鈍化且日KD黃金交叉");
//============內外盤量比差====================
variable:c3(0);
value6=GetField("內盤量");//單位:元
value7=GetField("外盤量");//單位:元
if volume<>0 then begin
value8=value7/volume*100;//外盤量比
value9=value6/volume*100;//內盤量比
end;
value10=average(value8,5);
value11=average(value9,5);
value7=value10-value11+5;
c3=barslast(value7 crosses over 0);
if c3=0 and c3[1]>20 then
condition2=true;
if condition2 then
plot2(value5*0.99,"內外盤量比差");
//===========淨力指標==============
input: _TEXT2("===============","淨力指標參數");
input:period2(10,"長期參數");
variable:c4(0);
value12=summation(high-close,period2);//上檔賣壓
value13=summation(close-open,period2); //多空實績
value14=summation(close-low,period2);//下檔支撐
value15=summation(open-close[1],period2);//隔夜力道
if close<>0 then
value16=(value13+value14+value15-value12)/close*100;
c4=barslast(value16 crosses over -4);
if c4=0 and c4[1]>20 then
condition3=true;
if condition3 then
plot3(value5*0.98,"淨力指標");
//===========多頭起漲前的籌碼收集================
variable:c2(0);
value1=GetField("分公司買進家數");
value2=GetField("分公司賣出家數");
value3=value2-value1;
value4=countif(value3>20,10);
c2=barslast(value4>6);
if c2=0 and c2[1]>20 then
condition4=true;
if condition4=true then
plot4(value5*0.97,"籌碼收集");
//===========法人同步買超====================
variable: v1(0),v2(0),v3(0),c1(0);
v1=GetField("外資買賣超");
v2=GetField("投信買賣超");
v3=GetField("自營商買賣超");
c1= barslast(maxlist2(v1,v2,v3)>100);
if c1=0 and c1[1]>20 then
condition5=true;
if condition5=true then
plot5(value5*0.96,"法人同步買超");
//========DIF-MACD 翻正=============
input: _TEXT3("===============","MACD參數");
input: FastLength(12,"DIF短天數"), SlowLength(26, "DIF長天數"), MACDLength(9, "MACD天數");
variable: difValue(0), macdValue(0), oscValue(0);
MACD(weightedclose(), FastLength, SlowLength,MACDLength, difValue, macdValue, oscValue);
variable:c6(0);
c6=barslast(oscValue Crosses Above 0);
if c6=0 and c6[1]>20 then
condition6=true;
if condition6 then
plot6(value5*0.95,"DIF-MACD 翻正");
//========資金流向======================
variable: m1(0),ma1(0),c7(0);
m1=GetField("資金流向");
ma1=average(m1,20)*1.5;
c7=barslast(m1 crosses over ma1 and close>close[1]);
if c7=0 and c7[1]>20 then
condition7=true;
if condition7 then
plot7(value5*0.94,"資金流向");
//=========總成交次數================
variable: t1(0),mat1(0),c8(0);
t1=GetField("總成交次數","D");
mat1=average(t1,20)*1.5;
c8=barslast(t1 crosses over mat1 and close>close[1]);
if c8=0 and c8[1]>20 then
condition8=true;
if condition8 then
plot8(value5*0.93,"成交次數");
//=========強弱指標==================
variable:s1(0),c9(0);
s1=GetField("強弱指標","D");
c9=barslast(trueall(s1>0,3));
if c9=0 and c9[1]>20 then
condition9=true;
if condition9 then
plot9(value5*0.92,"強弱指標");
//============開盤委買================
variable:b1(0),mab1(0),c10(0);
b1=GetField("主力買張");
mab1=average(b1,10);
c10=barslast(b1 crosses over mab1);
if c10=0 and c10[1]>10 then
condition10=true;
if condition10 then
plot10(value5*0.91,"主力買張");
用這個腳本畫出來的圖如下圖
這個程式它的步驟有幾個
一,把每一個進場標準都視為一個condition,有多少個標準就設多少個,每一個condition的default值都是false。
二,依不同價位設置進場點的標示位置,
三,開始根據進場標準,在condition從false變成true時把進場標示標在當根K棒的底下,用Barslast來過濾同一個訊號必須是20天來第一次出現的
根據這些步驟,舉一個更容易理解的例子,如果把移動平均線黃金交叉,動能指標突破零,9K突破9D,以及6日RSI突破12日RSI,DIF-MACD轉正視為五個不同的進場標準,那麼包含這四個進場標準的個股儀表板就可以像下面這個腳本的寫法
//把每一個進場標準都視為一個condition,
//有多少個標準就設多少個,
//每一個condition的default值都是false。
condition1=false;
condition2=false;
condition3=false;
condition4=false;
condition5=false;
//依不同價位設置進場點的標示位置
switch(close)
begin
case >150: value5=low*0.9;
case <50 : value5=low*0.98;
default: value5=low*0.95;
end;
//開始根據進場標準,
//在condition從false變成true時
//把進場標示標在當根K棒的底下。
//用Barslast來過濾同一個訊號必須是20天來第一次出現的
//==========日KD黃金交叉================
input: _TEXT1("===============","KD參數");
input: Length_D(9,"日KD期間");
variable:rsv_d(0),kk_d(0),dd_d(0),c1(0);
stochastic(Length_D, 3, 3, rsv_d, kk_d, dd_d);
c1=barslast(kk_d crosses over dd_d);
if c1=0 and c1[1]>20 then
condition1=true;
if condition1 then
plot1(value5,"月KD高檔鈍化且日KD黃金交叉");
//========DIF-MACD 翻正=============
input: _TEXT3("===============","MACD參數");
input: FastLength(12,"DIF短天數"), SlowLength(26, "DIF長天數"), MACDLength(9, "MACD天數");
variable: difValue(0), macdValue(0), oscValue(0);
MACD(weightedclose(), FastLength, SlowLength,MACDLength, difValue, macdValue, oscValue);
variable:c2(0);
c2=barslast(oscValue Crosses Above 0);
if c2=0 and c2[1]>20 then
condition2=true;
if condition2 then
plot2(value5*0.99,"DIF-MACD 翻正");
//========移動平均線黃金交叉======================
variable: c3(0);
c3=barslast(average(close,5)cross over average(close,20));
if c3=0 and c3[1]>20 then
condition3=true;
if condition3 then
plot3(value5*0.98,"移動平均線黃金交叉");
//=========RSI黃金交叉================
variable: c4(0);
c4=barslast(RSI(close,6) crosses over rsi(close,12));
if c4=0 and c4[1]>20 then
condition4=true;
if condition4 then
plot4(value5*0.97,"RSI黃金交叉");
//=========動能指標==================
variable:c5(0);
c5=barslast( momentum(close,10) crosses over 0);
if c5=0 and c5[1]>20 then
condition5=true;
if condition5 then
plot5(value5*0.96,"動能指標");
這樣的腳本可以畫出下面這樣的圖
透過這樣的視覺化作法,就可以把您私房的進場標準,一一標示在K線圖上,這樣就隨時可以檢視自選股符合那些您自設的進場標準了。


