看了两天了没看出毛病,自己被绕晕了,不得已发上来请教一下
此主题相关图片如下:qq图片20161012163548.png

===============================================
//中间变量
gapprice:=gap*fprice;//一跳多少钱
variable:markprice=fprice;//发生交易时的参考价格
disp:=(gapn-0.1)*gapprice;//定义波动极限,upp和downp的范围之内是能进行增减交易,最边缘的交易将导致超出范围
upp:fprice+disp;
downp:fprice-disp;
refpm:ref(markprice,1),CIRCLEDOT;
//执行
if barpos=1 then buy(1,10000,market);
if date()>daterun+1000000 then begin
if c>=refpm+gapprice and c<upp then begin
sell (1,stockgap,market,refpm+gapprice);
markprice:=refpm+gapprice;
GOTO QUITLINE;
end
end
QUITLINE@ ee:markprice,CROSSDOT;
EXIT;
====================================
设计思路是,当价格高于markprice一个gapprice时卖出一次,同时markprice要加上一个gapprice。
主要的问题是,refpm并没有完全被赋值为前一天的markprice,而是在发生变化时推迟了一天,于是价格突破某个界限时的交易变成了连续两天交易。
猜测可能是在判断语句里对markprice重新赋值造成的,但不知道该怎么处理。
如图,refpm是圆圈线,ee:markprice是X线,应该两者只差一个周期,但是在发生交易的位置,却并非如此。
if c>=refpm+gapprice and c<upp then begin
这里加一个holding>0的条件,也就是:
if c>=refpm+gapprice and c<upp and holding>0 then begin
这个和持仓没关系,持仓一直大于0,因为前面有初始仓位。
我要的不是信号过滤,而是连在一起的第二个信号不应该有,如果refpm能跟上上周期的markprice。。。
if c>=markprice+gapprice and c<upp then begin
sell (1,stockgap,limitr,refpm+gapprice),ignorecheckprice;
markprice:=markprice+gapprice;
GOTO QUITLINE;
end