Aid needed to customise plot of RSI indicator with PlotOHLC

Hello guys,
I have just started learning AFL and Amibroker. Have 0 to none knowledge yet.
So decided to solve simple tasks first to practice.
I want to edit RSI indicator so that it fills areas above 70 with solid RED and areas below 30 with solid GREEN. Everything inbetween those ideally to not fill with any color, but for the time being to fill it with black is fine.
However I can't figure it out.

plot_CCI_RSI

I've used one of the examples on the web and successfully achieved desired result for the CCI using code below:

periods = Param( "Periods", 14, 2, 200, 1 );
r = CCI (periods);

minValue = Param ("Min",-100, -200, 0, 1);
maxValue = Param ("Max",100, 0, 200, 1);

Plot( r, _DEFAULT_NAME(), ParamColor( "White",  colorWhite ), ParamStyle("Style")  );
PlotOHLC( r,r,0,r, "", IIf(r > 0, colorRed, colorGreen), styleCloud | styleClipMinMax, minValue, maxValue );

For the RSI I am using the following:

SetChartOptions(0,0,chartGrid30|chartGrid70);
periods = Param( "Periods", 15, 1, 200, 1 );

r = RSI (periods);
minValue = Param ("Min",30, 0, 100, 1);
maxValue = Param ("Max",70, 0, 100, 1);

Plot( r, _DEFAULT_NAME(), ParamColor( "Color",  colorCycle ), ParamStyle("Style")  );
PlotOHLC( r,r,0,r, "", IIf (r < minValue, colorGreen, IIf (r > maxValue, colorRed, colorBlack)), styleCloud | styleClipMinMax, minValue, maxValue );

And as you can see it's not exactly what I am aiming for.

Could anyone please offer any advice where I should look to plot RSI similar to what I got for CCI already?

Huge thanks for your support.

1 Like

Change PlotOHLC's 3rd argument from 0 to 50;

PlotOHLC( r,r,50,r, "", IIf (r < minValue, colorGreen, IIf (r > maxValue, colorRed, colorBlack)), styleCloud | styleClipMinMax, minValue, maxValue );

So here is full code

SetChartOptions(0,0,chartGrid30|chartGrid70);
periods = Param( "Periods", 15, 1, 200, 1 );

r = RSI (periods);
minValue = Param ("Min",30, 0, 100, 1);
maxValue = Param ("Max",70, 0,100, 1);

Plot( r, _DEFAULT_NAME(), ParamColor( "Color",  colorCycle ), ParamStyle("Style")  );
PlotOHLC( r,r,50,r, "", IIf (r < minValue, colorGreen, IIf (r > maxValue, colorRed, colorBlack)), styleCloud | styleClipMinMax, minValue, maxValue );
3 Likes

Hey @fxshrat !
Thank you very much. All works beautifully.
Obviously I haven't completely understood the way PlotOHLC works. That's why this question occurred.

PlotOHLC( open, high, low, close, name, color/barcolor, style = styleCandle | styleOwnScale, minvalue = {empty}, maxvalue = {empty}, XShift = 0, ZOrder = 0, width = 1 )

May I ask why 50 should be the low value in my case? As it's not very intuitive to me yet ^^'

Thank you again for solving my question so fast.

Many indicators, including RSI that you asked for, are bounded to 0...100 range. 50 is the center value in 0..100 range. Also it is center of 30-70 overbought/oversold range. That is why 50 is used.

1 Like