Drawing rectangle extended to the end of day

Hello!
I'm trying to draw rectangle that starts at certain position (if condition) and extends to the end of the day. I want it to have not only on current day (then it would be easier becauase I could use barcount function) but also for historical charts.
I tried to do sth like this (if there is a gap-up, then draw a rectangle):

bi = BarIndex();
FVB = FirstVisibleValue(bi);
LVB = LastVisibleValue(bi);

firstBarDay=DateNum()!=Ref(DateNum(),-1); //changing date

//Yesterday's High (for gap)
	TimeFrameSet(inDaily);
		PrevHighD=Ref(H,-1);
		TodayOpenD=O;
	TimeFrameRestore();
		PrevH=TimeFrameExpand(PrevHighD,inDaily,expandFirst);
		TodayO=TimeFrameExpand(TodayOpenD,inDaily,expandFirst);
		
GapUp=IIf(TodayO > PrevH AND firstBarDay==1, 1, 0);
	
GfxSetZOrder(-5);
GfxSetCoordsMode(1);
GfxSetBkMode(1);
GfxSelectPen(ColorRGB( 50, 100, 150), 1, 0);
GfxSelectSolidBrush( ColorRGB( 50, 100, 150) );
	
for (i=FVB-100;i<LVB;i++)
	{
	if (GapUp[i]==1)
		{
		GfxRectangle(i, TodayO[i], i+70, PrevH[i]); // i+70 is a problem!!!
		}
	}

It draws a rectangle but the width (in bars) is fixed (currently set to 70 for 5min). It looks like this below:
obraz

On different instruments (or time-frames) there is different number of bars every day.
So for historical charts it should extend a rectangle to the end of the day and for current day it should draw a rectangle to the last bar.
Any suggestions, please...

Better -->

PrevH = TimeFrameGetPrice("H", inDaily, -1);
TodayO = TimeFrameGetPrice("O", inDaily, 0);

GapUp() is a native AB function. You can not assign something to function.


-->

next_day = dn != Ref(dn,1) OR bi == LastValue(bi);
EOD_bi = ValueWhen(next_day, bi, 0);
/// @link https://forum.amibroker.com/t/drawing-rectangle-extended-to-the-end-of-day/23732
bi = BarIndex();
dn = DateNum();
FVB = FirstVisibleValue(bi);
LVB = LastVisibleValue(bi);
firstBarDay= dn != Ref(dn,-1); //changing date
next_day = dn != Ref(dn,1) OR bi == LastValue(bi);
EOD_bi = ValueWhen(next_day, bi, 0);

//Yesterday's High (for gap)
PrevH = TimeFrameGetPrice("H", inDaily, -1);
TodayO = TimeFrameGetPrice("O", inDaily, 0);
Gap_Up = TodayO > PrevH AND firstBarDay;

Plot( C, "Price", colorDefault, styleBar );	
GfxSetZOrder(-5);
GfxSetCoordsMode(1);
GfxSetBkMode(1);
GfxSelectPen(ColorRGB( 50, 100, 150), 1, 0);
GfxSelectSolidBrush( ColorRGB( 50, 100, 150) );
	
for( i = FVB; i < LVB; i++ )
{
	if( Gap_Up[i] )	GfxRectangle( i, TodayO[i], EOD_bi[i]+1, PrevH[i] );
}

22

3 Likes

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