Plot line between values - ignore nil values

Hi all,

I am hoping this is an easy fix for someone.

I have my data (which is a csv file from excel) it has all the usual info OPEN, HIGH, LOW, CLOSE ..etc.

The last column is a calculated value (done in excel) that I want to plot - not every entry (date) has a value. When importing the database I call this column AUX1.
When i try to plot AUX1 all the non entries plot as 0.

This is what I want it to look like.
Ideal

This is what it currently looks like.

current

Hope someone can help!!

Cheers.

I'm not 100% confident this is the right answer, but it is worth eliminating:

File> Database Settings> Configure> Pad non-trading days (or All Market Days).

2 Likes

Thanks for the attempt Chris but no luck there. "Local database does not need further configuring" is what I get.

All the days in my database are trade days, some just dont have a Aux1 value, which seems to upset the plotting.

Instead of plotting just Aux1 plot this:

Plot( Iif( Aux1 > 0, Aux1, Null ), "SSC", colorBlue, styleLine );

or if you want to connect non-zero points

Plot( ValueWhen( Aux1 > 0, Aux1 ), "SSC", colorBlue, styleLine );
4 Likes

Looking at the posted images, I think @smedlex needs to do something similar to what is covered by this article.

Here is a snippet to compare the different suggested ways (with a fake array to be replaced by his Aux1 values):

// Code derived from this article:
// http://www.amibroker.org/userkb/2007/04/20/plotting-trade-zigzag-lines/

// Let's fill a fake array with some values every 50 bars in a zig-zag (others bars are null)
SetBarsRequired( sbrAll, sbrAll );
a = Null;
for( i = 0; i < BarCount; i+=50 )
{
    if( ( i % 100) == 0 )
        a[i] = i;
    else
        a[i] = i + 100;
}

// Uncomment the next line and delete all the above to test with your Aux1 data
// a = Aux1;

// Comparing other ways to plot the array that has multiple null values
// -- plot only the values as histogram (no bar is displayed for null values)
// Plot(a, "a", colorWhite, styleHistogram);
// -- plot only the existing values (will be displayed as dots) 
Plot(Iif( a > 0, a, Null ), "Array", colorYellow, styleLine, Null, Null, 0, 0, -100); // to see this you need to zoom in....
// -- plot a line with last value on zero value
Plot( ValueWhen( a > 0, a ), "Array", colorBrightGreen, styleDashed );

// Plot as a zig-Zag line using lineArray()
fvb  = Status( "firstvisiblebar" );
lvb = Status( "lastvisiblebar" );
combinedLine = Null;
x1 = 0;
y1 = a[0];

// Find the firstnon zero value before first visible bar
for( i = fvb - 1; i >= 0; i-- )
{
    if( a[i] > 0 )
    {
        x1 = i;
        y1 = a[i];
        break;
    }
}

// Use LineArray to join the NON-ZERO values and
// then combine all the segments in a sngle line
lastValidBar = -1;
lastValidValue = Null;
for( i = fvb; ( i <= lvb )  AND( i < BarCount ); i++ )
{
    if( a[i] > 0 )
    {
        lastValidBar = i;
        lastValidValue = a[i];
        x2 = i;
        y2 = a[i];
        segment = LineArray( x1, y1, x2, y2 );
        combinedLine = IIf( IsNull( segment ), combinedLine, segment );
        x1 = x2;
        y1 = y2;
    }
}

// optional - use the last known value to plot if the rest of bars are null
if( ( lastValidBar >= 0 ) AND( lastValidBar <  BarCount) )
{
    x2 = BarCount - 1;
    y2 = lastValidValue;
    segment = LineArray( x1, y1, x2, y2 );
    combinedLine = IIf( IsNull( segment ), combinedLine, segment );
}

Plot( combinedLine, "Array", colorRed, styleLine | styleThick );
3 Likes

If that's what he want (instead of using ValueWhen) then here is simpler way....

Plot( C, "Price", colorDefault, styleCandle );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} Op %g, Hi %g, Lo %g, Cl %g (%.1f%%), Vol %g {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );
//
bi = Barindex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

cond = IIf( Aux1 > 0, 1, Null );

start = NullCount( cond );
printf( "%g, %g", start, lvb );

GfxSetCoordsMode( 1 );
GfxSelectPen( colorRed, 1, 0 );
GfxMoveTo( start, Aux1[start] );
for( i = start; i <= lvb; i++ ) 
    if( cond[i] )	GfxLineTo( i, Aux1[i] );

100

3 Likes

The small advantage of the "old" lineArray() method is that the plotted combinedLine values could be used with functions like SelectedValue() (for instance in the Title) to get theoretical intermediate values for the Null bars.

2 Likes

Thanks so much Beppe ( again ) and fxshrat for all your help.
I appreciate all your efforts.

Cheers.