請問如下的 “ 第二次及第n次開倉條件 ” 的語句如何編寫?
tr1 : max(max((high-low),abs(ref(close,1)-high)),abs(ref(close,1)-low));
atr : ma(tr1,20); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //atr公式
?
ma20:ma(close,20); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //20日均線
?
a1:=0.01*valuewhen(barpos=1,asset); ?????????????//初始資金的1%
?
a2:=floor(a1/(2*atr)); ? ? ? ? ? ? ? ? ? ? ? ? //開倉手數
?
a3:=ref(hhv(high,20),1); ? ? ? ? ? ? ? ? ? ? ? //20日高點
?
if holding=0 and close>a3 and close>ma20
then begin
buy(1,a2,marketr);
end ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //第一次開倉
?
a4:=enterprice-2*ref(atr,enterbars=1);
if holding=1 and low<=a4
then begin
sell(1,0,limitr,a4);
end ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //第一次開倉離場
?
//第二次及第n次開倉條件:如果隨后的收盤 > 上一次(即第 n-1 次)開倉的(enterprice+2*atr),則開倉(即第 n 次);
?
variable:bj=0;
tr1 : max(max((high-low),abs(ref(close,1)-high)),abs(ref(close,1)-low));
atr : ma(tr1,20); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //atr公式
ma20:ma(close,20); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //20日均線
a1:=0.01*valuewhen(barpos=1,asset); ?????????????//初始資金的1%
a2:=floor(a1/(2*atr)); ? ? ? ? ? ? ? ? ? ? ? ? //開倉手數
a3:=ref(hhv(high,20),1); ? ? ? ? ? ? ? ? ? ? ? //20日高點
if holding=0 and close>a3 and close>ma20 and bj=0
then begin
buy(1,a2,marketr);
bj:=1;
end ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //第一次開倉
if holidng=0 and close>enterprice+2*atr and bj=1?
then begin
buy(1,a2,marketr);
end
a4:=enterprice-2*ref(atr,enterbars=1);
if holding=1 and low<=a4
then begin
sell(1,0,limitr,a4);
end ? ? ? ? ? ? ?
?
?