有没有简单的方法?有,呵呵,看下面的例子:双均线交易.
input:man1(12),man2(26);
ma1:ma(close,man1),colorred;
ma2:ma(close,man2),colorgreen;
ts:=iif(ma1>ma2,1,iif(ma1<ma2,-1,0)); //注意
ts_1:=ref(ts,1);
ts_2:=ref(ts,2);
{平多}
sell(holding>0 and (ts<0 and ts_1>0),0,thisclose); //测试时,需要跳变
Tsell(Tholding>0 and (ts_1<0 and ts_2>0),0,lmt,c); //实战时,冒头就行,注意取值
{平空}
sellshort(holding<0 and (ts>0 and ts_1<0),0,thisclose);
Tsellshort(Tholding<0 and (ts_1>0 and ts_2<0),0,lmt,c);
{开多}
buy(vol>=3000 and holding=0 and ts>0 and ts_1<0 ,intpart(asset*0.4/close),thisclose);
Tbuy(vol>=5000 and Tholding=0 and ts_1>0 and ts_2<0,intpart(Tasset*0.1/close),lmt,c);
{开空}
buyshort(vol>=3000 and holding=0 and ts<0 and ts_1>0,intpart(asset*0.4/close),thisclose);
Tbuyshort(vol>=5000 and Tholding=0 and ts_1<0 and ts_2>0,intpart(Tasset*0.1/close),lmt,c);
资产_control:asset,COLORCYAN,noaxis;
//持仓:holding,noaxis;
问题解决了,如果采用其他解决方案,代码比较长,不例举了,有兴趣,大家一起探讨。
本文意在回馈论坛,因为从版主,管理员那学到很多东西,打扰了很长时间,听说在以后1.94版,这个问题会得到完满的解决,让我们拭目以待。。。。
[此贴子已经被作者于2009-11-11 3:15:08编辑过]