代码如下,很简单的ma交易系统
input:man(26,2,200);
ma1:=ma(close,man);
ccm:=cross(close,ma1);
cmc:=cross(ma1,close);
{开多}
buy(vol>20000 and holding=0 and ccm,1);
{平多}
sell(holding>0 and cmc,1);
{开空}
buyshort(vol>20000 and holding=0 and cmc,1);
{平空}
sellshort(holding<0 and ccm,1);
改成如下代码也不行 不明白了
input:man(26,2,200);
ma1:=ma(close,man);
ccm:=cross(close,ma1);
cmc:=cross(ma1,close);
if holding=0 then
begin
{开多}
if ccm then
begin
buy(ccm,1);
exit;
end;
{开空}
if cmc then
begin
buyshort(cmc,1);
exit;
end;
end;
{平多}
if cmc and holding>0 then
begin
sell(holding>0 and cmc,1);
exit;
end;
{平空}
sellshort(holding<0 and ccm,1);
这样写就对了,这是交易逻辑处理的问题
input:man(26,2,200);
ma1:=ma(close,man);
ccm:=cross(close,ma1);
cmc:=cross(ma1,close);
资产:ASSET,LINETHICK0;
可用现金:CASH(0),LINETHICK0;
持仓:HOLDING,LINETHICK0;
if ccm then
begin
//平空开多
sellshort(holding<0 and ccm,0);
buy(holding<=0,1);
end
if cmc then
begin
//平多开空
sell(holding>0 and cmc,0);
buyshort(holding>=0,1);
end