AmiBroker custom bar colors buy sell AFL

Following piece of code is for drawing, coloured bars/candles that changes its colour with signal, it makes easy to understand working of strategy.

color = IIf(Flip(Buy, Sell), colorLime, colorLightGrey);
color = IIf(Flip(Short, Cover), colorRed, IIf(color != colorLightGrey, color, colorLightGrey));
Plot(C, "C", color, styleCandle);

 

Note that all four variables buy, sell, short, cover must be set in AFL somewhere before above code starts, a sample working AFL may look like below;

 

ma1 = ma(c, 10);
ma2 = ma(c, 30);

buy=cover = cross(ma1, ma2);
sell=short = cross(ma2, ma1);

color = IIf(Flip(Buy, Sell), colorLime, colorLightGrey);
color = IIf(Flip(Short, Cover), colorRed, IIf(color != colorLightGrey, color, colorLightGrey));
Plot(C, "C", color, styleCandle);

Leave a Reply