Extracting 5 minute candle value from Daily periodicity

Hi Seniors,

I have written an exploration to find next day's pivot range with 'Periodicity' set to 'Daily'. On the very same exploration, I want to fetch the values of today's Open, High, Low, Close (OHLC) on the last bar created on 5 minute timeframe. But I am getting blank result.

Here's what I have done.

periodicityCheck = True;

if( periodicityCheck )
{
    if( Status( "action" ) == actionScan OR Status( "action" ) == actionExplore OR Status( "action" ) == actionBacktest )
    {
        if( NOT Interval() == inDaily ) Error( "Automatic Analysis 'Periodicity' - Must be set to 'DAILY'!" );
    }
}

// Pivot calculation for next day on Daily periodicity
Hi = TimeFrameGetPrice( "H", inDaily, 0 );
Lo = TimeFrameGetPrice( "L", inDaily, 0 );
Cl = TimeFrameGetPrice( "C", inDaily, 0 );
pivot = Prec( ( ( Hi + Lo + Cl ) / 3 ), 2 );

// OHLC calculation for today on 5 minute periodicity on last bar
TimeFrameSet( in5Minute );

tn = TimeNum();
StartTime = 152500;
Endtime = 152959;
StartBar = tn == StartTime;
EndBar = tn == Endtime;
bi = BarIndex();
dn = Day();
firstB = dn != Ref( dn, -1 );
bars = BarsSince( firstB );
lastB = bars == 74;

// Today's Last Candle (5min) OHLC
lastB_Op = ValueWhen( lastB, O );
lastB_Hi = ValueWhen( lastB, H );
lastB_Lo = ValueWhen( lastB, L );
lastB_Cl = ValueWhen( lastB, C );

Parameters = ( tn >= StartTime AND tn <= Endtime );

TimeFrameRestore();

Filter = 1;
SetOption( "NoDefaultColumns", True );
AddTextColumn( Name(), "Name", 1, colorDefault, 2, 93 );
AddTextColumn( DateTimeFormat( "%d-%b-%Y", LastValue( DateTime() ) ) , "Date", 1, colorDefault, 2, 82 );
AddColumn( pivot, "Pivot", 1.2, colorDefault, 2, 59 );

Filter = ( tn >= StartTime AND tn <= Endtime );
AddColumn( lastB_Op, "Today L5mB Op", 1.2, colorDefault, 2, 76 );
AddColumn( lastB_Hi, "Today L5mB Hi", 1.2, colorDefault, 2, 72 );
AddColumn( lastB_Lo, "Today L5mB Lo", 1.2, colorDefault, 2, 73 );
AddColumn( lastB_Cl, "Today L5mB Cl", 1.2, colorDefault, 2, 71 );
SetSortColumns( 1 );

P.S - The exchange working time is from 091500 to 153000

It would be very helpful for me if anyone can guide me where I am doing wrong!

AmiBroker can't look into a lower timeframe than the Periodicity setting, so you can't look at a 5-minute bar if the Periodicity is set to Daily.

You could set Periodicity to 5 minutes and then change the rest of your code to look into the higher Daily timeframe.

3 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.