|  | 
 
| 小弟是MC新手最近想寫一個布林通道的策略,但跑起來一直有問題,想請問下面語法哪裡有錯?另外,是否有更好建議可提供 Inputs:bollingerLengths(20),line1(2),line2(2),gaphigh(10),gapmid(5),stdths(10),stdthsloss(10),hm(1),hl(1),bm(1),bl(1);
 Vars: upBand(0),dnBand(0),mid(0),std(0),innumber(0);
 
 upBand = BollingerBand(Close,bollingerlengths,(20*0.1));
 dnBand = BollingerBand(Close,bollingerlengths,(20*(-0.1)));
 mid=(upband+dnband)*0.5; //設定布林通道上下中線
 std=upBand-dnBand;
 
 順勢進場
 //in
 if innumber=0 and std>std[1] and std[1]>std[2] and std[2]>std[3] then begin
 
 if h >upband and marketposition=0 then buy("highbuy") next bar  at market;
 if l <dnband and marketposition=0 then sellshort("highshort")   next bar at market; //過上線或下線進場
 innumber=innumber+1;
 end;
 出場
 //loss
 if innumber=1 then begin
 if l <mid and marketposition>0 then sell("highsell") next bar  at market;
 if h>mid  and marketposition<0  then buytocover ("highcover") next bar at market; //回落至中線出場
 innumber=innumber-1;
 end;
 
 逆勢進場
 //in
 if innumber=0 and std<=gapmid then begin
 if l<dnband and marketposition=0 then buy("midbuy") next bar at market;
 if h>upband and marketposition=0 then sellshort ("midshort") next bar at market;  //碰上下限反向操作
 innumber=2;
 end;
 出場
 //loss
 if innumber=2 then begin
 if l< mid and marketposition>0 then sell("midsell") next bar  at market;
 if h> mid and marketposition<0  then buytocover("midcover") next bar at market; //回落至中線出場
 innumber=innumber-2;
 end;
 
 
 
 | 
 |