Intraday Barcount

Romeo1998

Well-Known Member
#1
Dear Friends,
In the data of any symbol, the first bar is 0, second bar is 1, third bar is 2 n so on.
But I want the first bar on every new day to be 0 :| I have tried many things but its not working :|
Can anyone please tell me how can I achieve that :)
Awaiting your reply.
Thank you :)
 

trash

Well-Known Member
#2
People almost always say "I have tried..."
But what is it that you have tried actually?

Well, obviously you would need to flag new day.

Code:
dn = DateNum();
newday = dn != Ref( dn, -1 );

BarsOfDay = BarsSince( newday ) /*+ 1*/;

printf( "Bars since new day: %g", BarsOfDay );
 

Romeo1998

Well-Known Member
#3
People almost always say "I have tried..."
But what is it that you have tried actually?

Well, obviously you would need to flag new day.

Code:
dn = DateNum();
newday = dn != Ref( dn, -1 );

BarsOfDay = BarsSince( newday ) /*+ 1*/;

printf( "Bars since new day: %g", BarsOfDay );
thank you dear friend :)
I have tried this code

dist = 1 * ATR( 2 );
for (i=0; i<BarCount;++i)
{
PlotText( "" + i , i , L - dist, colorGreen );
}

i get the bar number below each bar

but i dont know how to reset the bar number with each new day in intraday timeframe, means with each new day count from 0 in intraday timeframe :)
 
Last edited:

Romeo1998

Well-Known Member
#4
wow, i used your code, n finally i got it ^_^ , thank u friend ^_^
this is the code for what i wanted to do ^_^
Code:
for (i=0; i<BarCount;++i)
{
PlotText(  " "  + barsofday[i] , i , L - dist, colorGreen );
}
 

trash

Well-Known Member
#5
wow, i used your code, n finally i got it ^_^ , thank u friend ^_^
this is the code for what i wanted to do ^_^
Code:
for (i=0; i<BarCount;++i)
{
PlotText(  " "  + barsofday[i] , i , L - dist, colorGreen );
}
Your code is wrong. L - dist is an ARRAY! So you have to use subscript.
But you only need L because PlotText has an y-offset argument at 6th position!

Also you don't need to iterate entire Barcount but just visible one.
So,

Code:
SetBarsRequired( 1500, 1500 );

dn = DateNum();
newday = dn != Ref( dn, -1 );

BarsOfDay = BarsSince( newday ) /*+ 1*/;

printf( "Bars since new day: %g", BarsOfDay );

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

bi = Barindex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

yoffset = -20;
for( i = fvb; i <= lvb; i++ ) {
    PlotText( " "  + barsofday[i] , i , L[i], colorGreen, -1, yoffset );
}
 

Romeo1998

Well-Known Member
#6
Your code is wrong. L - dist is an ARRAY! So you have to use subscript.
But you only need L because PlotText has an y-offset argument at 6th position!

Also you don't need to iterate entire Barcount but just visible one.
So,

Code:
SetBarsRequired( 1500, 1500 );

dn = DateNum();
newday = dn != Ref( dn, -1 );

BarsOfDay = BarsSince( newday ) /*+ 1*/;

printf( "Bars since new day: %g", BarsOfDay );

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

bi = Barindex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

yoffset = -20;
for( i = fvb; i <= lvb; i++ ) {
    PlotText( " "  + barsofday[i] , i , L[i], colorGreen, -1, yoffset );
}
yes, u r right friend , i was making many mistakes :|
i m new to c++ and afl, but i m learning bit by bit everyday :)
thank you once again for helping me out ^_^ :)
have an amazing day ^_^ :)
 
#7
Code:
dn = DateNum();
newday = dn != Ref( dn, -1 );

BarsOfDay = BarsSince( newday ) /*+ 1*/;

printf( "Bars since new day: %g", BarsOfDay );
This was what I was looking for. Good Job