Plot prior day H L C

Hi,

Long time since I asked for help.May be some mistake in the way I am presenting my question, please bear with me.
Know that the solution will come from one of the masters of the software.

I have been trying to plot only the prior days "H L C" but what I have ended up with is a continuous plot - so my request for help is "how do I plot only the prior days "H L C".

A screenshot is below:

and the code I have arrived is below ;---

_SECTION_BEGIN("Price");

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), "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();



_SECTION_BEGIN("HLC");
plotPDR = ParamToggle("PLOT PDR","NO |YES",0);

if (plotPDR)
{
Plot(TimeFrameGetPrice( "H", inDaily, -1 ),"PDH",colorBlue,styleThick);
PlotText("PDH",BarCount,LastValue(TimeFrameGetPrice( "H", inDaily, -1 ),True),colorBlue);
Plot(TimeFrameGetPrice( "L", inDaily, -1 ),"PDL",colorRed,styleThick);
PlotText("PDL",BarCount,LastValue(TimeFrameGetPrice( "L", inDaily, -1 ),True),colorRed);
/*Plot(TimeFrameGetPrice( "O", inDaily, -1 ),"PDO",colorLightGrey,styleLine);
PlotText("Open",BarCount,LastValue(TimeFrameGetPrice( "O", inDaily, -1 ),True),colorLightGrey);*/
Plot(TimeFrameGetPrice( "C", inDaily, -1 ),"PDC",colorDarkGrey,styleLine);
PlotText("PDC",BarCount,LastValue(TimeFrameGetPrice( "C", inDaily, -1 ),True),colorDarkGrey);
}
_SECTION_END();

Thanks for your help.

@Jeetu, you mean to get something like this?

In such a case, instead of Plot(), you should store the previous days HLC data in some arrays, and use the Gfx functions (low-level graphics) in GfxSetCoordsMode( 1 ) to plot the horizontal lines, looping over the visible bars.
You'll need to draw multipe segments from a point to another (boundaries are at each new day): y coordinates are the HLC stored arrays and the x ones are corresponding to bar indexes.

Hint: if you do it from the last visible bar to to first visible one, with some additional logic, you can also y draw the "dotted" lines to the actual previous H L bars (keeping track of the previous day change bar index).

I suggest you search the forum for gfxlineto to find some examples that are using the required functions.

Thanks for the lovely explanation, lots more work for me.

For the present I have used Gfx and bar count to plot lines, screen shot below:

gfx

1 Like

Hi @JEETU
For what you asking the afl code is ready here.
just remember to use -1 for the previous day TimeFrameGetPrice( "H", inDaily, -1 ); // for previous day use -1 in the third parameter

Non sense advice to use slower Gfx within loop instead of just using two Plot lines.

Based on this thread's code

Buy = Day() != Ref(Day(),-1);
Sell = TimeFrameExpand(1, inDaily, expandPoint);

/// @link https://forum.amibroker.com/t/plot-prior-day-h-l-c/35834/4
/// @link https://www.amibroker.com/kb/2014/12/31/drawing-indicators-on-a-subset-of-visible-bars/
/// code snippet by fxshrat@gmail.com
bi = BarIndex();
lastbar = bi == LastValue(bi);

InTrade = Flip(Buy, Sell);
bfutlow = ValueWhen(Sell OR lastbar, LowestSince(Buy, L));
bll = IIf( InTrade, bfutlow, Null );
bfuthigh = ValueWhen(Sell OR lastbar, HighestSince(Buy, H));
bhh = IIf( InTrade, bfuthigh, Null );

_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );

Plot( C, "", colorDefault, styleBar );
Plot( bhh, "High of Previous Day", colorGreen, styleStaircase, Null, Null,1 );
Plot( bll, "Low of Previous Day", colorRed, styleStaircase, Null, Null,1 );

1 Like

Thanks a lot, a bit of help, how do I also plot the closing value.

I did try but have no success

Lovely , solved my immediate issue, I am using the below code for now:- allows me to toggle on and off as well as switch days.

I have another idea, can we plot this for all the visible bars ( something like what "fxshrat" has done for only "H & L" but not for the Close ), will try and see if I come up with anything, otherwise will ask for help.

Once again thanks a lot, yours is a simple guidance which has worked for me.

_SECTION_BEGIN("Price");
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( (H+L+c)/3, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();


_SECTION_BEGIN("Tags");
function ShowLastDay( array )
{
    dn = datenum();
    lastDay = dn == LastValue( dn );

    return IIf( lastDay, array, Null );
}

//HLC
k=IIf(ParamList("select type","daily|next day")=="daily",-1,0);

TimeFrameSet(inDaily);
PDH= LastValue(Ref(H,K));
PDL= LastValue(Ref(L,K));
PDC= LastValue(Ref(C,K));
TimeFrameRestore();
plt = ParamToggle("DAILY","OFF|ON",0);
if(plt)
{
Plot( ShowLastDay( PDH), "", colorGreen, styleThick  );
Plot( ShowLastDay( PDL ), "", colorRed, styleThick  );
Plot( ShowLastDay( PDC ), "", colorBlue, styleDashed|styleThick  );

}

_SECTION_END();

By simply using another Plot line, maybe?

Buy = Day() != Ref(Day(),-1);
Sell = TimeFrameExpand(1, inDaily, expandPoint);

/// @link https://forum.amibroker.com/t/plot-prior-day-h-l-c/35834/4
/// @link https://www.amibroker.com/kb/2014/12/31/drawing-indicators-on-a-subset-of-visible-bars/
/// code snippet by fxshrat@gmail.com
bi = BarIndex();
lastbar = bi == LastValue(bi);

InTrade = Flip(Buy, Sell);
bfutlow = ValueWhen(Sell OR lastbar, LowestSince(Buy, L));
bll = IIf( InTrade, bfutlow, Null );
bfuthigh = ValueWhen(Sell OR lastbar, HighestSince(Buy, H));
bhh = IIf( InTrade, bfuthigh, Null );

prev_close = IIf(InTrade, TimeFrameGetPrice("C", inDaily, -1), Null);

_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );

Plot( C, "", colorDefault, styleBar );
Plot( bhh, "Highest of Previous Day", colorGreen, styleStaircase, Null, Null,1 );
Plot( bll, "Lowest of Previous Day", colorRed, styleStaircase, Null, Null,1 );
Plot( prev_close, "Close of Previous Day", colorBlue, styleStaircase, Null, Null,1 );
1 Like

Thanks a ton for your effort and this lovely solution

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