Solid and Hollow Candles as shown in the below image

Hi,

I am looking to configure candles as shown in the below image.

Green Hollow Candle:
Close > Open AND Close > Previous Close

Green Solid Candle:
Close < Open AND Close > Previous Close

Red Solid Candle:
Close < Open AND Close < Previous Close

Red Hollow Candle:
Close > Open AND Close < Previous Close

Is this possible in Amibroker?

I have played with "Preferences -> Bars and Candles" but looks like that doesn't meet my requirements?

I am using Amibroker 6.40.4.

Any insight into this is highly appreciated.

Hi
YES... it is possible in Amibroker

Did you try the function SetBarFillColor ?

https://www.amibroker.com/guide/afl/setbarfillcolor.html

I did try that. Please see below code:

_SECTION_BEGIN( "Plot Basic Chart" );
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() );

SetBarFillColor( IIf( Close > Open AND Close > Ref( Close, -1 ), colorBlack,
                      IIf( Close < Open AND Close > Ref( Close, -1 ), colorGreen,
                           IIf( Close < Open AND Close < Ref( Close, -1 ), colorRed, colorBlack ) ) ) );
_SECTION_END();

Tried using this code along with all 5 options under Tools -> Preferences -> Bars & Candles -> Candlestick Chart Settings.

Is there anything that I am doing wrong?

Hello
Yes . Τhe most important mistake that users make is that they do not read the instructions carefully. And indeed this time it is written in capital letters.

FUNCTION SetBarFillColor( colorarray ) allows to independently control candlestick, bar, cloud, and area chart fill color

SetBarFillColor must PRECEDE the Plot() function call it applies to.

Try something like below code

// SetBarFillColor must PRECEDE the Plot() function call it applies to.

SetBarFillColor( IIf( Close < Open AND Close > Ref( Close, -1 ), colorGreen,
						IIf( Close < Open AND Close < Ref( Close, -1 ), colorred,
							colorBlack)) );

Plot( C, "Close",  IIf( Close > Open AND Close < Ref( Close, -1 ), colorRed, colorBlueGrey ),styleCandle );
1 Like

Thanks @PanoS for rectifying your mistake. I feel bad about myself for making such a silly mistake. I am able to correct it and make some changes to get the hollow candle style that I am looking for. Appreciate your inputs and adding code below for future reference of myself or anyone looking for something like this.

//my Green color - ColorRGB(38, 166, 154)
//my Red color - ColorRGB(239, 83, 80)
_SECTION_BEGIN( "Plot Basic Chart" );
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 ) ) ) );

SetBarFillColor( IIf( Close > Open AND Close > Ref( Close, -1 ), colorBlack,
                      IIf( Close < Open AND Close > Ref( Close, -1 ), ColorRGB(38, 166, 154),
                           IIf( Close < Open AND Close < Ref( Close, -1 ), ColorRGB(239, 83, 80), colorBlack ) ) ) );

Plot( C, "Close", IIf( Close > Open AND Close > Ref( Close, -1 ), ColorRGB(38, 166, 154), IIf( Close < Open AND Close > Ref( Close, -1 ), ColorRGB(38, 166, 154), IIf( Close < Open AND Close < Ref( Close, -1 ), ColorRGB(239, 83, 80), ColorRGB(239, 83, 80) ) ) ), styleNoTitle | styleCandle);
_SECTION_END();

@vdtedla1, to make it a bit more adaptable to different chart configurations, instead of colorBlack you can use the GetChartBkColor() function for the hollow candles.

1 Like

Thanks @beppe. That's a great suggestion. Modified code as below.

//my Green color - ColorRGB(38, 166, 154)
//my Red color - ColorRGB(239, 83, 80)
_SECTION_BEGIN( "Plot Basic Chart with Hollow Candles" );
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 ) ) ) );

SetBarFillColor( IIf( Close > Open AND Close > Ref( Close, -1 ),  GetChartBkColor(),
                      IIf( Close < Open AND Close > Ref( Close, -1 ), ColorRGB(38, 166, 154),
                           IIf( Close < Open AND Close < Ref( Close, -1 ), ColorRGB(239, 83, 80),  GetChartBkColor() ) ) ) );

Plot( C, "Close", IIf( Close > Open AND Close > Ref( Close, -1 ), ColorRGB(38, 166, 154), IIf( Close < Open AND Close > Ref( Close, -1 ), ColorRGB(38, 166, 154), IIf( Close < Open AND Close < Ref( Close, -1 ), ColorRGB(239, 83, 80), ColorRGB(239, 83, 80) ) ) ), styleNoTitle | styleCandle);
_SECTION_END();

2 Likes