How to test if Color == CLR_NONE ?

 

I have been coding a function to display previous trades on a chart,  in the same way that dragging a previous trade to a chart does.

I want to keep my function versatile so I am making it configurable while at the same time making the defaults match what MT4 shows by default, so some of my function parameters are set to CLR_NONE as default.  When I test for for this value within the function I get results that are wrong,  or seem wrong to me.

So to debug the issue I added Print statements for some of these variables and instead of seeing the value of  4294967295  printed for CLR_NONE  ( 0xFFFFFFFF )  I see -16777216  which isn't correct.  It looks like CLR_NONE has been converted into a signed int .  Now I could understand this happening as part of the Print function,  sort of,  but it also seems that when I try to compare a color with CLR_NONE  I also don't get what I think I should get.

 

I'm using MetaEditor build  409 and testing on  MT4 build 445

If anyone has any ideas or can reproduce what I am getting  ( please state the builds you are using )   please post.  The attached script should show the issues I am getting.  Before running the script place a Horizontal line on your chart called  Test  and change it's color to  none  then run the script with the default parameters and look in the Experts tab.


Thanks.

Files:
 

The show inputs is somehow changing it into -White. What I would expect with CLR_NONE is -1. Try alternating the selected section below and perhaps you could figure out a pattern as to when it wants to print 0, -1 or -16777216. The Built of my last bogus proxy is 432.

//#property show_inputs //Section1


extern color ColorA = CLR_NONE; //Section2
extern color ColorB = CLR_NONE; //Section2


/*  Section:3
color ColorA;
color ColorB;

void init(){
    color ColorA = CLR_NONE;
    color ColorB = CLR_NONE;
}
*/

void start(){
    Alert("CLR_NONE=",CLR_NONE);
    Alert("CLR_White=",White);
    Alert("ColorA=",ColorA,"    ","ColorB=",ColorB);
}
 
ubzen:

The show inputs is somehow changing it into -White. What I would expect with CLR_NONE is -1. Try alternating the selected section below and perhaps you could figure out a pattern as to when it wants to print 0, -1 or -16777216. The Built of my last bogus proxy is 432.


Did you notice how the correct value is printed for the colour of the line ?

2013.01.13 16:26:47 CLR_NONE_Test GBPUSD,H1: Colour of Object Test is:  4294967295

 
RaptorUK:


Did you notice how the correct value is printed for the colour of the line ?

2013.01.13 16:26:47 CLR_NONE_Test GBPUSD,H1: Colour of Object Test is:  4294967295

Yes, but I attributed that to the fact that ObjectGet returns a Double and not a Color. The document for Print says that Color will print with their Numeric representation. I interpreted that to mean "we're gonna mess with it before we print it ;)". The 3 things it had this warning for was Time, Bool and Color. Just like you tested with time, it's not gonna out-put any integer you provide because the time is capped-out by Unix_Time issue. Bool, I'm guessing is so simple they didn't screw it up yet. Color on the other hand could have some technical reason ex) hex, which it has to stay compatible with and maybe thats one of the reason for the funky behavior.
 
ubzen:
Yes, but I attributed that to the fact that ObjectGet returns a Double and not a Color. The document for Print says that Color will print with their Numeric representation. I interpreted that to mean "we're gonna mess with it before we print it ;)". The 3 things it had this warning for was Time, Bool and Color. Just like you tested with time, it's not gonna out-put the integer you provide because the time is capped-out by Unix_Time issue. Bool, I'm guessing is so simple they didn't screw it up yet. Color on the other hand could have some technical reason ex) hex, which it has to stay compatible with and maybe thats one of the reason for the funky behavior.

Good point about the double . . .  thank you. :-)
 

I have a work around that I've tested and seems to work . . . I just don't like working around something.

// Replace    
if (variable == CLR_NONE)

// with       
if (variable > White || variable < Black) 


// Replace    
if (variable != CLR_NONE)

// with       
if (variable <= White && variable >= Black)
 

Bingo, I still couldn't understand where the 4294967295 came from.

CLR_NONE    0xFFFFFFFF    Indicates empty state of colors.

FFFFFFFF= 4294967295 [Decimal]

Calculator. Guess that answers it. :)

 
ubzen:

Bingo, I still couldn't understand where the 4294967295 came from.

CLR_NONE    0xFFFFFFFF    Indicates empty state of colors.

FFFFFFFF= 4294967295 [Decimal]

Calculator. Guess that answers it. :)

Yep,  I mentioned that in my first post ;-)  I even gave a link  ;-)

What you mentioned about the properties box was a big help though,  I should be able to revert back to my original code and use my workaround to reset any colours set to "CLR_NONE"  back to CLR_NONE in the function.  :-)

I'll report the behaviour of the properties box to the service desk as a bug. 

 
Cool, I learned something new too. Til next time.
 

It seems to me that basically your problem come from misused of CLR_NONE. CLR_NONE is not intended to be default color, or no color. For object if you set a color to CLR_NONE, it take backgroung color, what makes the object appear as "invisible".

A better approach :

#property show_inputs


#define         DEFAULT_COLOR_1         Red
#define         DEFAULT_COLOR_2         Blue    

extern color ColorA = DEFAULT_COLOR_1;
extern color ColorB = DEFAULT_COLOR_2;

....

if (variable == DEFAULT_COLOR_1) ...

But I've learned something through your use of CLR_NONE. Thanks

 
angevoyageur:

It seems to me that basically your problem come from misused of CLR_NONE. CLR_NONE is not intended to be default color, or no color. For object if you set a color to CLR_NONE, it take backgroung color, what makes the object appear as "invisible".

A better approach :

But I've learned something through your use of CLR_NONE. Thanks

I'm trying to use CLR_NONE in the same way it is used in OrderSend() or OrderClose()  for the default arrow colour . . .   color arrow_color=CLR_NONE   . . . I don't see it as a misuse.  

CLR_NONE  can be manually selected as a valid colour for any Object,  create an Object,  change it's colour and you will see the option of None at the top of the colour picker box. If the colour is set to None how does one then test for this ?
Reason: