以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  如何实现平多开空与平空开多信号在同一K线发出  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=85671)

--  作者:lcgs005
--  发布时间:2015/9/25 21:45:42
--  如何实现平多开空与平空开多信号在同一K线发出

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编辑过]

--  作者:王锋
--  发布时间:2015/9/25 21:51:38
--  
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);

--  作者:lcgs005
--  发布时间:2015/9/26 0:18:08
--  
还是不行的,在平仓后没有开仓信号


--  作者:lcgs005
--  发布时间:2015/9/26 0:27:34
--  
 在平仓后不马上开反向仓位,
这个问题导致测试结果与实盘差异过大,必须得解决才行

--  作者:lcgs005
--  发布时间:2015/9/26 0:53:25
--  
//
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);
写成这样后解决了,可以平仓后反手了,但这里面的原因是什么?有哪些相关的东西需要我再学习下,请各位赐教

--  作者:jinzhe
--  发布时间:2015/9/28 8:51:46
--  
因为你把holding判断写前面了,后面平仓的holding变化影响不了aa值