問一個高手都很難解的問題(如何提高afl解碼速度?)

Discussion in 'AmiBroker' started by BjJPfahxYv, Jan 11, 2014.

  1. 如果有一個afl程式碼有1萬行

    每一秒進一個tick,這1萬行程式碼都會重新run一次

    如何用時間去讓部分程式碼只跑一次提高afl解碼速度?

    例如

    a=0;
    if(開盤時間=="1")
    {
    a=1+2+..................................................................;
    }

    b=a+1;

    (不過這個例子回測結果是失敗的, 還會產生未來訊號)
     
  2. 这个你要去问问TJ,他会很生气,一定会问你:
    为什么要让每个tick都去触发他超快的AFL,为什么?为什么? :D
    为什么每秒只能进一个tick,而不是3个tick,为什么?为什么? :D
    如果你买了正版的话,难说他会退你钱的。 :D
     
  3. 呵呵!
     
  4. AB 記憶中無論是EXPLORER 或 INDICATOR 沒有BY TICK觸發,最快是每秒觸發一次。 而在我實際應用中,策略和執行代碼是分開的,但是加起来最多也就幾十行,應該沒人過百。網上有許多公開的代碼,最多也就幾十行。如果是一萬行,不可想象。
     
  5. 這是 TJ 搞的
    我看這個AddToComposite 根本不能用



    On May 11, 2007, at 1:26 PM, Tomasz Janeczko wrote:

    Hello,

    Then my advice is to use AddToComposite for computing intensive
    task.

    lasttimenum = StaticVarGet("lasttimenum"); // if you want it chart-
    specific you may add GetChartID() prefix/suffix

    if( ( Now( 4 ) - lasttimenum ) > 100 )
    {
    // one minute passed sincce last recalc

    .... // do computing intesive stuff here
    result = .. .put your result array here

    AddToComposite( result, "~myresult", "x", atcFlagEnableInIndicator | atcDefaults );
    }

    // regular part that is executed all the time
    result = Foreign("~myresult", "c" ); // this will retrieve values
    of computing-intensive part calculated last time


    Best regards,
    Tomasz Janeczko
    amibroker.com
     
  6. Code:
    /*
    from the help file:
    
    "lastbartimeleft" - returns number of seconds to the completion of current last bar. 
    Works for time-based bars only. Note that for proper operation this requires database 
    timeshift to be set properly (so dates displayed on chart match your local computer time zone). (v5.60)
     
    "lastbartimeleftrt" - it works like "lastbartimeleft" but uses the most recent RT stream update time instead of Now(). 
    Also added Status("lastrtupdate") - time of last RT stream update Depends on RT plugin to deliver correct DateUpdate / TimeUpdate data. 
    If plugin or date source sends incorrect datetimestamps or does not send DateUpdate/TimeUpdate correctly this function will not operate properly. 
    Note that most data sources send weird (not current) datetime stamps on weekends. 
    Also IQFeed plugin sends DateUpdate/TimeUpdate only inside regular trading hours. (v5.60)
    */
    
    Current = Now ( 4 );
    Hours = int ( Current / 10000 );
    Minutes = int ( ( Current - Hours * 10000 ) / 100 );
    Seconds = Current - Hours * 10000 - Minutes * 100;
    totalSeconds = Hours * 60 ^ 2 + Minutes * 60 + Seconds;
    Left =  Interval() - totalseconds % Interval();//Status( "lastbartimeleft" ); //Status( "lastbartimeleftrt" );
    
    execute = StaticVarGet ( "execute" ); // if you want it chart-specific you may add GetChartID () prefix / suffix 
    
    if ( Interval() - Left == 0 )
    {
        if ( execute )
        {
    // put calculations here and store result in a static variable
            StaticVarSet( "myvariable", MA( C, 20 ) );
            StaticVarSet ( "execute", 0 );
            SetChartBkGradientFill( colorYellow, colorYellow );
        }
    }
    else
        StaticVarSet ( "execute", 1 );
    
    Title = StrFormat( "Time left: %g", left );
    Plot( StaticVarGet( "myvariable" ), "Yourindicator", colorRed );
    
    
     
  7. Code:
    elapsed  = GetPerformanceCounter() - Nz( StaticVarGet( "start" ) );
    if ( elapsed / 1000 > 5 /*every five seconds*/ )
    {
    // put calculations here and store result in a static variable
        StaticVarSet( "myvariable", MA( C, 20 ) );
        StaticVarSet ( "start", GetPerformanceCounter( 1 ) );
        SetChartBkGradientFill( colorYellow, colorYellow );
    }
    
    Plot( StaticVarGet( "myvariable" ), "Yourindicator", colorRed );
     
  8. Code:
    time = GetPerformanceCounter();
    time = int( time / 1000 );
     
    trigger = time % 10 == 0; // 10 seconds interval
     
    if ( trigger)
    {
        SetChartBkGradientFill( colorYellow, colorYellow );
        StaticVarSet( "last time", time );
    }
     
    RequestTimedRefresh(1);
    Title = "Seconds: " + (time - Nz( StaticVarGet( "last time") ) );