策略的想法很簡單,用長期的資料區間畫出箱型的上下緣後,再使用短期的資料區間去判斷買進與賣出訊號。
經過測試,此策略使用的時間區間是3日線與一小時線,如果要試用看看的朋友可以試試看其他日期區間。
附帶一提,這個策略並沒有加上台指到期日出場的語法。要試用的人也可以自己加上去測試看看。
好了,說了這麼多,程式碼如以下所示。
vars:HighBox(0),LowBox(0);
condition1 = (high[1] > (high[2]) and high[1] > (high)) of data2;
condition3 = ((Low[1] )< low[2] and (Low[1])< low) of data2;
if condition1 then
HighBox = high[1];
if condition3 then
LowBox = Low[1];
if C > HighBox and O < highbox then begin //long
if marketposition = 0 then
buy("B") this bar at close;
if marketposition = -1 then
buytocover("BC") this bar at close;
end;
if C < LowBox and O > lowbox then begin //short
if marketposition = 0 then
sellshort("SH") this bar at close;
if marketposition = 1 then
sell("S") this bar at close;
end;
SetPercentTrailing(100000, 10);
這個策略的實測結果如下,測試使用資料是台指期10年資料。跟大家分享,有使用的朋友,也可以回饋您的心得給我喔。

沒有留言:
張貼留言