Indicator color change based on a condition

 
Is it possible to change the color of an indicator based on a condition?

for example:

       if (momentum1>0) 
       {
            SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Lime);          
       }
       if (momentum1<0) 
       {
            SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Red);          
       }
       Plot0[shift]=momentum1;



I know some coders are using 2 indicator buffers, but would be great if we can change the color of an indicator as i explained (The above example doesnt work, may be iam missing something).

Thanks in advance for any help.
Regards
Alejandro Galindo

 
I forgot to mention that this is outside the Init() function, the change color code is on Main() function.

Regards,
Alejandro Galindo
 
Is it possible to change the color of an indicator based on a condition?

for example:

       if (momentum1>0) 
       {
            SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Lime);          
       }
       if (momentum1<0) 
       {
            SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Red);          
       }
       Plot0[shift]=momentum1;



I know some coders are using 2 indicator buffers, but would be great if we can change the color of an indicator as i explained (The above example doesnt work, may be iam missing something).


color is set for whole line only. you need for 2 buffers - first for momemntum1>0, second for momentum1<0 (and what about momentum1==0?)
 
Thanks Slawa.

Regards
Alejandro Galindo
 
Oh Slawa, i didnt responded your question about momentum1==0, if its cero then doesnt matter, i prefer to dont plot at cero value because i only want to see above or bellow cero level (on this case of course).

Regards
Alejandro Galindo