Adding Color to an indicator

 

I would like to print a red square (small) on the chart when the next higher time frame is going down. And a white square if it is going up.

How do I do that? Once I get that figured out, I can then add other time frames and different bars.

my code so far is:

// 30 min current

double open.30.0 =iCustom(NULL,30,"Heiken Ashi",0,2,0); //Previous Open

double close.30.0 =iCustom(NULL,30,"Heiken Ashi",0,3,0); //Previous Close

bool Up.30.0 = (close.30.0>open.30.0);

bool Down.30.0 = (close.30.0<open.30.0);

Comment ("\n 30 min current up or down " + Up.30.0 +" "+ Down.30.0);

But instead of the comment to have a "0" or a "1", I want it to show a red or white square or dot.


Any help would be appreciated... I can't find anything by searching this sight or the web.

 
mrchuckw:

I would like to print a red square (small) on the chart when the next higher time frame is going down. And a white square if it is going up.

How do I do that? Once I get that figured out, I can then add other time frames and different bars.

my code so far is:

// 30 min current

double open.30.0 =iCustom(NULL,30,"Heiken Ashi",0,2,0); //Previous Open

double close.30.0 =iCustom(NULL,30,"Heiken Ashi",0,3,0); //Previous Close

bool Up.30.0 = (close.30.0>open.30.0);

bool Down.30.0 = (close.30.0<open.30.0);

Comment ("\n 30 min current up or down " + Up.30.0 +" "+ Down.30.0);

But instead of the comment to have a "0" or a "1", I want it to show a red or white square or dot.


Any help would be appreciated... I can't find anything by searching this sight or the web.

Hi mrchuckw,

Search this site and other FX forums for EA's that have ObjectCreate code...

You use ObjectCreate to place colored marks where you want them.

Hope this helps,

Robert


 
Color indicator's use two buffers. Set one to the value and the other to the empty_value. Look at some indicator code in the code base
 
Thanks Robert!
 

I am using the following code... why isn't it putting a white rectangle on my chart?

ObjectCreate("square",OBJ_RECTANGLE,0,0,0);

ObjectSet("square",OBJPROP_XDISTANCE,193);

ObjectSet("square",OBJPROP_YDISTANCE,48);

ObjectSet("square",OBJPROP_COLOR,White);

 

mrchuckw:

I am using the following code... why isn't it putting a white rectangle on my chart?

ObjectCreate("square",OBJ_RECTANGLE,0,0,0);

ObjectSet("square",OBJPROP_XDISTANCE,193);

ObjectSet("square",OBJPROP_YDISTANCE,48);

ObjectSet("square",OBJPROP_COLOR,White);

OBJ_RECTANGLE 16 Rectangle. Uses 2 coordinates. A coordinate is time and price . . so . . .

ObjectCreate("square",OBJ_RECTANGLE, 0, datetime time1, double price1, datetime time2, double price2);

ObjectSet("square",OBJPROP_COLOR,White);



You need to fill in values for . . datetime time1, double price1, datetime time2, double price2

Or maybe you want to use a Label, OBJ_LABEL and then use a wingding for the square ? https://docs.mql4.com/constants/wingdings

 

Ok... I think. I don't want it to be date/time oriented... I don't think.

Here's what I want. At the bottom of the chart, under the current bar, I want to place a square (wingding 110 ?) that I can fill with

red, if the next time frame up is going down, or fill with white if it is going up.

Then as that bar closes, and the next bar starts, I want the square to move under the former bar, and a new square under the new bar...

does that make sense?

so how would the ObjectCreate() line look? How do I place it on the chart where I want it, or should I use a separate window?

Thanks for your help.

 
mrchuckw:

Ok... I think. I don't want it to be date/time oriented... I don't think.

Here's what I want. At the bottom of the chart, under the current bar, I want to place a square (wingding 110 ?) that I can fill with

red, if the next time frame up is going down, or fill with white if it is going up.

Then as that bar closes, and the next bar starts, I want the square to move under the former bar, and a new square under the new bar...

does that make sense?

so how would the ObjectCreate() line look? How do I place it on the chart where I want it, or should I use a separate window?

Thanks for your help.

Ah OK, so you want a square under every bar, either white or red dependant on an indicator . . . don't use Objects, use Indicator buffers. ( https://docs.mql4.com/customind )

Create 2 indicator buffers, one for red squares one for white squares, set the buffers to have empty values ( SetIndexEmptyValue( int index, double value) ) to get the square under the bar use the bars Low value - 10 pips . . . this is basically what WHRoeder was getting at.

 
But if I set it 10 pips below the price, won't it jump around? maybe I should put it in a separate windo. I want the square in the same place in the chart, no matter what the bars are doing.
 
mrchuckw:
But if I set it 10 pips below the price, won't it jump around? maybe I should put it in a separate windo.
You can put it in a separate window if you want . . . what I said was 10 pips below the Low of the bar . . not below the current price. Most of the code you need is common, if you do it to a separate window it is easy to change it to a position under the bar afterwards . . .
 
OK... let me play with this for a while. I appreciate all the help!
Reason: