开拓者期货期权程序化系统交易论坛

标题: 两种写法得出的结论不一样,求高手解答一下。 [打印本页]

作者: yimatouzi    时间: 2017-10-22 15:29:45     标题: 两种写法得出的结论不一样,求高手解答一下。


    想在早上十点的时候,取 9-10点之间的  最高价与最低价,  用了两种方法写,感觉上是都是可行的,第一种方法得出的结论不对,只是当前K线的高低点。


Params


Vars

  Numeric   high10;
  numeric   low10;
     
Begin


If(time==0.1000)
{
High10=Highest(high,59);
  Low10=Lowest(low,59);
SetGlobalVar(0,High10);
SetGlobalVar(1,Low10);

PlotNumeric("aa",high10,0,-1,0);
PlotNumeric("bb",low10,0,-1,0);
}
//PlotString("H10",text(high10),h,-1,0);
//PlotString("L10",text(low10),l,-1,0);


End
上面这种方法得出的是 10点根K线的最高最低价。
Params


Vars

  Numeric   high10;
  numeric   low10;
     
Begin

  High10=Highest(high,59);
  Low10=Lowest(low,59);
If(time==0.1000)
{
SetGlobalVar(0,High10);
SetGlobalVar(1,Low10);

PlotNumeric("aa",high10,0,-1,0);
PlotNumeric("bb",low10,0,-1,0);
}
//PlotString("H10",text(high10),h,-1,0);
//PlotString("L10",text(low10),l,-1,0);


End

把最高价最低价定义 放在时间外,又正常了,这是为何?



作者: cf_55390    时间: 2017-10-22 15:54:34

time 是Bar的开始时间,在当根Bar没结束前time==0.1000你里面的代码每来个tick都会执行,直到当根Bar完成,High,Low也会更新,自然取不到正确值。
作者: yimatouzi    时间: 2017-10-22 16:27:20

cf_55390 发表于 2017-10-22 15:54
time 是Bar的开始时间,在当根Bar没结束前time==0.1000你里面的代码每来个tick都会执行,直到当根Bar完成, ...

用的历史回测,不是实时的。不存在这种问题。
作者: cf_55390    时间: 2017-10-22 18:40:11

这个可能是Highest,Lowest底层封装的机制问题,写在外面是每个BAR执行一遍(历史回测)在条件T=0.1000里是只执行一次,你看看在实盘下或模拟盘中能否取到该值。
作者: yimatouzi    时间: 2017-10-22 20:57:11

cf_55390 发表于 2017-10-22 18:40
这个可能是Highest,Lowest底层封装的机制问题,写在外面是每个BAR执行一遍(历史回测)在条件T=0.1000里是 ...

第二个是  每根K先运算了一遍,然后再满足条件 time==0.1000 然后取到了
正确的最高最低价。  

第一个是  时间满足了 time==0,而做的 highest 与lowest 却只计算了当前的K线。前面的59根K线都没能通过这个函数计算得到。

现象是如此,底层的东西不清楚

作者: cf_55390    时间: 2017-10-23 23:50:31

If(Time>0.233700)
{
High10=Highest(high,59);
Low10=Lowest(low,59);
SetGlobalVar(0,High10);
SetGlobalVar(1,Low10);

PlotNumeric("aa",high10,0,-1,0);
PlotNumeric("bb",low10,0,-1,0);
}
PlotString("H10",text(high10),h,-1,0);
PlotString("L10",text(low10),l,-1,0));
这样写盘中能取到0.233700之后的最高,最低值
If(Vol>0)
{
High10=Highest(high,59);
Low10=Lowest(low,59);
SetGlobalVar(0,High10);
SetGlobalVar(1,Low10);

PlotNumeric("aa",high10,0,-1,0);
PlotNumeric("bb",low10,0,-1,0);
}
PlotString("H10",text(high10),h,-1,0);
PlotString("L10",text(low10),l,-1,0);
这样写在盘中能取到正确值。






欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/) Powered by Discuz! X2