只在这根K线开始时为某个变量赋值,如令A:=1。
我是1分钟K线轮询高频交易,所以用当second=0时为A赋值的方法不行,因为在秒数=0的这1秒内,也会重复几次令A:=1,有没有办法令这个赋值只在这根K线里执行一次呢?
[此贴子已经被作者于2014/8/11 14:28:55编辑过]
用一个全局变量限定
variable:num=0
if num=0 and second=0 then
begin
A:=1;
num:=1;
end
if num=1 and second=59 then //59秒时重新将num置0
num:=0;
variable:num=0,a=0;
sec1:=if(islastbar,dynainfo(207),time);
//second不能用在1分钟图,所以用另一种方法表示秒数
sec:=time0-timetot0(sec1);
if num=0 and sec=59 then
begin
a:=1;
num:=1;
end
if num=1 and sec=1 then
num:=0;
rc:=ref(c,1);
if c>rc+2 or c<rc-2 then a:=0
//我想要达到的效果,满足时a才会=0
variable:num=0,a=0;
sec1:=if(islastbar,dynainfo(207),time);
//second不能用在1分钟图,所以用另一种方法表示秒数
sec:=time0-timetot0(sec1);
if num=0 and sec=59 then
begin
a:=1;
num:=1;
end
if num=1 and sec=1 then
num:=0;
rc:=ref(c,1);
if (c>rc+2 or c<rc-2) and a=1 then begin
..开仓语句..;
a:=0;
end
//我想要达到的效果,满足时才开仓且只开一次
改了一下,大概是这样的
[此贴子已经被作者于2014/8/12 11:12:34编辑过]
一开始没留意second在分钟图上的问题,抱歉。
一条开仓语句本来就只开一次,你上面问题是什么。另外你这样会没有历史信号的。历史sec都是0,在and (a=1 or not(islastbar))这样处理下吧
恩,islastbar的问题我注意到了,这段代码只是举一个例子。
我的问题是这样的:
if num=0 and sec=59 then begin
a:=1;
num:=1;
end
这段代码,本意是在1分钟K线开始时,将a和num赋值=1。 等到满足 (c>rc+2 or c<rc-2) and a=1 这个条件后开仓,并令a=0使得不重复开仓。
但在我用高频轮询测试时发现,只有在sec=59时,a=1和num=1是对的。当1秒后,即sec=58以后,a和num两个变量就成0了。这样这两个变量的目的就达不到了
[此贴子已经被作者于2014/8/12 12:55:53编辑过]
1,这种K线内的精细控制,建议用户使用后台。图表涉及历史情况,不好处理
2,variable每次刷新都会重新赋值到0,只会记录当根K最后一次运行的结果。
如果一定要使用需要EXTGBDATASET记录