Intraday value Timeframe

Hello Friends,

first of all, sorry for the my poor English.

i have one doubt for timeframe in in1Second & inDaily @ intraday, which both timeframe need to use together. but i try code OHLC value, not showing.

i need 3 value OHLC

  1. Yesterday OHLC value
  2. today our market open time 91500, need OHLC value.
  3. starttime 91500 to endtime 93000 value OHLC.

see the below screenshot.Untitled

SetBarsRequired( sbrAll, sbrAll );
TimeFrameMode(1);
TimeFrameSet(inDaily);
inO = TimeFrameGetPrice( "O", inDaily, -1 );
inH = TimeFrameGetPrice( "H", inDaily, -1 );
inL = TimeFrameGetPrice( "L", inDaily, -1 );
inC = TimeFrameGetPrice( "C", inDaily, -1 );
for( i = 1; i < BarCount ; i++ ) 
{ 
	LastO[i] = inO[i];
	LastH[i] = inH[i];
	LastL[i] = inL[i];
	LastC[i] = inC[i];		
	range[i] = LastH[i] - LastL[i];
}

TimeFrameRestore();
POpen = TimeFrameExpand( TimeFrameCompress( LastO, inDaily, compressOpen), inDaily, expandFirst);
PHigh = TimeFrameExpand( TimeFrameCompress( LastH, inDaily, compressHigh), inDaily, expandFirst);
PLow = TimeFrameExpand( TimeFrameCompress( LastL, inDaily, compressLow), inDaily, expandFirst);
PClose = TimeFrameExpand( TimeFrameCompress( LastC, inDaily, compressLast), inDaily, expandFirst);
PRange = TimeFrameExpand( TimeFrameCompress( range, inDaily, compressLast), inDaily, expandFirst);

TimeFrameMode(1);
TimeFrameSet( in1Second );

NewDay = Day() != Ref(Day(),-1);
BT1 = 91500;	//BT = Param("BreakoutTime",93000,09000,120000);

HighValue=HighestSince(newDay AND BT1,H);
LowValue=LowestSince(newDay AND BT1,L);

// 9:15am Value 

DayO=ValueWhen(NewDay,O);//Todays Open
DayH=ValueWhen(NewDay,H);//Todays opening Hign
DayL=ValueWhen(NewDay,L);//Todays opening Low
DayC=ValueWhen(NewDay,C);//Todays opening CLOSE

TimeFrameRestore();

// 9:15am Value 
PreOpen = TimeFrameExpand( TimeFrameCompress(DayO,in1Second,compressOpen), in1Second,expandFirst);  
PreHigh = TimeFrameExpand( TimeFrameCompress(DayH,in1Second,compressHigh), in1Second,expandLast); 
PreLow = TimeFrameExpand( TimeFrameCompress(DayL,in1Second,compressLow), in1Second,expandLast);
PreClose = TimeFrameExpand( TimeFrameCompress(DayC,in1Second,compressLast), in1Second,expandLast); 

textsize = Param("TextSize",9,6,20,1,0);
GfxSetOverlayMode(0);
GfxSelectFont("Trebuchet MS",textsize, 700);
GfxSetBkMode(0); // transparent
GfxSetTextAlign(0);

GfxSetTextColor( colorCustom16 );

GfxTextOut("High", 90, 12);
GfxTextOut("Low" , 150, 12);
GfxTextOut("Close", 210, 12);

GfxTextOut("Yesterday ", 0, 25);
GfxTextOut("Rate@9:15AM ", 0, 40);
GfxTextOut("Rate@9:30AM ", 0, 55);

GfxSetTextColor( colorblue );
GfxTextOut("" + PHigh, 85, 25);
GfxTextOut("" + PLow, 145, 25);
GfxTextOut("" + PClose, 205, 25);

GfxTextOut(""+PreHigh, 85, 40);
GfxTextOut(""+PreLow, 145, 40);
GfxTextOut(""+PreClose, 205, 40);

Your loop is pointless. Remove it.

You said 1-second and daily... but your chart is showing 1-minute.
If you need 1-second then set to 1-second interval in interval selector.
If you want to get 1-second on 1-minute or other compressed intervals being longer than 1-second then create 2nd chart with 1-second interval and store required 1-sec data there via StaticVarSet() and call it elsewhere such as in 1-min chart via StaticVarGet(). You can not look from longer interval to shorter interval via TimeFrame functions but just vice versa.

