@SHANTVCI here is a revised version to be used with intraday data (should work with a minimum of 1-second interval but I have not executed with any RT data under 1-minute).
I added some extra lines to handle your request and also appended an exploration to examine the arrays I used to determine what is the "day" session last bar (where the drawing lines will terminate).
// sample Buy/Sell signals - replace with your code
Buy = Cross( MACD(), Signal() );
Sell = Cross( Signal(), MACD() );
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
Plot( C, "Close", colorDefault, styleCandle );
PlotShapes( shape, IIf( Buy, colorBrightGreen, colorOrange ), 0, IIf( Buy, Low, High ) );
// the following drawing lines code is adapted from a post found in the AmiBroker Community forum:
// https://forum.amibroker.com/t/help-with-iif-function-in-a-loop-horizontal-lines-with-labels-how-to-check-if-the-code-is-efficient/7187/10
// added some logic to draw the lines only till the end of each intraday session
// plot lines only for the visible bars
fvb = Status( "firstvisiblebar" );
lvb = Status( "lastvisiblebar" );
// plot lines behind the price plot
GfxSetZOrder( -1 );
// go back some bars in order to paint lines in the day session also when the buy/sell bars are not yet displayed (hidden at the left)
numBarsInADay = IIf( Interval() >= in1Second, 86400 / Interval(), 0 ); // 24h * 60m * 60s = 86400s
start = Max( 0, fvb - numBarsInADay );
end = Min( lvb, BarCount - 1 );
// added logic to draw lines "per session"
bi = BarIndex();
dn = DateNum();
nd = ( dn != Ref( dn, -1 ) ); // Detect a new day session
vwndbi = ValueWhen( nd, bi ); // Bar index at new day session
vwnextndbi = ValueWhen( nd, bi, 0 ); // Bar index for the next day session (looking to future bars)
lastValidSessionBar = LastValue( Highest( vwnextndbi ) );
firsValidSessionBar = LastValue( Lowest( vwndbi ) );
// Show days separation - Remove/comment out if using Axis/Grid Vertical Gridlines preferences
Plot( nd, "", colorBlue, styleNoTitle | styleNoLabel | styleHistogram | styleOwnScale, 0, 1, 0, -2 );
// set mode = 1 - bar / price mode where X is expressed in bar index and Y is expressed in price
GfxSetCoordsMode( 1 );
for( x = start; x <= end ; x++ )
{
if( Buy[x] OR Sell[x] )
{
// Handle first and last (could be incomplete) sessions
daySessionLastBar = IIf( x >= lastValidSessionBar, lvb, Max( vwnextndbi[x] - 1, 0 ) );
daySessionLastBar = IIf( x < firsValidSessionBar, Max( firsValidSessionBar - 1, 0 ), daySessionLastBar );
if( Buy[x] )
colorLine = colorGreen;
else
colorLine = colorRed;
// Draw line from the open price
y = Open[x];
GfxSelectPen( colorLine, 1, 0 );
GfxMoveTo( x, y );
GfxLineTo( daySessionLastBar, y );
}
}
// Exploration to better understand the used arrays
function nil( a )
{
return ( IIf( a, 1, Null ) );
}
Filter = 1;
AddColumn( Nil( Buy ), "Buy", 1, colorWhite, colorGreen );
AddColumn( Nil( Sell ), "Sell", 1, colorWhite, colorRed );
AddColumn( Nil( nd ), "New Day", 1, colorWhite, colorBlue );
AddColumn( bi, "Bar # (index)", 1 );
AddColumn( vwndbi, "New Day bar #", 1 );
AddColumn( vwnextndbi, "Next Day bar #", 1 );
AddColumn( Lowest( vwndbi ) - 1, "1st closed session bar #" );
AddColumn( Highest( vwnextndbi ) - 1, "Last closed session bar #" );
if( Status( "action" ) == actionExplore )
SetSortColumns( -2 );
I hope it works as expected. I have not tested it extensively since intraday strategies are not my field of action; in any case, if necessary, I leave you the task to improve it and fix any mistake.