How can I change color EMA line?

Hi

I try to use function IIF with EMA change color green when raise up and color red when go down but it not working.

Anyone pls help me

P = ParamField("Price field",-1);

Periods = Param("Periods", 15, 2, 300, 1, 10 );

colorchange = IIf(Periods > -1, colorGreen, colorRed);

Plot( EMA( P, Periods ), _DEFAULT_NAME(), colorchange, ParamStyle("Style") );

Hello zhaud,

May I suggest the following:

P  = ParamField( "Price field", -1 ) ;
Periods = Param( "Periods", 15, 2, 300, 1, 10 ) ;
myEMA   = EMA( P, Periods ) ;

colorchange = IIf( myEMA > Ref( myEMA, -1), colorGreen, colorRed ) ;

Plot ( EMA( P, Periods ), "My EMA( " + Periods + ")", colorchange, styleLine ); 

Best Regards,

1 Like

Dear Coltrane153

thanks