Help my simple AFL, please

#1
Dear members ,
I have simple AFL (Close to EMA 50) , but I can not solve my problem , maybe somebody can help me
if the result of percentage is positive --- > the text color changed to Green
if the result of percentage is negative ---> the text color changed to Red

Example : EMA 50 = 2.57 % (text color & result : green & with position x+1450, y+222)
EMA 50 = -1.24 % (text color & result : red & with position x+1450, y+222)

code :

//=====================================
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("Close - EMA 20 {{NAME}} - {{INTERVAL}} {{DATE}} Open %g High %g Low %g Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorWhite ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
SetChartBkGradientFill( ParamColor("BgTop", colorBlack),ParamColor("BgBottom", colorBlack),ParamColor("Titleblock",colorSkyblue ));

Plot( EMA( Close, 50 ),"", colorGold, styleDots);
x=Param("xposn",1,0,1000,1);
y=Param("yposn",1,0,1000,1);
GfxSetBkMode(1);

PersentaseClose_EMA50 = (C-EMA(C,50))/EMA(C,50)*100;
GfxSelectFont( "Calibri", 15, 800, False );
GfxSetTextColor( colorGreen );
GfxTextOut( "EMA 50 = ",x+1300, y+222);
GfxTextOut( ""+ WriteVal( (PersentaseClose_EMA50),format= 1.2) + " " ,x+1400, y+222);
GfxTextOut( "%" ,x+1450, y+222);

//=====================================

I've tried a few weeks but still can't solve problem
Maybe somebody can help me please
Thank you before :thumb: :thumb:
 
Last edited:

colion

Active Member
#2
Substitute the following for GfxSetTextColor()

if( SelectedValue( persentaseclose_ema50 ) > 0 ) GfxSetTextColor(colorGreen );

else GfxSetTextColor( colorRed );
 

Similar threads