现有模型A,B,C。分别运行于3、5、8分钟周期。
如何引用它们的holding持仓量以达到以下目的:
1、当ABC皆为1即做多,则新模型做多buy。
2、当ABC皆为-1即做空,则新模型做空buy short
3、其余时候都全平,持仓为0
请问该如何写?运行于哪个周期?
[此贴子已经被作者于2014/9/3 0:37:44编辑过]
分别设置3个公式,买入卖出改为holdings=1或者=0或者=-1
在策略里引用三个holdings的值,三者相加=3则做多,=-3做空
新策略要运行在1分钟周期,才能保证以更小时间间隔执行三个策略而不漏单
r1:=todaybar-1;
//********************************
rr1:=stkindiex('if00','tears25.持仓',0,22,80,0);
rr2:=stkindiex('if00','tears25.持仓',0,22,90,0);
rr3:=stkindiex('if00','qq25.持仓',0,22,125,0),noaxis;
r12:rr1+rr2+rr3,linethick0;
//*************第一遍*************
if r12=3 and p3<=xdd then
begin
buy(holding<cx,tn,limitr,jgx+hd1+hdd);
end
if r12=-3 and p3<=xdk then
begin
buyshort(abs(holding)<cx,tn,limitr,jgs-hd1-hdk);
end
//*************第二遍*************
if r12=3 and p3<=xdd then
begin
buy(holding<cx,tn,limitr,jgx+hd1+hdd);
end
if r12=-3 and p3<=xdk then
begin
buyshort(abs(holding)<cx,tn,limitr,jgs-hd1-hdk);
end
//*************第三遍*************
if r12=3 and p3<=xdd then
begin
buy(holding<cx,tn,limitr,jgx+hd1+hdd);
end
if r12=-3 and p3<=xdk then
begin
buyshort(abs(holding)<cx,tn,limitr,jgs-hd1-hdk);
end
//********************************
if abs(r12)<=2 and p3<=xdk then
begin
sell(holding>0,0,limitr,jgs-hd1-hdk);
end
if abs(r12)<=2 and p3<=xdd then
begin
sellshort(holding<0,0,limitr,jgx+hd1+hdk);
end
//********************************
交易总数:totaltrade,colorwhite,linethick0;
盈亏:asset-1000000,colorred,linethick1,noaxis;
日盈亏:asset-ref(asset,todaybar),noaxis,colorred,linethick0;
虚拟持仓:holding,colorwhite,linethick0;
variable:hc=0;
回撤:hhv(盈亏,30000)-盈亏,linethick0,coloryellow;
if 回撤>hc then hc:=回撤;
最大回撤:hc,linethick0,coloryellow;
[此贴子已经被作者于2014/9/3 8:10:35编辑过]
如果是用后台交易,开仓只要写一遍,就可以了。
如果是标准版图表交易,可以用小一点的周期,看看再同一根k线有几个同时下单的可能就用几遍。
一般使用轮询,什么周期都可以。
原程序信号不能闪,如果有闪的问题,可以适当延长扫描时间。
重新整理一下,前面说的不对,前面说的是净单交易:
r1:=todaybar-1;
//********************************
rr1:=stkindiex('if00','tears25.持仓',0,22,80,0);
rr2:=stkindiex('if00','tears25.持仓',0,22,90,0);
rr3:=stkindiex('if00','tears25.持仓',0,22,125,0),noaxis;
r12:rr1+rr2+rr3,linethick0;
//*****************************
if r12=3 then
begin
buy(holding=0,tn,limitr,c);
end
if r12=-3 then
begin
uyshort(abs(holding)=0,tn,limitr,c);
end
//********************************
if abs(r12)<=2 then
begin
sell(holding=0,0,limitr,c);
end
if abs(r12)<=2 then
begin
sellshort(holding=0,0,limitr,c);
end
//********************************
交易总数:totaltrade,colorwhite,linethick0;
盈亏:asset-1000000,colorred,linethick1,noaxis;
日盈亏:asset-ref(asset,todaybar),noaxis,colorred,linethick0;
虚拟持仓:holding,colorwhite,linethick0;
variable:hc=0;
回撤:hhv(盈亏,30000)-盈亏,linethick0,coloryellow;
if 回撤>hc then hc:=回撤;
最大回撤:hc,linethick0,coloryellow;
什么周期都可以,不要太大(8分,10分都可以)。
要使用轮询,原程序的信号不能闪,否则会来回交易,可以适当延长扫描时间来缓解“信号闪”的问题。
也可以在任意周期上使用k线走完模式交易,注意这样做图表结果和实盘是有差异的。如果图表k线周期大于你原程序周期则一致。
重新修改一下:
r1:=todaybar-1;
tn:=1;
//********************************
rr1:=stkindiex('if00','tears25.持仓',0,22,80,0);
rr2:=stkindiex('if00','tears25.持仓',0,22,90,0);
rr3:=stkindiex('if00','tears25.持仓',0,22,125,0),noaxis;
r12:rr1+rr2+rr3,linethick0;
//*****************************
if r12=3 then
begin
buy(holding=0,tn,limitr,c);
end
if r12=-3 then
begin
buyshort(abs(holding)=0,tn,limitr,c);
end
//********************************
if abs(r12)<=2 then
begin
sell(holding>0,0,limitr,c);
end
if abs(r12)<=2 then
begin
sellshort(holding<0,0,limitr,c);
end
//********************************
交易总数:totaltrade,colorwhite,linethick0;
盈亏:asset-1000000,colorred,linethick1,noaxis;
日盈亏:asset-ref(asset,todaybar),noaxis,colorred,linethick0;
虚拟持仓:holding,colorwhite,linethick0;
variable:hc=0;
回撤:hhv(盈亏,30000)-盈亏,linethick0,coloryellow;
if 回撤>hc then hc:=回撤;
最大回撤:hc,linethick0,coloryellow;
如果不是一根k线走完,图表结果和实盘结果有差异,实盘会比图表好。