有老師說,布林通道(bollingband)很適合當做逆勢交易的支撐或壓力,到達通道下緣買進多單,通道上緣買進空單,這樣到底會不會賺錢,以下是程式交易的簡單範例
inputs:len1(40),len2(3); 參數設定
vars:VH(0); 自訂變數
value1 = BollingerBand(close, len1, len2); 布林通道上緣
value2 = average(close,len1); 移動平均線(布林通道中線)
value3 = BollingerBand(close, len1, -len2); 布林通道下緣
if date[0]<>date[1] then begin VH = 99999; end; 每天開盤的時候變數歸無限大
if time>0900 and time<1300 and entriestoday(date)<=0 then begin 限制交易時間和交易次數
if L<value2 then VH=H ;
if Value2-Value3>10 and value2-value3<50 and value2-value2[1]<0 then buy next bar at VH+1 stop; 當布林通道的寬度在一定區間而且均線的斜率往下 就準備買進多單
end;
setstoploss(50*pointvalue); 設定停損
if marketposition=1 and time>=1325 then sell next bar at market; 多單收盤前平倉
以上範例僅作參考,可以發揮自己的創意找出更適合的交易模式;透過multicharts回測功能可以印證實際交易的可行性