如何在图中快速回到历史数据中的某个时间?

Discussion in 'AmiBroker' started by espresso, Jun 7, 2009.

  1. 如题,比如在日线上,我想快速回到 2005年10月11日 那一天的位置上,有什么比较快的方法?比如输入“20051011”就可以,像MT4那样。我现在每次都只有按前后方向按钮,或者使用鼠标滚轮,很不方便啊。

    或者需要用AFL实现???

    多谢各位~
     
  2. amibroker的k线图的下面不是有一个“水平滚动条”的吗?用鼠标一拉滚动下就行了吧?
     
  3. thanks! wj2000
    不过,滚动条有点麻烦,而且不能很精确地回到某个时间。
    MT4里面,按“enter”之后,会出现一个小框,可直接输入date/time,很方便。
    有点像word里面,ctrl+G之后,你可以输入到第几页一样。
     
  4. 回答我自己一年以前问的问题。:)
    我一直都希望AB能有这么一个功能,这样可以很方便地回到任何时刻的bar上面。这个周末终于花时间写了一个。很好用,哈哈!

    把代码保存到一个文件中,取名为 GotoDate.afl,作为一个指标装到你的图上。然后输入日期,比如“5/2/2009”,按下面的按钮即可。输入时间也可以,但是要符合AB图里面左上角显示的日期格式,比如“5/2/2009 12:05:00 am”。

    日期的比较采用比较简单的字串比较,程序会在第一个匹配的日期上停止然后显示。所以,你输入“5/2/2009 12:05”,会找到"5/2/2009 12:05:00 am"这个bar,如果你要找下午的那个bar,就必须更精确的输入"5/2/2009 12:05:00 pm"。

    你指定的bar被定位在图形区域的正中央,你可以多按1,2次那个按钮,会看到两个黄色的三角形闪烁,这样可以很方便地定位这个bar。

    等我有空把它放到Amibroker AFL Library里面去.......

    Code:
    _SECTION_BEGIN("GotoDate_v1.1");
    /* GotoDate v1.1 - Go to specific bar with specified date (and time)
     *
     * How to use: 
     *    *) Load it as an indicator.
     *    *) Simply enter a date "m/d/yyyy" and click the button, 
     *       it will swtich the view to the first bar of that day.
     *    *) You can also enter exact date/time and switch to specifc bar,
     *       such as "8/18/2005 5:25:00 pm", refer to the date/time displayed in AB for reference.
     *    *) You will see a pair of triangles highlighted on the exact 
     *       bar when you press the button
     *
     * v1.1 change (Sept/27/2010)
     *    fix a bug that the EndZoom goes beyond the latest bar, need the cap the max bar index
     *
     */
    
    sDateStr = ParamStr("Goto [m/d/yyyy h:mm:00 am]", "");
    bGoNow = ParamTrigger("Click Button to Go", "Click Here");
            
    // require all bars, otherwise the index will not be correct
    SetBarsRequired(-2, -2);
    
    procedure ZoomChart(BeginZoom, EndZoom) {
        AB = CreateObject( "Broker.Application" );
        AW = AB.ActiveWindow;
        AW.ZoomToRange( BeginZoom, EndZoom);
    }
    
    if(bGoNow AND StrLen(sDateStr) > 0) {
    
        // Retrieve current indexes for visible bars
        FirstBarIndex = Status( "firstvisiblebarindex" );
        LastBarIndex = Status( "lastvisiblebarindex" );
    
        nHalfScrRange = round( abs(LastBarIndex - FirstBarIndex) / 2);
    
        DT = DateTime();
        
        sDateStr = StrToUpper(sDateStr);
        TargetMidBarIndex = 0;
        for(i = 1; i < BarCount; i++) {
            if (StrFind(DateTimeToStr(DT[i]), sDateStr) > 0) {
                TargetMidBarIndex = i;
                break;
            }
        }
        
        if(TargetMidBarIndex > 0) {
            // cap the bar index if it goes beyond BarCount
            if (TargetMidBarIndex + nHalfScrRange > BarCount) {
                BeginZoom = DateTimeToStr(DT[BarCount - 1 - nHalfScrRange * 2]);
                EndZoom = DateTimeToStr(DT[BarCount - 1]);
            }
            else {
                BeginZoom = DateTimeToStr(DT[TargetMidBarIndex - nHalfScrRange]);
                EndZoom = DateTimeToStr(DT[TargetMidBarIndex + nHalfScrRange]);
            }
            
            // zoom to specified range
            ZoomChart(BeginZoom, EndZoom);
    
            // draw up/down triangle to highlight the identified bar
            shapeArr[TargetMidBarIndex] = shapeUpTriangle;
            PlotShapes(shapeArr, colorYellow, 0, Low[TargetMidBarIndex], -12); 
            shapeArr[TargetMidBarIndex] = shapeDownTriangle;
            PlotShapes(shapeArr, colorYellow, 0, High[TargetMidBarIndex], -12); 
        }
        
    }
    _SECTION_END();
    
    
     
  5. 贴个图:

    [​IMG]
     
  6. 不错,赞一个。

    另外请教一下老大,用盈透的数据,浏览一组品种,有没有出现后台品种数据没有及时加载到本机的情况?

    我现在浏览一组里面的多个外汇行情,只有在屏幕上面显示的品种,数据和计算机时间一样,切换到其他品种,发现其他品种的数据没有下载下来,也就是最后的数据时间和实时差一些,需要点击右下角conn里面的reconnect。

    谢谢
     
  7. 你这个问题我遇到过,后来问过AB的技术支持,下面是回复。大致就是说你要让AB知道那些品种是需要接收实时数据的,把这些品种都加到real-time quote window里面,然后把所有品种都点一遍使其显示一下,或者就运行一个最简单的scan,把这些品种扫描一遍。


    Tuesday, May 26, 2009
    11:33 AM

    Hello,

    In order to make sure that all symbols get refreshed - please add them ALL to the realtime quote window. Then - at the beginning of your work - access all of the symbols somehow (either display a chart or perhaps run a SCAN or EXPLORATION over all symbols). That will add them to the plugin streaming list and all the quotes will be updated even if you don't display the chart all the time).

    Then - before you close the program - you can also re-run the scan or display chart for each symbol (so collected data will be read from the plugin).

    Best regards

    Marcin Gorzynski
    Amibroker.com Technical Support
     
  8. 但是,我现在都没有把品种添加到real-time window里面,只是运行scan或者exploration,这样似乎也可以。
     
  9. 非常感谢
     
  10. 好东西,谢谢分享。
     
  11. 你用IB看外汇并馈入AB数据? 历史数据回补如何解决?
     
  12. 这个问题正想问espresso兄 :
    1、通过real-time window,可以下载实时数据了,但是一组品种里面,有的会自动下载历史数据,有的不会。右键点击conn,backfill current和backfill ALL RT 都不行,提示的原因都不是:最新版、真实帐户等,重新点击Recurrent,可以下载,但是只是显示的一个品种,其他有的品种历史数据仍然没有。请问espresso兄 如何解决的?

    2、 espresso兄 现在用哪个数据源,价格如何?

    3、espresso兄 开发的自动交易软件卖不卖呀?海洋也发起一个团购吧,呵呵
     
  13. 回复Stanwell, yfbook二兄,我没有使用IB作为数据源,所以也没有backfill的烦恼。 ;)
    可以参考一下这个链接,很详细地介绍了如何从MT4获得历史数据。

    求助!如何导入MT4的DDE数据?
    http://www.hylt.net/vb/showthread.php?t=28910

    不过正如cat老兄在那里感叹的,如果只是做外汇的话,似乎在MT4里面上手比较快。因为用AB存在一个历史数据要手工导入的过程。MT4则没有这个问题。

    至于回测的话,把数据导入AB之后,在AB里面做还是比较高效的。
     
  14. 这个..... 目前还没有考虑过出售的问题,虽然我的系统还是有一点强大的 :D
     
  15. 你好,COPY了上面的代码,程序无报错,但填好日期后,点"click here",无任何反应,已试过多种方法,都没看到指示或切换到那一日。
    另外,amibroker的Restore Last Used Range,关闭程序后,再打开总是停在最前面的一日,而非关闭程序时的那个日子。无论分钟线还是日线都这样。
     
  16. woodark,我的那个程序是简单比较日期,所以你要看一下你的AB图形左上角显示的日期格式,计算机的设置不同,日期格式不同,比如我的是"9/29/2010 3:25:00 PM"这样子的,你的也许是"09-29-2010 03:25:00 PM",所以你填的日期必须和这个格式一致。

    amibroker的Restore Last Used Range,没有用过,参考了一下它的代码。还是我自己这个比较灵活 ;)
     
  17. 确实是时间设置的问题,你的这个AFL非常实用
     
  18. 最近发现这个指标有一个问题,那就是如果我打开多个AMIBROKEr,那么只有第一次打开那个该AFL才有效。后面打开的都没有用。
    AB = CreateObject("Broker.Application");
    AW = AB.ActiveWindow;(应该是这条语句的原因,但哪位知道怎么改吗?)
    AW.ZoomToRange( FirstDateTimestr, LastDateTimestr );