DIFF:=EMA(CLOSE,12) - EMA(CLOSE,26);
DEA:=EMA(DIFF,9);
MACD:=2*(DIFF-DEA);
//
JC:=CROSS(DIFF,DEA);
SC:=CROSS(DEA,DIFF);
JC1:=SUMBARS(JC,1);
SC1:=SUMBARS(SC,1);
//
aa:=holding;
//金叉时平空开多,死叉时平多开空,
if aa<0 and jc then sellshort(1,0,thisclose);
if aa=0 and sc then buyshort(1,1,thisclose);
if aa>0 and sc then sell(1,0,thisclose);
if aa=0 and jc then buy(1,1,thisclose);
在出来的图表上,在平多时当根K线并没有开空信号,在平空时当根K线并没有开多信号,不知应在buy语句中要如何改写,才能实现在当根K线上同时平多开空,

此主题相关图片如下:qq图片20150925215001.png

[此贴子已经被作者于2015/9/25 21:46:54编辑过]
if aa<0 and jc then sellshort(1,0,thisclose);
if aa>0 and sc then sell(1,0,thisclose);
if aa=0 and sc then buyshort(1,1,thisclose);
if aa=0 and jc then buy(1,1,thisclose);
在平仓后不马上开反向仓位,
这个问题导致测试结果与实盘差异过大,必须得解决才行
//
if holding>0 and sc then sell(1,0,thisclose);
if holding<0 and jc then sellshort(1,0,thisclose);
if holding=0 and sc then buyshort(1,1,thisclose);
if holding=0 and jc then buy(1,1,thisclose);
写成这样后解决了,可以平仓后反手了,但这里面的原因是什么?有哪些相关的东西需要我再学习下,请各位赐教
因为你把holding判断写前面了,后面平仓的holding变化影响不了aa值