https://www.amibroker.com/guide/h_timeframe.html
https://www.amibroker.com/guide/afl/timeframeset.html

Please note that you can only compress data from shorter interval to longer interval. So when working with 1-minute data you can compress to 2, 3, 4, 5, 6, ....N-minute data. But when working with 15 minute data you can not get 1-minute data bars. In a similar way if you have only EOD data you can not access intraday time frames.

But if instead of 1-second you really mean 1-minute (as your chart indicates) and want to access daily TF data there then just use this one.

daysback = 1;
SetBarsRequired(daysback*inDaily/Max(1,Interval()));

LastO = TimeFrameGetPrice( "O", inDaily, -1 );
LastH = TimeFrameGetPrice( "H", inDaily, -1 );
LastL = TimeFrameGetPrice( "L", inDaily, -1 );
LastC = TimeFrameGetPrice( "C", inDaily, -1 );
range = LastH-LastL;

range_value = SelectedValue(range);// not an array but single value

tn = TimeNum();
dd = Day();
NewDay = dd != Ref(dd,-1);
BT1 = tn == 91500;	//BT = Param("BreakoutTime",93000,09000,120000);

HighValue=HighestSince(newDay /*AND BT1*/,H);
LowValue=LowestSince(newDay /*AND BT1*/,L);

// 9:15am array of selected(!) Interval (e.g. selected in Chart's interval selector)
DayO=ValueWhen(NewDay,O);//Todays Open
DayH=ValueWhen(NewDay,H);//Todays opening Hign
DayL=ValueWhen(NewDay,L);//Todays opening Low
DayC=ValueWhen(NewDay,C);//Todays opening CLOSE


textsize = Param("TextSize",9,6,20,1,0);
GfxSetOverlayMode(0);
GfxSelectFont("Trebuchet MS",textsize, 700);
GfxSetBkMode(0); // transparent
GfxSetTextAlign(0);

GfxSetTextColor( colorCustom16 );

GfxTextOut("High", 90, 12);
GfxTextOut("Low" , 150, 12);
GfxTextOut("Close", 210, 12);

GfxTextOut("Yesterday ", 0, 25);
GfxTextOut("Rate@9:15AM ", 0, 40);
GfxTextOut("Rate@9:30AM ", 0, 55);

GfxSetTextColor( colorblue );
GfxTextOut("" + SelectedValue(LastH), 85, 25);
GfxTextOut("" + SelectedValue(LastL), 145, 25);
GfxTextOut("" + SelectedValue(LastC), 205, 25);

GfxTextOut(""+SelectedValue(DayH), 85, 40);
GfxTextOut(""+SelectedValue(DayL), 145, 40);
GfxTextOut(""+SelectedValue(DayC), 205, 40);


BTW, as for this one in your original code

dd = Day();
NewDay = dd != Ref(dd,-1);
BT1 = 91500;

HighValue=HighestSince(newDay AND BT1,H);
LowValue=LowestSince(newDay AND BT1,L);

BT1 is not a true/false array but just a time value. Highest/Lowestsince expect true/false array in 1st arguments.

tn = TimeNum();
dd = Day();

NewDay = dd != Ref(dd,-1);

BT1 = tn == 91500;

HighValue=HighestSince(newDay AND BT1,H);
LowValue=LowestSince(newDay AND BT1,L);

But then why newday and BT1 if market open is at 091500 anyway and you being looking for market open?

So just use newDay only.

dd = Day();
NewDay = dd != Ref(dd,-1);

HighValue=HighestSince(newDay,H);
LowValue=LowestSince(newDay,L);

// code for Intervals such as 1-sec or 1-minute
// 3. starttime 91500 to endtime 93000 value OHLC.
// getting OHLC of 15-min bar in shorter intervals
O15 = TimeFrameGetPrice( "O", in15Minute );
H15 = TimeFrameGetPrice( "H", in15Minute );
L15 = TimeFrameGetPrice( "L", in15Minute );
C15 = TimeFrameGetPrice( "C", in15Minute );

FirstO15 = ValueWhen(newday, O15);// or ValueWhen(NewDay,O);
FirstH15 = ValueWhen(newday, H15);
FirstL15 = ValueWhen(newday, L15);
FirstC15 = ValueWhen(newday, C15);
6 Likes

