当前位置 博文首页 > 文章内容

    量化投资_EasyLanguage/PowerLanguage教学课程__【第二篇专题】__【第十章bar内模式与非bar内模式】

    作者: 栏目:未分类 时间:2020-09-23 14:00:01

    本站于2023年9月4日。收到“大连君*****咨询有限公司”通知
    说我们IIS7站长博客,有一篇博文用了他们的图片。
    要求我们给他们一张图片6000元。要不然法院告我们

    为避免不必要的麻烦,IIS7站长博客,全站内容图片下架、并积极应诉
    博文内容全部不再显示,请需要相关资讯的站长朋友到必应搜索。谢谢!

    另祝:版权碰瓷诈骗团伙,早日弃暗投明。

    相关新闻:借版权之名、行诈骗之实,周某因犯诈骗罪被判处有期徒刑十一年六个月

    叹!百花齐放的时代,渐行渐远!



    第十章:bar内模式与非bar内模式

    1、MC对于bar的运行模式区分bar内模式与非bar内模式两种,区分这两种模式主要是为了(本人认为)是为了加速代码的运算速度。

     

    2、可以根据信号设置开启bar内模式,也可以在代码上方写入[IntrabarOrderGeneration=True],表示开启bar内

     

     3、回测时:

      不开始bar内交易:每根K线收盘,计算一次

      开启bar内交易:根据精细资料的选择作为计算周期

      【精细资料】

     

     

    4、实时:

      不开始bar内交易:每根K线收盘(收到收盘tick时),计算一次

      开启bar内交易:每逢新tick计算一次

     

    5、图示:

     

     

    6、开始bar内和不开启bar内,barStatus的异同

      开启bar内:

    //历史行情读取时
    time= 1309.00 barstatus= 2.00 time= 1309.00 barstatus= 0.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1309.00 barstatus= 1.00 time= 1310.00 barstatus= 2.00

    //实时数据时

    time= 1311.00 barstatus= 2.00
    time= 1312.00 barstatus= 0.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00
    time= 1312.00 barstatus= 1.00

    time= 1312.00 barstatus= 2.00

     

      不开始bar内:

    time= 1301.00 barstatus=    2.00
    time= 1302.00 barstatus=    2.00
    time= 1303.00 barstatus=    2.00
    time= 1304.00 barstatus=    2.00
    time= 1305.00 barstatus=    2.00
    time= 1306.00 barstatus=    2.00
    time= 1307.00 barstatus=    2.00
    time= 1308.00 barstatus=    2.00
    time= 1309.00 barstatus=    2.00

     

    【总结】:

      在开启bar时,读取历史行情的情况下是基于精细数据而言,因此在开始的第一个状态会保证读取的是收盘tick,然后再用开盘tick覆盖掉,所以显示了2后再显示0,实时数据保持一致。

      在不开始bar时,数据是在bar结束时更新一次。

     

    7、bar内模式和非bar内模式,bar数据取值的不同点

      非bar内模式下:

        根据bar的合成规则:当新的一笔tick来临,如果触发bar的完成,此时在bar的最后一个tick会计算一次,形成收盘价,此时新来的这一笔tick就叫做下一个bar的开盘tick。

        【举例】:

         第一步: 【上一个未完成的bar】 ----(新tick来临)-----(促成上一个bar完成)---- 【形成上一个bar的收盘价】 + 【形成下一个bar的开盘价】

         第二步:  (新tick来临) = (开盘tick)【下一个bar的】

         第三步:    【旧bar形成】←←←close[1]/open[1]/high[1]/low[1]... 瞬间完成...open of next bar  →→→  【新bar开始】

      【总结】

          在第三步的瞬间完成,我们发现此时可以取到两类值:    

                        第一类:旧bar的开高低收的值

                        第二类:新bar的开盘价

          因此,这就解释了在非bar内模式下,为什么我们下单可以下“buy 1 shares Next bar at open of Next bar”,此时“open of Next bar”等于右侧箭头的那一瞬间完成的新bar开盘价。

          在一种解释是,我们发现当前正在形成的这根bar上面显示的市价和本地时间不一致:

          

     

           如图所示,bar上面的实现显示是36分钟,而电脑bar显示的时间是35分钟,而我们在这个bar结束时,打印的是35分钟    

          

     

           这就解释了,在MC机制下,bar上的时间总是提前是因为当前的的这个时间是准备要完成的时间,而不是完成后的时间。直白说就是当一个新开盘tick来临时,等待这个bar的时间结束行程旧bar时的那一刻打印数据,此时已经完成了。

          也就是在交易代码中:

          if XXX > XXX then....

          这样就可以不用采用回溯的方式,在上面所说的“瞬时完成”的那一刻,旧的时间已经完成了,此时已是过去式,新的价格来的,此时是正在进行时。因此不用回溯。

          MC的这种机制和其他软件的不太一样。其他的软件都是等bar形式后,才公布此时形成的时间,而MC是新的tick来临时,按照这个规定的时间来完成tick。一个是过去完成时,一个是将来完成时。

     

      bar内模式:

        bar内模式的取值方式是非常不一样的。正如前面所说的,在非bar内模式下,在“瞬时完成”,这一刻会取到旧bar的开高低收价格和新bar的开盘价。因为MC对于非bar模式具有这样一种计算模式。但是bar内模式是每根tick都进行计算,因此不存在这种计算模式。因此不能取“open of next bar”这样的数值。而且从上面可以看到,在非bar内模式下,打印的是“顺势完成”这个时刻打印,而且打印的是上一个时间的值,但是bar内模式下是实时打印,打印的是当前时刻的值。

     

     

    =================================================

    之前的文章感谢大家的转载,希望转载时请注明出处,本人转自其它网站的图表一并感谢,谢谢~!

    https://www.cnblogs.com/noah0532/