long1:=tsellholdingex('12202822',' ',1)>0 and c>ma4+5*mindiff ;
long2:=tsellholdingex('12202822',' ',1)=0 and c>ma4+5*mindiff and ma42>ref(ma4,1) ;
tsellshort(long1,0,mkt,0,0,'12202822');
tbuy(long2,1,mkt,0,0,'12202822');
short1:=tbuyholdingex('12202822',' ',1)>0 and c<ma42-5*mindiff ;
short2:=tbuyholdingex('12202822',' ',1)=0 and c<ma42-5*mindiff and ma4<ref(ma4,1) ;
tsell(short1,0,mkt,0,0,'12202822');
tbuyshort(short2,1,mkt,0,0,'12202822');
试运行了一下,持仓判断不对,应怎么改呀?
long1:=tsellholdingex('12202822',' ',1)>0 and c>ma4+5*mindiff ;
long2:=tsellholdingex('12202822',' ',1)=0 and c>ma4+5*mindiff and ma42>ref(ma4,1) ;
if long1 then
begin
tsellshort(1,0,mkt,0,0,'12202822');
end
if long2 then
begin
tbuy(1,1,mkt,0,0,'12202822');
end
short1:=tbuyholdingex('12202822',' ',1)>0 and c<ma42-5*mindiff ;
short2:=tbuyholdingex('12202822',' ',1)=0 and c<ma42-5*mindiff and ma4<ref(ma4,1) ;
if short1 then
begin
tsell(1,0,mkt,0,0,'12202822');
end
if short2 then
begin
tbuyshort(1,1,mkt,0,0,'12202822');
end
改成这样试试
楼主的写法基本正确.tbuyholdingex('12202822',' ',1)这种写法表示12202822帐户当前品种的所有买持仓
取到的就应该是实际的监控品种的买持仓呀.
if tsellholdingex('12202822','',1)>0 and c>ma4+5*mindiff then tsellshort(1,0,mkt,0,0,'12202822');//有空仓满足条件就平掉
//如果想没有空仓,满足条件就开多仓,可以这样写
if tsellholdingex('12202822','',1)=0 and c>ma4+5*mindiff and ma42>ref(ma4,1) then tbuy(1,0,mkt,0,0,'12202822');
//如果想即没有空仓也没有多仓,满足条件才开多仓,这样写
if tsellholdingex('12202822','',1)=0 and tbuyholdingex('12202822',' ',1)=0 and c>ma4+5*mindiff and ma42>ref(ma4,1) then
tbuy(1,0,mkt,0,0,'12202822');
看看你的tbuyholdingex('12202822','',1)这句,第2个参数,注意中间不要有空格
可用这句话在图表上看看你的该帐户在该品种的持仓是否正确
x:tbuyholdingex('12202822','',1),linethick0;
对了,是空格的问题