How to color a rectangle automatically

Hi
wanted to color a rectangle box automatically when a crossover happens
default rectangle color black

GfxRectangle( 10, 150, 150, 50);
GfxFillSolidRect(10, 150, 150, 50, colorBlack );

a=C;
g=(EMA(Close,3) * (2 / 4 - 1)-EMA(Close,60) * (2 / 61 - 1)) / (2 /4- 2 /61);
e=Ref(g,-1);

Plot (EMA(a,10), "10ema", colorBlue,styleNoTitle);
Plot (EMA(a,30), "30ema", colorRed,styleNoTitle);


Buy=Cross(EMA(C,10),EMA(C,30));
Sell=Cross(EMA(C,30),EMA(C,10));

how to color the rectangle to green when buy and red when sell ?
if there is no crossover want the box to be black as would want conditions to apply later .
and also want to remove the ema price value which show up on the right where the price range, I tried with stylenolabel and stylenotitle dint help

StyleNoLabel does prevent showing label on price axis!

Anyway here is code modification...

Either like so (if color change only at signal bar)

a=C;
g=(EMA(Close,3) * (2 / 4 - 1)-EMA(Close,60) * (2 / 61 - 1)) / (2 /4- 2 /61);
e=Ref(g,-1);

Plot (EMA(a,10), "10ema", colorBlue,styleNoLabel);
Plot (EMA(a,30), "30ema", colorRed,styleNoLabel);


Buy=Cross(EMA(C,10),EMA(C,30));
Sell=Cross(EMA(C,30),EMA(C,10));

//GfxRectangle( 10, 150, 150, 50);

rectcolor = LastVisibleValue(IIf(Buy, colorGreen, IIf(Sell, colorRed, colorBlack)));
GfxFillSolidRect(10, 150, 150, 50, rectcolor );

test

Or using Flip for whole period "in trade" / "out of trade".

a=C;
g=(EMA(Close,3) * (2 / 4 - 1)-EMA(Close,60) * (2 / 61 - 1)) / (2 /4- 2 /61);
e=Ref(g,-1);

Plot (EMA(a,10), "10ema", colorBlue, styleNoLabel);
Plot (EMA(a,30), "30ema", colorRed, styleNoLabel);

Buy=Cross(EMA(C,10),EMA(C,30));
Sell=Cross(EMA(C,30),EMA(C,10));

//GfxRectangle( 10, 150, 150, 50);

intrade = Flip(Buy, Sell);
rectcolor = LastVisibleValue(IIf(intrade, colorGreen, colorRed));
GfxFillSolidRect(10, 150, 150, 50, rectcolor );

Or...

3 Likes

@fxshrat Thank You So much