代码如下:
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 //第一次开仓
a4:=enterprice+2*atr;
if holding=0 and close>a4 and bj=1
then begin
buy(1,a2,marketr);
end //第n次开仓
a5:=enterprice-2*ref(atr,enterbars=1);
if holding=1 and low<=a5
then begin
sell(1,0,limitr,a4);
end //第一次开仓的离场
现在,我要设置的、当holding>1时的离场方式为:收盘<("holding=n"与“holding=n-1”)/2的位置;请问该如何编写?
此主题相关图片如下:止损.jpg

[此贴子已经被作者于2017/3/22 11:27:39编辑过]