High, Low & Close bar chart

Hi,

I would like to emulate investors.com’s chart where it only plots the bar chart with the high, low and close prices. A close higher than the previous day’s close is coloured blue and a close below the previous day’s close is coloured red. The same goes for the volume. If it’s possible to code, could you please help me with it? Thanks in advance.

This should give you what you’re after. You’ll need to save them to separate AFL files so you can display them in separate panes.

Plot( C, _DEFAULT_NAME(), IIf( C > Ref(C, -1), colorBlue, IIf(C < Ref(C, -1), colorRed, colorGrey40)), styleBar | styleThick );

Plot( Volume, _DEFAULT_NAME(), IIf( C > Ref(C, -1), colorBlue, IIf(C < Ref(C, -1), colorRed, colorGrey40)), styleHistogram | styleThick, maskHistogram  );

Further reading: https://www.amibroker.com/guide/h_dragdrop.html

3 Likes

Code in post #2 is not HLC. It is standard OHLC.
(Also maskHistogram is at wrong place.)

Here is proper HLC bar chart.

Version( 5.73);

thickness = Param( "Bar thickness", -20, -100, 10, 1 );

rc = ROC( C, 1 );
color = IIf( rc > 0, colorBlue, IIf( rc < 0, colorRed, -1 ) );

style = styleNoTitle | styleBar;

PlotOHLC( Null, H, L, C, "", color, style, Null, Null, 0, 0, thickness ); 

SetChartOptions( 0, chartShowArrows | chartShowDates );

_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}}, Hi:%g, Lo:%g, Close:%g, Volume:%g {{VALUES}}", H, L, C, V ) );   

And separate volume chart

rc = ROC( C, 1 );
color = IIf( rc > 0, colorBlue, IIf( rc < 0, colorRed, -1 ) );

Plot( Volume, "Volume", color, styleHistogram, Null, Null, 0, 0, width = -60 );
6 Likes

Those are awesome, thank you very much! Either of these will work fine for me.

Thanks again :slight_smile:

Can you please tell me if there is a way to make the default bar style when selected via "View - Price Chart Style" a HLC Bar chart. I know that it can be done via parameters

PriceStyle = ParamList("Price Style", "Candlesticks|Bars");

PriceStyle1 =  PriceStyle == "Candlesticks";
PriceStyle2 =  PriceStyle == "Bars";

but I want to be able to select it via the view menu. I'm not sure if it can be done and if it can what do I reference to? I tried this.

_SECTION_BEGIN("Price");

GraphXSpace = 5;
SetBarsRequired(sbrAll,sbrAll);

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

if(GetPriceStyle()=="Bars")
 {
 PlotOHLC( Null, H, L, C, "", colorBlack, styleBar, Null, Null, Null, -1 );
 }


if(GetPriceStyle()=="Candlesticks") 
{
Plot( C, "Close", ParamColor("Color", colorDefault ),styleCandle,Null,Null,Null,0); 
}


if(GetPriceStyle()=="Line") 
{
Plot( C, "Close", ParamColor("Color", colorDefault ),styleLine,Null,Null,Null,0); 
}


_SECTION_END();

GetPriceStyle returns number not string.

_SECTION_BEGIN("Price");

GraphXSpace = 5;
//SetBarsRequired(sbrAll,sbrAll);

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

param_color = ParamColor("Color", colorDefault );

if(GetPriceStyle()==styleBar)
{
	PlotOHLC( Null, H, L, C, "", colorBlack, styleBar, Null, Null, 0, -1 );
} 
else 
{
	Plot( C, "Close", param_color,GetPriceStyle(),Null,Null,0,0); 
}
_SECTION_END();
1 Like