Download MetaTrader 5
To add comments, please log in or register
MQL5 Cloud Network is a distributed computing network. Just give it a try!
Hoa Hoang Van
4377
Hoa Hoang Van 2014.05.12 10:34 

Dear all,

I want change color of bar chart like Heiken Ashi indicator. Can anyone help me this code?

For example: when RSI > 50 Bar color is red, RSI < 50 bar is blue.

Thank you!

qjol
3243
qjol 2014.05.12 10:54  

if you want to change a single bar you have to use objects for that

to change the entire chart use ChartSetInteger ENUM_CHART_PROPERTY_INTEGER:


CHART_COLOR_BACKGROUND

Chart background color

color

CHART_COLOR_FOREGROUND

Color of axes, scales and OHLC line

color

CHART_COLOR_GRID

Grid color

color

CHART_COLOR_VOLUME

Color of volumes and order opening levels

color

CHART_COLOR_CHART_UP

Color for the up bar, shadows and body borders of bull candlesticks

color

CHART_COLOR_CHART_DOWN

Color for the down bar, shadows and body borders of bear candlesticks

color

CHART_COLOR_CHART_LINE

Line chart color and color of "Doji" Japanese candlesticks

color

CHART_COLOR_CANDLE_BULL

Body color of a bull candlestick

color

CHART_COLOR_CANDLE_BEAR

Body color of a bear candlestick

color

CHART_COLOR_BID

Bid price level color

color

CHART_COLOR_ASK

Ask price level color

color

CHART_COLOR_LAST

Line color of the last executed deal price (Last)

Hoa Hoang Van
4377
Hoa Hoang Van 2014.05.12 16:28  

Thank you for your answer. I wanna change entire chart, but i dont understand how to use this ChartSetInterger with my conditions. Can you write a simple code with my example?

RSI >50, bar is red. RSI < 50 bar is blue

qjol
3243
qjol 2014.05.12 16:50  
here you can find functions and examples ready to use
Hoa Hoang Van
4377
Hoa Hoang Van 2014.05.13 09:22  
It seems to be complex. Thank you :)
qjol
3243
qjol 2014.05.13 09:58  

complex ? why ?

it's so simple MQ already done the dirty work for you just pick the right function put it in your EA/indicator/Script

the only thing they left for you, is to call the right function when you want or need it

for instance if for some reason i want to change the background color to blue i copy the fonction to my EA/Ind......

//+------------------------------------------------------------------+
//| The function sets chart background color.                        |
//+------------------------------------------------------------------+
bool ChartBackColorSet(const color clr,const long chart_ID=0)
  {
//--- reset the error value
   ResetLastError();
//--- set the chart background color
   if(!ChartSetInteger(chart_ID,CHART_COLOR_BACKGROUND,clr))
     {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }


and i call it whenever i want

if (Bla Bla Bla)
   ChartBackColorSet(clrBlue);
/
To add comments, please log in or register