What is wrong in my code

color = IIf( False , ParamColor("Up Color", colorRed ), ParamColor("Down Color", colorGreen ) );

Plot( abs(OIchange), _DEFAULT_NAME(), color , ParamStyle( "Style", styleHistogram | styleThick, maskHistogram  ) );

I am expecting green bar but it is giving red bar.

image

What type is “false”? It is type number and equal to 0 (zero).
If you just write false then false is active for all bars. So all bars are colored red in your case.

f = false;
printf( "Type of FALSE is: %s and returns: %g", typeof(f), f );

Instead write array color like so, for example (assuming that your oichange variable is of type array)

color = Iif( oichange <= 0, colorRed, colorGreen );

image

image

image

Since condition is evaluating to false so I am expecting Green to be bar Color, am I missing anything ?
if condition is true then it taking false part color

Yes.

color = Iff( False, ..., ... ); 

Translation: If false (is zero) then return … else return …

So basically you could just write also

truecond = False == 0;
color = iif( truecond, ...., ... );

similar to True

truecond = True == 1;
color = iif( truecond, ...., ... );

Since both are true for entire array you get single color.

@fxshrat Sorry to trouble you and thanks for your effort, I am still confused with the output of the AFL.

image

image

in both the cases condition is evaluating to 1 as printed but result is coming differently. please see the Bar color and Line color they are opposite, also if you see the code since condition is 1 it should take true part of the code which is red but it is taking the false part for true condition and true part for false condition.

also see the below

image

problem is coming when using Paramcolor in the code.

//color = IIf( false,  ParamColor("Up Color", colorRed), ParamColor("Down Color", colorGreen) );
color = IIf( False, colorRed, colorGreen);

Plot( abs(OIchange), _DEFAULT_NAME(), color , ParamStyle( "Style", styleHistogram | styleThick, maskHistogram  ) );

//color = IIf( true ,  ParamColor("Up Color", colorRed), ParamColor("Down Color", colorGreen) );
color = IIf( False, colorRed, colorGreen);

Plot(OI % factor,"Open Interest",color, styleLine);

truecond = (False == 0);
printf("\ntruecond = %g", truecond); // gave output  truecond = 1


truecond = (True == 1);
printf("\ntruecond = %g", truecond); // gave output  truecond = 1

@phb, Not that I can code like @fxshrat, but I am trying to understand your code.

Normally I think of an IF statement or the IIF statement as doing a TEST first, then controlling what happens.

So, I don’t understand your code line of:
color = IIF( False, colorRed, colorGreen);
How are you “testing” the expression ‘False’?

If you code was something like:
color = IIF(vara > varb, colorRed, colorGreen);
Then I would understand you are testing variable A and variable B. But testing ‘False’ does not make sense to me.

OR if your code was:
color = IIF(varc == False, colorRed, colorGreen);
Then you are testing if variable C is evaluating to True or False.

Additionally, for clarity, you might want to use color1 & color2 variables when building your sample code. That way you can make sure you are not overwriting the same variable. That should help in your debugging as well.

Since your first sample code tests once for False, and then for True, I would expect both Red and Green colors.

Your second sample tests for False both times, so only Green shows.

Hope this helps.
Snoopy

@snoopy.pa30

Most of the code in that was for debugging purpose.

Original code is this.

OIchange =1000000;

//color = IIf( OIchange > 0, colorRed, colorGreen);

color = IIf( OIchange < 0, ParamColor("Up Color", colorRed ), ParamColor("Down Color", colorGreen ) );

Plot( abs(OIchange), _DEFAULT_NAME(), color , styleHistogram | styleThick, maskHistogram );

Plot(OI % factor,"Open Interest", colorYellow, styleLine);

output is coming like this

image

OIchange < 0 will be = false so it should draw in Green color but it is drawing in Red.

if I change the code like this then it is OK.

image

so It seems something wrong with usage of Paramcolor. if you try the code given in first post you can understand.

I interchanged text "Up" and "Down" in that line it solved the problem

but how that is related to this is mystery for me :smiley:

image

Let us put things straight: there is nothing wrong with ParamColor.

You are aware that you code has wrong parameters, aren’t you? You are passing maskHistogram in place of “xmin” argument. Secondly, Param* functions should be called undonditionaly. Corrected code is:

OIchange =1000000;

upcolor = ParamColor("Up Color", colorRed );
dncolor = ParamColor("Down Color", colorGreen );

color = IIf( OIchange > 0, upcolor, dncolor );

// condition that evaluates to true will give you UP (red) color 
Plot( C, _DEFAULT_NAME(), color , styleHistogram | styleThick );

and this

OIchange =1000000;

upcolor = ParamColor("Up Color", colorRed );
dncolor = ParamColor("Down Color", colorGreen );

// reverse sign (evaluates to false )will give you down color (Green)
color = IIf( OIchange < 0, upcolor, dncolor );

Plot( C, _DEFAULT_NAME(), color , styleHistogram | styleThick );

And by the way - press “RESET ALL” in parameters window because you are likely messed up colors to be reverse from the defined in the code.

And I have changed the topic subject from “what is wrong with ParamColor” to “what is wrong with my code” that better reflects the situation here.

Recommended reading:

1 Like

Thank You @Tomasz

I will go through the links.