first of all thanks for feedback.

Please note that you can only compress data from shorter interval to longer interval . So when working with 1-minute data you can compress to 2, 3, 4, 5, 6, ....N-minute data. But when working with 15 minute data you can not get 1-minute data bars. In a similar way if you have only EOD data you can not access intraday time frames.

noted only compress data from shorter interval to longer interval.

so EOD, that means yesterday (inDaily) data can not get 1-minute data bars. so below code compress data from shorter interval to longer interval. super. i understood.:+1:

SetBarsRequired(daysback*inDaily/Max(1,Interval()));

once compress data from TimeFrameGetPrice. but how can stored compress data an array not single value. because i need to take compare daily data calculate previous daily data through "for" statement. for example

Pre_Value[ 1 ] = LastC [ 1 ];
for( i = 2; i < BarCount ; i++ )
{ 	
	prevMSF = Pre_Value[ i-1 ]; 
	MSF[ i ] =  round( int((( LastC [ i ] - Pre_Value)* 0.33 + Pre_Value) * 100 )/ 5 ) * 0.05;
}

i got result Pre_Value "0". where i am mistake. please advise

But then why newday and BT1 if market open is at 091500 anyway and you being looking for market open?

i am looking for market open value. you are correct. i will use this code

dd = Day();
NewDay = dd != Ref(dd,-1);

HighValue=HighestSince(newDay,H);
LowValue=LowestSince(newDay,L);

No, that line does not compress data but it does set required bars.
https://www.amibroker.com/guide/afl/setbarsrequired.html
https://www.amibroker.com/kb/2008/07/03/quickafl/

As for loops and timeframe functions read here:
http://www.amibroker.com/kb/2014/11/25/using-loops-with-timeframe-functions/

2 Likes

i try using loops with timeframe functions, but what ever itis result showing zero except Price field and default function MA, RSI and ......

please tell me simple solve below code through example, how to using loops with timeframe.

MSF[ 1 ] = LastC [ 1 ];
for( i = 2; i < BarCount ; i++ )
{ 	
	prevMSF = MSF[ i-1 ]; 
	MSF[ i ] =  round( int((( LastC [ i ] - prevMSF )* 0.33 + prevMSF ) * 100 )/ 5 ) * 0.05;
}

I think better to understand me through above example.

Please study the NullCount() function. It is very clearly explained in the KB link shared by fxshrat - Using loops with TimeFrame functions.

Initializing like this is unnecessary:

Since every count in AFL starts with Zero, if you happen to call the first element of an Array, 0 must be used in the subscript, as in, MSF[ 0 ] or LastC [ 0 ]. But to initialize an Array (in this case MSF), it is unnecessary to call using [].

Also refer to When scalar becomes an array, aka. type coercion in AFL

You can just write:
MSF = LastC; //MSF is an Array
or
MSF = 0; //Initialization as 0

With Loop:

TimeFrameSet( WhicheverHghrInterval );
	 //PLEASE READ THIS http://www.amibroker.com/kb/2014/11/25/using-loops-with-timeframe-functions/
	 //AND TRY OUT THE EXAMPLES SHOWN IN THE KB
	 start = NullCount( LastC ) + 1;
	 
	 CompMSF = LastC; //Compressed MSF array Init
	 for( i = start; i < BarCount; i++ ) {
		 prevMSF = CompMSF[ i - 1 ];
		 CompMSF[ i ] =  round( int( ( ( LastC [ i ] - prevMSF ) * 0.33 + prevMSF ) * 100 ) / 5 ) * 0.05;
	 }
TimeFrameRestore();

expandHow = expandFirst; //Otherwise expandLast or expandPoint (Depends on what you want to accomplish)
MSF = TimeFrameExpand( CompMSF, WhicheverHghrInterval, expandHow );

It is hard to tell what exactly you are trying to do. Without a Loop the same can also be written as:

MSF = 0;
MSF = ( ( ( ( LastC - Ref( MSF, -1 ) ) * 0.33 + Ref( MSF, -1 ) ) * 100 ) / 5 ) * 0.05;
MSFComp = TimeFrameCompress( MSF, WhicheverHghrInterval, compressLast );
expandHow = expandFirst; //Otherwise expandLast or expandPoint (Depends on what you want to accomplish)
MSFExp = TimeFrameExpand( MSFComp, WhicheverHghrInterval, expandHow );
//Then use MSFExp for plotting or for further calculation as per your requirements

