1
votes

Is there a way I can get the current color of a bar chart in msql. Let's assume I set it to red, when the chart is going down and green when it is going up. So how can I get and return the current color in mql?

I tried using OBJPROP_COLOR but can't seem to get it work.

2

2 Answers

3
votes

MQL4 conceptually does not allow user to either touch or query aBarOBJECT.

There are simply no functions to ask in a similar way, like you can ask any other MT4.Graph.anyOtherGuiOBJECT.

The color settings per se are configurable via a manual GUI-dialogue under [F8] Properties

However, MQL4 can detect indirectly rising up Bullish / falling down Bearish bars:

bool isThisBarBULLISH( int aBarPTR = 0 ){
     return ( Close[aBarPTR] > Open[aBarPTR] );
    }

bool isThisBarBEARISH( int aBarPTR = 0 ){
     return ( Close[aBarPTR] < Open[aBarPTR] );
    }

# ||||||||||||||
#
# kindly notice, aBarOBJECT.color has a tri-<state> behaviour:
#
#                           {  aBullish | anIndifferent ( Hammer | ... ) | aBearish }
# ____________________________________________________________________________________
0
votes

AFAIK, you can only get/set an object property on these objects (http://docs.mql4.com/constants/objectconstants/enum_object)

I am not sure if I understand what you mean about setting the color of a bar chart. Do you want to change the color of the current bar, or the color of all the bars on a chart? I don't think that you can change the color of all the bars on a chart programmatically in MT4.

You can always hit F8 and change your chart's color properties to whatever you prefer. Then you can right click on the chart, go to Template, and click save template (give it the name 'default'). Then whenever you open a new chart, it will have the colors you set in the template.