Need Help: Bar Chart Color

#1
Hi Members,

Can you help me with the AFL for the BAR Price Charts such that when:

close < open = RED
close > open = GREEN

I have attached an image for reference.
Thanks.
 
Last edited:
#2


PHP:
 //THANKS TO : WWW.JACKPOTOPTION.COM

_SECTION_BEGIN("Price Chart");
bgTop = ParamColor("BgTop",    colorBlack);
bgBot = ParamColor("BgBottom", colorBlack);
SetChartBkGradientFill( bgTop ,bgBot, colorLightGrey);

pStyle = ParamList("Price Style", "Candle|Solid Candle|Bar|Line|Heikin-Ashi",2);
cBull = ParamColor("Price Bull", colorLime);
CBear = ParamColor("Price Bear", colorRed);
cLine = ParamColor("Price Line", colorWhite);


SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

ThisStyle = styleCandle;
ThisTitle = "";

_O=O; _C=C; _H=H; _L=L;

ThisColor = IIf( _C>_O, cBull, IIf(_C<_O, CBear, CLine));


switch (pStyle )
{

  case "Solid Candle":   
        SetBarFillColor( ThisColor ); 
        break;


  case "Bar": 
       ThisStyle = styleBar;
       break;

  case "Line": 
      ThisStyle = styleLine;
      ThisColor = cLine;
       break;


  case "Heikin-Ashi": 
       _C = (O+H+L+C)/4; 
		  _O = AMA( Ref( _C, -1 ), 0.5 ); 
       _H = Max( H, Max( _C, _O ) ); 
       _L = Min( L, Min( _C, _O ) ); 

       ThisColor = IIf(_C >= _O,CBull, CBear);
       SetBarFillColor( ThisColor );
 
       ThisColor = IIf(_C >= _O,cLine, cLine);
		  ThisTitle = "Heikin-Ashi";
       break;

  default:   
        SetBarFillColor( ThisColor ); 
        ThisColor = cLine;

       break;

}

   PlotOHLC( _O, _H, _L, _C, ThisTitle, ThisColor, ThisStyle); 
   GraphXSpace = 8;

_SECTION_END();
 
#4
Here is another one:

_SECTION_BEGIN("Price");
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 ) ) ));
upColor = ParamColor("Up Color", colorDarkGreen );
downColor = ParamColor("Down Color", colorRed );
Plot( C, "Close", IIf( C>O, upcolor, downColor), styleNoTitle | ParamStyle("Style") | GetPriceStyle() | styleThick);
_SECTION_END();
 
#6
Can anybody please post the AFL as mentioned above but with two modifications :

1. Without open price (Use only High, Low and Close prices)

2. If todays close is greater than yesterdays close than Green bar and if todays close is less than yesterdays bar then Red Color bar. If I am not asking too much than kindly add the same conditions of color in Volume also.

Thanks in advance
 
#7
I have tried the below mentioned formula but unable to add condition of color change Red and Green as per todays close in comparison to yesterdays close.

This is working :

_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 )) ));
PlotOHLC(Null,H,L,C,"",colorBlack,styleBar);
_SECTION_END();

This I wish to add in the above mentioned AFL.


// Get Previous Day's close, Low and High
Prev_Close = TimeFrameGetPrice( "C", inDaily, -1, expandFirst);

Color = IIf(Prev_Close < C, colorRed, colorBlack);
 

casoni

Well-Known Member
#8
I have tried the below mentioned formula but unable to add condition of color change Red and Green as per todays close in comparison to yesterdays close.

This is working :

_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 )) ));
PlotOHLC(Null,H,L,C,"",colorBlack,styleBar);
_SECTION_END();

This I wish to add in the above mentioned AFL.


// Get Previous Day's close, Low and High
Prev_Close = TimeFrameGetPrice( "C", inDaily, -1, expandFirst);

Color = IIf(Prev_Close < C, colorRed, colorBlack);
try this
CC=TimeFrameGetPrice( "C", inDaily, -1 );
col=iif(c>cc,colorgreen,colorred);
plot(c,"",col,128);//style bar
plot(c,"",col,64); //style candle
 

KelvinHand

Well-Known Member
#9


PHP:
 //THANKS TO : WWW.JACKPOTOPTION.COM

_SECTION_BEGIN("Price Chart");
bgTop = ParamColor("BgTop",    colorBlack);
bgBot = ParamColor("BgBottom", colorBlack);
SetChartBkGradientFill( bgTop ,bgBot, colorLightGrey);

pStyle = ParamList("Price Style", "Candle|Solid Candle|Bar|Line|Heikin-Ashi",2);
cBull = ParamColor("Price Bull", colorLime);
CBear = ParamColor("Price Bear", colorRed);
cLine = ParamColor("Price Line", colorWhite);


SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

ThisStyle = styleCandle;
ThisTitle = "";

_O=O; _C=C; _H=H; _L=L;

ThisColor = IIf( _C>_O, cBull, IIf(_C<_O, CBear, CLine));


switch (pStyle )
{

  case "Solid Candle":   
        SetBarFillColor( ThisColor ); 
        break;


  case "Bar": 
       ThisStyle = styleBar;
       break;

  case "Line": 
      ThisStyle = styleLine;
      ThisColor = cLine;
       break;


  case "Heikin-Ashi": 
       _C = (O+H+L+C)/4; 
		  _O = AMA( Ref( _C, -1 ), 0.5 ); 
       _H = Max( H, Max( _C, _O ) ); 
       _L = Min( L, Min( _C, _O ) ); 

       ThisColor = IIf(_C >= _O,CBull, CBear);
       SetBarFillColor( ThisColor );
 
       ThisColor = IIf(_C >= _O,cLine, cLine);
		  ThisTitle = "Heikin-Ashi";
       break;

  default:   
        SetBarFillColor( ThisColor ); 
        ThisColor = cLine;

       break;

}

   PlotOHLC( _O, _H, _L, _C, ThisTitle, ThisColor, ThisStyle); 
   GraphXSpace = 8;

_SECTION_END();
Please thank to KelvinHand. He is the original Creator.
Here is his work published:
http://www.wisestocktrader.com/indicators/3336-integrated-price-chart

It is public sharing code, a bad habit not recognizing his hard work and not mentioning the originator's name.
And let people think is created by him.

It will make the creator stop sharing anymore.


Here are the last 2 pieces of works:
http://www.wisestocktrader.com/indicators/3337-moving-averages
http://www.wisestocktrader.com/indicators/3340-bb-macd
 
Last edited:
#10
try this
CC=TimeFrameGetPrice( "C", inDaily, -1 );
col=iif(c>cc,colorgreen,colorred);
plot(c,"",col,128);//style bar
plot(c,"",col,64); //style candle
Thanks for reply. It is not working. Please check. I have given the whole AFL code for bar charts without open price and its working but I am unable to change the colors of the bars as per yesterdays close.
 

Similar threads