@kiennc below there is a formula, similar to the one posted by @awilson, which additionally allows you to control how many extensions to draw and also to print the number of consecutive repeated lows (I hope I understood your request). It also includes some dynamically editable parameters.
This version is slower and way more convoluted than the one he posted, looping over the bars one by one, to determine the coordinates from which to start the extension, but perhaps easier to understand for someone who has already programmed using loops in any other language.
// https://forum.amibroker.com/t/how-to-plot-extend-donchian-low-channel-line-from-the-past/39465
donchianLowPeriod = Param( "Donchian low period", 20, 5, 100, 5 );
donchianLowColor = ParamColor( "Donchian low color", colorGreen );
donchianLowVisibility = ParamList( "Donchian low line visible", "No|Full|Repeated values", 1 );
donchianLowExtensionColor = ParamColor( "Donchian low extension color", colorOrange );
sameValuesCount = Param( "# of equal values", 5, 3, 100, 1 );
maxExtensions = Param( "# of line extensions", 3, 0, 10, 1 );
showExtensionsPrice = ParamToggle( "Show line extensions price", "No|Yes", 1 );
LC = LLV( Ref( L, -1 ), donchianLowPeriod );
GraphXSpace = 5;
Plot( C, "Price", colorDefault, styleCandle );
if( donchianLowVisibility == "Full" )
Plot( LC, "Donchian Low", donchianLowColor, styleThick );
if( maxExtensions > 0 )
{
// draws only in the "visible" bars range
bi = Barindex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
GfxSetBkMode( 1 );
GfxSetCoordsMode( 1 );
GfxSelectPen( donchianLowExtensionColor, 1, 2 );
GfxSelectFont( "Arial", 9, 800 );
GfxSetTextColor( donchianLowExtensionColor );
// loop over the visible bars backward
prev = LC[lvb];
counter = 0;
start = -1;
drawnLines = 0;
LCRepeatedValues = null;
for( i = lvb - 1; i >= fvb; i-- )
{
if( drawnLines >= maxExtensions )
break;
if( LC[i] == prev )
{
if( counter == 0 )
{
start = i + 1;
LCRepeatedValues[start] = LC[start];
}
counter++;
LCRepeatedValues[i] = LC[i];
}
else
{
if( counter >= sameValuesCount )
{
if( start < lvb )
{
GfxTextOut( "" + counter, start, LC[start] );
GfxMoveTo( start, LC[start] );
GfxLineTo( Lvb, LC[start] );
drawnLines++;
if( donchianLowVisibility == "Repeated values" )
{
Plot( LCRepeatedValues, "", donchianLowColor , styleThick );
LCRepeatedValues = null;
}
if( showExtensionsPrice )
Plot( LC[start], "", donchianLowExtensionColor, styleNoLine | styleNoTitle );
}
}
counter = 0;
LCRepeatedValues = null;
}
prev = LC[i];
}
// if required draw one more extension line in case the repeated values continue until the leftmost visible bar: the displyed count is then only for the visible bars...
if( drawnLines < maxExtensions )
{
if( counter >= sameValuesCount )
{
GfxTextOut( ">=" + counter, start, LC[start] );
GfxMoveTo( start, LC[start] );
GfxLineTo( Lvb, LC[start] );
if( donchianLowVisibility == "Repeated values" )
{
Plot( LCRepeatedValues, "", donchianLowColor , styleThick );
}
if( showExtensionsPrice )
Plot( LC[start], "", donchianLowExtensionColor, styleNoLine | styleNoTitle );
}
}
}
_N( Title = StrFormat( "{{NAME}} - " + FullName() +
" - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +
WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Note that in this code if the Donchian low line of the last (rightmost) visible bar is part of a sequence of repeated values, the extension is not drawn and consequently not even counted (even if you have some "blank bars").
Although this code example uses a loop limited to a certain number of individual bars, when possible it is always better to use functions that work on entire arrays and for this reason I recommend you continue your study on how AFL works!