思路如下:
1:空仓情况下(2个常量:X/Y)
收盘价上穿X开多,如果收盘前下破X平多,否则持多仓过夜;
收盘价下破Y开空,如果收盘前上穿Y平空,否则持空仓过夜;
2:持仓情况下(2个常量:X/Y)
持多仓:
收盘价下破Y平多开空,如果收盘前上穿Y平空开多,否则持空仓过夜;
持空仓:
收盘价上穿X平空开多,如果收盘前下穿X平多开空,否则持多仓过夜;
已经请人编好的如下:
if holding=0 and cross(close,x) then begin
buy(1,1,market);
end
if cross(x,close) and holding>0 then begin
sell(1,0,market);
end
if holding=0 and cross(y,close) then begin
buyshort(1,1,market);
end
if holding<0 and cross(close,y) then begin
sellshort(1,0,market);
end
if holding>0 and cross(y,close) then begin
sell(1,0,market);
buyshort(holding=0,1,market);
end
if cross(close,y) then begin
sellshort(1,0,market);
buy(holding=0,1,market);
end
if holding<0 and cross(close,x) then begin
sellshort(1,0,market);
buy(holding=0,1,market);
end
if cross(x,close) then begin
sell(1,0,market);
buyshort(holding=0,1,market);
end
问题是:
在我持有隔夜多单时,次日日内在没有出现平多开空动作情况下,直接开多了,也就是这段指令发生作用了:
if holding<0 and cross(close,x) then begin
sellshort(1,0,market);
buy(holding=0,1,market);
end
我是想在我持有隔夜多单时,次日日内如果没有下破Y则持有多单过夜,若下破Y,则平多开空,若再次上穿X,则平空开多,上述条件循环执行。能力有限,不知我表达清楚了没有,还请各位老师不吝赐教!
if cross(close,y) then begin
sellshort(1,0,market);
buy(holding=0,1,market);
end
//是你这段代码出现问题,此处没有限制有仓或无仓的情况。
另外CROSS函数不能在IF条件语句里使用
例如代码第一段
if holding=0 and cross(close,x) then begin
buy(1,1,market);
end
应该是这样写
cond1:CROSS(C,X);
IF HOLDING=0 AND COND1 THEN
BEGIN
BUY();
END
老师麻烦看一下,这样写对吗?我试了一下,主图没有显示,软件好像还是不能判断持仓情况:
持多仓:
收盘价下破Y平多开空,如果收盘前上穿Y平空开多,否则持空仓过夜;
cond3:=CROSS(C,Y);
cond4:=CROSS(Y,C);
if holding>0 and cond4 then
begin
sell(1,0,market);
buyshort(holding=0,1,market);
end
if holding>0 and cond3 then
begin
sellshort(1,0,market);
buy(holding=0,1,market);
end
“if holding>0 and cond3 then ”
平空时应该时holding<0,另外平仓手数最好写holding,不要写0,holding是平掉本策略里的持仓,0会平掉此品种所有持仓,包括其他策略开的仓。
sellshort(1,0,market);
buy(holding=0,1,market);
end
平空的持仓判断是<0不是>0