Timeframe用法请教 !!!

Discussion in 'AmiBroker' started by domino2013, Aug 26, 2014.

  1. 想做如下操作 :
    基于日图 ,先在周中进行K线的处理,然后将处理后的K线在日周期中使用。
    现在第一步就发现在周中barcount是等于日周期的,在TimeFrameSet( inWeekly )中 ,barcount=4027,TimeFrameRestore()后也是4027,且在inWeekly 中 TFOpen数组前面均为空值,从3829才开始有数值。
    对timeframe的操作还是没有理解透彻,是否TimeFrameSet( inWeekly )中,TFOpen的长度=Open长度,但把日周期的Open值转换成周的后放入了TFOpen后部数组?
    请高手指点一下,谢谢!

    TimeFrameSet( inWeekly );
    MA14_Weekly = MA( Close, 14 );
    TFOpen = Open;
    TFBarIndex = BarCount;

    for ( i = 0;i < TFBarIndex ;i++ )
    {
    if ( !IsNull( TFOpen ) )
    _TRACE( "i=" + i + " TFOpen=" + TFOpen );
    }

    _TRACE( "AA Interval()=" + Interval() + " TFBarIndex=" + TFBarIndex );

    TimeFrameRestore();

    TFOpen = TimeFrameExpand( TFOpen, inWeekly );
    TFBarIndex = TimeFrameExpand( TFBarIndex, inWeekly );

    _TRACE( "BB Interval()=" + Interval() + " TFBarIndex=" + TFBarIndex );

    输出:
    ......................
    i=4024 TFOpen=1.3355 C:\Program Files (x86)\AmiBroker5.5 - Hour\Formulas\Custom\TimeFrame-Test-6.afl 9 51 10:28:23.70
    i=4025 TFOpen=1.3491 C:\Program Files (x86)\AmiBroker5.5 - Hour\Formulas\Custom\TimeFrame-Test-6.afl 9 51 10:28:23.70
    i=4026 TFOpen=1.3552 C:\Program Files (x86)\AmiBroker5.5 - Hour\Formulas\Custom\TimeFrame-Test-6.afl 9 51 10:28:23.70

    AA Interval()=432001 TFBarIndex=4027
    BB Interval()=86400 TFBarIndex=4027
     
  2. 文档还是得仔细看,找到说明了:

    How does it work internally ?

    Time-frame functions do not change the BarCount - they just squeeze the arrays so you have first N-bars filled with NULL values and then - last part of the array contains the actual time-compressed values. This is why it is essential to expand the data back to the original frame with TimeFrameExpand. The following simple exploration shows what happens after you switch to a higher timeframe. Run Exploration on current symbol, all quotations, periodicity set to daily and you will see how "weekly close compressed" column contains empty values at the beginning and weekly compressed data at the end of array.
     
  3. amibroker下单接口的问题

    amibroker下单接口如何做 大家有弄的没?
     



  4. Code:
    SetBarsRequired (100000, 0);
    
    function myloop( array )
    {    
        StartBar = LastValue( ValueWhen( IsNull( array ), Cum( 1 ) ) );
        _TRACE("Startbar = " + StartBar );
    
    	myresult = Null;
        for ( i = StartBar;i < Barcount;i++ )
        {
            myresult[i] = array[i];
            _TRACE( "i=" + i + " TFOpen=" + myresult[i] );         
        } 
        
        return myresult;
    }
    
    tf = inWeekly;
    TimeFrameSet( tf );
    MA14_Weekly = MA( Close, 14 );
     
    test = myloop( Open ); 
    TimeFrameRestore();
    
    TFOpen = TimeFrameExpand( test, tf, expandfirst );
    
    Plot( TFOpen, "Open", colorDefault, styleLine );
     
  5. Code:
    //  https://finance.groups.yahoo.com/group/amibroker/message/176884
    // from Ehlers, John F. Cybernetic Analysis for Stocks and Futures. Wiley.2004.
    // Chapter 14, p. 213. Code on p. 221.
    
    // user example fixed by Tomasz Janeczko
    SetBarsRequired (100000, 0);
    
    function LRSI( array, gamma )
    {
        L0 = array;  // Initialize as array
        L1 = array;
        L2 = array;
        L3 = array;
    
        // need to initalize LRSIValue variable with Null
        // otherwise you are just copying Close array to it.
        LRSIValue = Null;
    
        StartBar = LastValue( ValueWhen( IsNull( array ), Cum( 1 ) ) );
        //_TRACE("Startbar LRSI = " + StartBar );
    
        for ( i = StartBar + 1; i < BarCount; i++ )
        {
            L0[i] = ( 1 - gamma ) * array[i] + gamma * L0[i-1];
            L1[i] = - gamma * L0[i] + L0[i-1] + gamma * L1[i-1];
            L2[i] = - gamma * L1[i] + L1[i-1] + gamma * L2[i-1];
            L3[i] = - gamma * L2[i] + L2[i-1] + gamma * L3[i-1];
    
            CU = 0;
            CD = 0;
    
            if ( L0[i] >= L1[i] )
                CU = L0[i] - L1[i];
            else
                CD = L1[i] - L0[i];
    
            if ( L1[i] >= L2[i] )
                CU = CU + L1[i] - L2[i];
            else
                CD = CD + L2[i] - L1[i];
    
            if ( L2[i] >= L3[i] )
                CU = CU + L2[i] - L3[i];
            else
                CD = CD + L3[i] - L2[i];
    
            if ( CU + CD != 0 )
                LRSIValue[i] = CU / ( CU + CD );
        }
    
        return LRSIValue;
    }
    
    
    tmfrm = 60 * Param( "Choose TimeFrame (minutes)", 60, 1, 1440, 1 );
    
    TimeFrameSet( tmfrm );
    RSIout = LRSI( Close, 0.5 );
    TimeFrameRestore();
    
    RSIout = TimeFrameExpand( RSIout, tmfrm, expandFirst );
    Plot( RSIout, "LRSI", colorRed, styleLine );
     
  6. 谢谢trash!