The initial query with which you started this thread was very meticulously solved by fxshrat in his next post.

1 Like

sorry for the delay.
i try this above and read verticals.

when i use timeframeset, yesterday value show "0"
image

if i removed timeframeset. then value show yesterday close value. i am not understand. why timeframeset not accepting.

image

i understood nullCount() funtion, so i had taken mode =1

Counts the number of consecutive nulls at the beginning of the array (mode = 1)

for Using loops with TimeFrame functions

If we want to use looping code in higher time-frame, we can not really start our calculations from the bar 0, because it would contain Null instead of real data. That is why we would first need to detect were the actual compressed data begins and start calculations on that particular bar instead.

every thing i had use as per rules. please advise the reason.

You are saying, "I saw a bird! Can anyone tell me which one?". Do you expect others to know, decipher and act accordingly to your thoughts?

Quantum physics is in its nascent stage, may be millenniums later, someone can just entangle with the sub-atomic particles of brain neurons and read your thoughts from thousand of miles apart. As of now, not possible! So, please share the code such that others can understand why:

From your shared screenshots no-one knows how you calculated MSF? And why it is not working for you?

BTW did you try not to use a loop as shown earlier?

1 Like

no, friends.

if i change Daily intervel it will give correct value, and if change 1m intraday intervel value showing "0".

TimeFrameSet(inDaily);
LastO = TimeFrameGetPrice( "O", inDaily, -1 );
LastH = TimeFrameGetPrice( "H", inDaily, -1 );
LastL = TimeFrameGetPrice( "L", inDaily, -1 );
LastC = TimeFrameGetPrice( "C", inDaily, -1 );
range = LastH-LastL;

range_value = SelectedValue(range);// not an array but single value

	 start = NullCount( LastC ) + 1;
	 
	 CompMSF = LastC; //Compressed MSF array Init
	 CompMSF[ 1 ] = LastC[ 1 ];
	 for( i = start; i < BarCount; i++ ) {
		 prevMSF = CompMSF[ i - 1 ];
		 CompMSF[ i ] =  round( int( ( ( LastC [ i ] - prevMSF ) * 0.33 + prevMSF ) * 100 ) / 5 ) * 0.05;
	 }
TimeFrameRestore();

expandHow = expandFirst; //Otherwise expandLast or expandPoint (Depends on what you want to accomplish)
MSF = TimeFrameExpand( TimeFrameCompress( CompMSF, inDaily, compressLast),inDaily, expandHow );

textsize = Param("TextSize",9,6,20,1,0);
GfxSetOverlayMode(0);
GfxSelectFont("Trebuchet MS",textsize, 700);
GfxSetBkMode(0); // transparent
GfxSetTextAlign(0);

GfxSetTextColor( colorCustom16 );

GfxTextOut("" + LastC, 205, 25);
GfxTextOut("" + MSF, 325, 25);

You should not mix TimeFrame functions and as such should not insert TimeFrameGetPrice inside TimeFrameSet procedure. Either use one or other.

Also your TimeFrameExpand line wasn't properly done.

//SetBarsRequired(-2);

LastO = TimeFrameGetPrice( "O", inDaily, -1 );
LastH = TimeFrameGetPrice( "H", inDaily, -1 );
LastL = TimeFrameGetPrice( "L", inDaily, -1 );

range = LastH - LastL;

range_value = SelectedValue( range ); // not an array but single value

TimeFrameSet( inDaily );
	LastC = Ref(C,-1);

	start = NullCount( LastC, 1 ) + 1;

	CompMSF = 0;
	for ( i = start; i < BarCount; i++ )
	{
		prevMSF = CompMSF[ i - 1 ];
		CompMSF[ i ] =  round( int( ( ( LastC[ i ] - prevMSF ) * 0.33 + prevMSF ) * 100 ) / 5 ) * 0.05;
	}
TimeFrameRestore();

expandHow = expandFirst; //Otherwise expandLast or expandPoint (Depends on what you want to accomplish)
MSF = TimeFrameExpand( CompMSF,inDaily, expandHow );

// ....
2 Likes