How to show the current price in the bar along with O H L

price

How to show the current price on the bar, so when a new bar is forming want the price to show in the new bar Open high low and current price

I don’t know why you need to have a yellow line and the value next to it?
It is easier to use LastValue()

This is the values of the last bar

//  the values of the last bar
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", LastValue(O), LastValue(H), LastValue(L), LastValue(C), SelectedValue( ROC( C, 1 )) ));
3 Likes

@twin, in a real chart, there are a lot of bars, and you can freely zoom and scroll them.

Although you can write some code using PlotText() (or if you want more control low-level graphics) to display (near the last bar) as text the its O H L C values, these numbers may not be very legible, overlapping each other (depending on the size of the candle).

For this reason, the OHLC values are usually displayed in the title.

One alternative way to "always" show, in an "easy to read" way, the O H L C values of the "last visible bar" is to use the labels displayed in the right side scale of the chart, like in the following screenshot:

immagine

To get this result, use this code snippet:

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{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 )) ));
Plot(C, "", colorDefault, styleCandle); 
Plot(O, "", colorYellow, styleNoLine);
Plot(H, "", colorBrightGreen, styleNoLine);
Plot(L, "", colorRed, styleNoLine);

In the above code, the title can be used to show also the values of the "selected bar" but you can modify it as suggested by @Panos.

Maybe this is an unorthodox usage of "styleNoLine" but it seems to work.
I do not know if this could be an acceptable solution for you, but I gave it a try.

2 Likes

@PanoS and @beppe thank you for your time and help

I got too many labels so wanted the price displayed .... I understand the overlapping thing ... However can we have just a line plotted on the current price of the bar .... I can do without the OHL

How to Draw a straight line on the current price

Val = Ref(close, 0); 

Plot ( Val, "Val", colorLightBlue, styleLine|styleThick|styleNoRescale );

@PanoS @beppe thanks for your time and help thank you :slight_smile:

@twin, maybe this snippet will give you additional ideas how to proceed:

drawLineMode = ParamToggle( "Keep line always in sight", "Yes|No", 1 );
drawLineBarsLenght = Param( "Line lenght - in bars", 10, 2, 60, 1 );
drawLineColor = ParamColor( "Line color", colorLightBlue );
drawLineSize = Param( "Line color size", 3, 1, 5, 1 );

drawLineCloseValue = LastValue( Close );

if( drawLineMode == 1 )
    drawLineCondition = ( BarIndex() > ( BarCount - drawLineBarsLenght ) );
else
{
    lvb = Status( "lastvisiblebar" );

    // ignore any potential "blank" future bars (past the last bar in the array)
    // as defined in preferences
    if( lvb > ( BarCount - 1 ) )
        lvb = BarCount - 1;

    drawLineCondition = ( BarIndex() > ( lvb - drawLineBarsLenght ) );
}

drawLine = iif( drawLineCondition, drawLineCloseValue, Null );
Plot( C, "Close", colorDefault, styleCandle );
// Plot line using Z-order -1  to draw it behind the price graph
Plot( drawLine, "Last Close Line", drawLineColor, styleLine | styleNoLabel | styleNoTitle, Null, Null, 0, -1, drawLineSize );

Play a little with the parameters: in particular, see how the "mode" will change how the line is drawn when you scroll the chart to the left to see old prices.

6 Likes

Hello

is not the best but it is ..... One more idea how to plot lines in right side of the chart using GFX.

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

GfxSetCoordsMode(2);
function gfxPlotRightLine( YPixels, Color )
{
    pxchartright= Status("pxchartright") ;
    GfxSelectPen( Color ) ;
    GfxMoveTo( pxchartright-20, LastValue(YPixels) );
    GfxLineTo( pxchartright-200, LastValue(YPixels) );
}

gfxPlotRightLine( O, colorBlue );  // line for Open
gfxPlotRightLine( H, colorBlue );
gfxPlotRightLine( L, colorBlue );
gfxPlotRightLine( C, colorYellow);

GfxLines

4 Likes

@PanoS nad @beppe thank you once again

1 Like