,“K线走完模式”转换成“固定轮询模式”或者“混合模式”的方法
以便把各个模型放在同一个框架内进行图表程序化交易
举例:
均线交叉模型运行于图表走完K线模式
[PEL] [color=rgb(51, 102, 153) !important][color=rgb(51, 102, 153) !important]复制代码
[color=rgb(255, 255, 255) !important][color=#ffffff !important] ?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
| runmode:0;
ma5:=ma(c,5);
ma20:=ma(c,20);
entertime:=time>100000 and time<144500;
if holding>0 and ma5<ma20 then sell(1,1,market);
if holding<0 and ma5>ma20 then sellshort(1,1,market);
if holding=0 and ma5>ma20 and entertime then buy(1,1,market);
if holding=0 and ma5<ma20 and entertime then buyshort(1,1,market);
if time>=150000 then begin
sell(1,1,market);
sellshort(1,1,market);
end
|
怎么改动上面的均线交易模型让它在图表固定轮询模式下执行的效果和上部分代码应用在走完K线模式下完全一样 简单的改法,自然是把各个条件“过去化”,如:ma5 改为 ref(ma(c,5),1);但这种方法碰到大型的、复杂的模型时,容易出错 可采用这种方法,把holding用全局变量cc替换,然后加入注释部分代码,注释色部分代码要放在信号语句的前面。
运行于图表固定轮询模式
[PEL] [color=rgb(51, 102, 153) !important][color=rgb(51, 102, 153) !important]复制代码
[color=rgb(255, 255, 255) !important][color=#ffffff !important] ?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
| runmode:0;
variable:cc=0;
ma5:=ma(c,5);
ma20:=ma(c,20);
entertime:=time>100000 and time<144500;
if holding>0 and cc<=0 then sell(1,1,limitr,o); //注释变化
if holding<0 and cc>=0 then sellshort(1,1,limitr,o); //注释变化
if holding=0 and cc>0 then buy(1,1,limitr,o); //注释变化
if holding=0 and cc<0 then buyshort(1,1,limitr,o); //注释变化
if cc>0 and ma5<ma20 then cc:=0;
if cc<0 and ma5>ma20 then cc:=0;
if cc=0 and ma5>ma20 and entertime then cc:=1;
if cc=0 and ma5<ma20 and entertime then cc:=-1;
if time>=150000 then begin cc:=0;
K线走完模式我理解就是本根K完成的时候信号固定了,然后在下根K开仓吧?
这是帖子里的代码,我不理解的是加个CC的控制貌似只是对上一个轮询时候的状态,轮询是1秒的,比如当前,CC=0但是这时候ma5>ma20了,自然CC状态就变成了1,不是在下个轮询
时候就可以满足buy的条件了,也就是还是在当根K线上实现了开仓,而不是下一根K线。为什么说能在轮询模式下能做到和K线走完一个效果?;
|
补充内容 (2022-4-7 10:29):
不知道为啥,拷贝过来出错了,反正就是论坛里那个教学帖子,我的问题是照道理比如cc当前=0,但是ma5>ma20了,程序本次轮询执行之后cc值应该=1了,等下次轮询的时候如果ma5>m20那么cc=1,就可以触发买入条件了
补充内容 (2022-4-7 10:30):
这样不还是原来的轮询的效果吗,为啥能实现K线走完的效果呢
补充内容 (2022-4-7 10:31):
https://www.weistock.com/bbs/for ... &extra=page%3D1 这个帖子的第一条 |