布林通道語法請教
小弟是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 and std>std and std>std then begin
if h >upband and marketposition=0 then buy("highbuy") next barat 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 barat market;
if h>midand marketposition<0then 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 barat market;
if h> mid and marketposition<0then buytocover("midcover") next bar at market; //回落至中線出場
innumber=innumber-2;
end;
2.要將K棒可能會同時跨在billing info 指標的兩條或三條線上,這會造成進出場訊號錯誤 不要用innumber去計算部位,而且你這樣寫多空都混在一起,部位全記錯了
值接利用marketposition跟currentcontracts去判斷部位跟多空即可 1.變數 innumber 在判斷條件不成立時不會計數,會造成有倉位時無法出場
頁:
[1]