平仓条件中加入abb:=(time0-timetot0(dynainfo(207))<=tq) or not(islastbar); 这个判断、
提前下单的范例代码,tq是提前的时间没
ma5:=ma(c,5);
ma10:=ma(c,10);
input:tq(5,3,60,1);//提前的秒数,最多提前60秒
abb:=(time0-timetot0(dynainfo(207))<=tq) or not(islastbar);
if abb then begin
if holding>0 and ma5<ma10 then sell(1,1,thisclose);
if holding<0 and ma5>ma10 then sellshort(1,1,thisclose);
if holding=0 and ma5>ma10 then buy(1,1,thisclose);
if holding=0 and ma5<ma10 then buyshort(1,1,thisclose);
end
//要设置为轮询1秒模式,平仓想设为走完1根K线但提前1秒下单,开仓想及时下单
DMA5: MA(high,5);
KMA5: MA(low,5);
DMA10:MA(high,10);
KMA10:MA(Low,10);
B1:=CROSS(DMA5,DMA10);
B2:=CROSS(KMA10,KMA5);
if date<>ref(date,1) then begin
count1:=1;
count2:=1;
end
lots:=1;
p2:=if(islastbar,dynainfo(207),time);
p3:=time0-timetot0(p2),linethick0;
//亏损平仓
if holding>0 and l<=ENTERPRICE-10 AND HOLDING>0 and p3<=1,0,limitr,jgs-hdk then begin
sell(1,holding,NEXTOPEN),IGNORECHECKPRICE;
end
if holding<0 and h>=ENTERPRICE+10 AND HOLDING<0 and p3<=1,0,limitr,jgx+hdd then begin
sellshort(1,holding,NEXTOPEN),IGNORECHECKPRICE;
end
//开仓
if holding=0 and count2=1 then begin
if B1 then begin
buy(1,lots,limitr,open),IGNORECHECKPRICE;
HigherAfterEntry:=enterprice;
LowerAfterEntry:=enterprice;
end
end
if holding=0 and count2=1 then begin
if B2 then
begin
buySHORT(1,lots,limitr,open),IGNORECHECKPRICE;
HigherAfterEntry:=enterprice;
LowerAfterEntry:=enterprice;
end
end
//盈利平仓
if holding>0 and enterbars>0 then begin
if enterbars>=1 and HigherAfterEntry>=enterprice*1 AND HOLDING>0 and p3<=5,0,limitr,jgs-hdk then begin
price:=EnterPrice+(HigherAfterEntry-EnterPrice)*1;
if low<=price then begin
sell(1,holding,NEXTOPEN),IGNORECHECKPRICE;
count2:=1;
end
end;
end;
if holding<0 and enterbars>0 then begin
if enterbars>=1 and lowerAfterEntry<=enterprice*1 AND HOLDING<0 and p3<=5,0,limitr,jgx+hdd then begin
price:=EnterPrice - (EnterPrice-LowerAfterEntry)*1;
if high>=price then begin
sellshort(1,holding,NEXTOPEN),IGNORECHECKPRICE;
count2:=1;
end;
end
end;
谢谢老师,谢谢老师