Defining bars in intraday

i know the current day bar can be calculated using this

FBL=ValueWhen(Day()!=Ref(Day(),-1),L);
FBH=ValueWhen(Day()!=Ref(Day(),-1),H);

but how to get the value of third and fourth bar of yesterday

Thanks

You should rather use DateNum() instead of Day() to mark new day because Day is less precisely. It is marginal issue but still...
Also you should not re-call same function over and over again.
You simply learn to do/repeat wrong habits from wrong people.

/// #####################################################################
/// @link https://forum.amibroker.com/t/defining-bars-in-intraday/6849/2
/// by fxshrat 
/// High/Low lines code for use with INTRADAY(!) data
/// #####################################################################
dn = DateNum();
newday = dn != Ref( dn, -1 );

brs_since = BarsSince( newday ) + 1;

days_back = 2;// "2" means previous day, "3" day before previous day etc.

startbar = 1; 
endbar = 4;
for ( i = startbar; i <= endbar; i++ ) {
	bars_condition = brs_since == i; 
	VarSet( "FBL" + i, ValueWhen( bars_condition, L, days_back ) );
	VarSet( "FBH" + i, ValueWhen( bars_condition, H, days_back ) );
}

for ( i = startbar; i <= endbar; i++ ) {
	vgL_str = "FBL" + i;
	vgL = VarGet( vgL_str );
	vgH_str = "FBH" + i;
	vgH = VarGet( vgH_str );
	Plot( vgL, vgL_str, colorRed, styleStaircase );
	Plot( vgH, vgH_str, colorGreen, styleStaircase );
}

Plot( C, "", colorDefault, styleCandle );

359

2 Likes

Alternative plot to shift lines to start of day (plots of current (last) day will appear if set startbar and endbar exist at current day).

Also look at startbar and endbar variables if you want more Highs and Lows.

/// #####################################################################
/// @link https://forum.amibroker.com/t/defining-bars-in-intraday/6849/3
/// High/Low lines code for use with INTRADAY(!) data
/// vrs. 1.1, shifting all plots to start of day
/// plots of current day will appear 
/// if set startbar and endbar exist at current day
/// by fxshrat 
/// #####################################################################
dn = DateNum();
newday = dn != Ref( dn, -1 );

brs_since = BarsSince( newday ) + 1;

days_back = 2;// "2" means previous day, "3" day before previous day etc.

startbar = 3; 
endbar = 4;
for ( i = startbar; i <= endbar; i++ ) {
	bars_condition = brs_since == i; 
	VarSet( "FBL" + i, ValueWhen( bars_condition, L, days_back ) );
	VarSet( "FBH" + i, ValueWhen( bars_condition, H, days_back ) );
}

for ( i = startbar; i <= endbar; i++ ) {
	vgL_str = "FBL" + i;
	vgL = VarGet( vgL_str );
	vgH_str = "FBH" + i;
	vgH = VarGet( vgH_str );
	Plot( Ref(vgL, i-1), vgL_str, colorRed, styleStaircase );
	Plot( Ref(vgH, i-1), vgH_str, colorGreen, styleStaircase);
}

Plot( C, "", colorDefault, styleCandle );

724

2 Likes

thanks fxshrat for your reply
and what is my thought is getting the value of every hour high low example 91500 close 101500 close and 101500 to 111500 close of the previous days intraday value

i had made some edits fxshart
to get the closes of specific candles

/// #####################################################################
/// @link https://forum.amibroker.com/t/defining-bars-in-intraday/6849/3
/// High/Low lines code for use with INTRADAY(!) data
/// vrs. 1.1, shifting all plots to start of day
/// plots of current day will appear 
/// if set startbar and endbar exist for current day
/// by fxshrat 
/// #####################################################################
dn = DateNum();
newday = dn != Ref( dn, -1 );

brs_since = BarsSince( newday ) + 1;

days_back = 2;// "2" means previous day, "3" day before previous day etc.

//BAR 1 START
startbar = 1; //BAR1
endbar = 1;//BAR1
for ( i = startbar; i <= endbar; i++ ) {
	bars_condition = brs_since == i; 
	VarSet( "FBC" + i, ValueWhen( bars_condition, C, days_back ) );
	
}

for ( i = startbar; i <= endbar; i++ ) {
	vgL_str = "FBC" + i;
	vgL0 = VarGet( vgL_str );
	Plot( Ref(vgL0, i-1), vgL_str, colorRed, styleStaircase );
	
}

//BAR END START


//BAR 1 START
startbar = 12; //BAR1
endbar = 12;//BAR1
for ( i = startbar; i <= endbar; i++ ) {
	bars_condition = brs_since == i; 
	VarSet( "FBC" + i, ValueWhen( bars_condition, C, days_back ) );
	
}

for ( i = startbar; i <= endbar; i++ ) {
	vgL_str = "FBC" + i;
	vgL1 = VarGet( vgL_str );
	Plot( Ref(vgL1, i-1), vgL_str, colorRed, styleStaircase );
	
}

//BAR END START
SetChartOptions(0,chartShowArrows|chartShowDates); 
_N(Title = Date()+ EncodeColor(colorWhite)+"OPEN:"+ Open+" ,"+"HIGH:"+High+" ,"+"LOW:"+Low+" , "+"CLOSE:"+Close 
+"TREND:   "   + vgL0 +"  "+ VGL1); 
Plot(Close,"",colorDefault,styleCandle); GraphXSpace=30; GraphGridZOrder=100; 

Sorry, but your last code is nonsense. Don't do that.

Also in your first post of this thread you did not say that you want to have start and end bar of every hour of previous day (e.g. start and end close of hourly bars of previous day in 5min TF). That is not what your first post is asking for!

You said you want to have value of third and fourth bar since start of day of yesterday. That is what your first post (which includes code example) is asking for. In wise foresight I added loop to choose any bar since start of day of selected interval.

Now it turns out you are looking for something different.

If are looking for wasting other peoples time by posting questions you are actually not looking an answer for then better choose different forum.

It is amazing that people look for other people taking their valuable time but some questioners do not even seem to bother taking more time to think about writing proper question before sending post.

Post question in such a way that it leaves not much room (or even better no room) for wasting time.
Pictures do help too as addition.
(And don't write questions in SMS style).

2 Likes