Daily RSI cloud color change based on MTF RSI level

Hello all,

Can any one please help me to get the correct code for the following. I'm trying to get Daily RSI 40-60 level cloud color change based on the MTF RSI levels. For example if monthly and weekly RSI is above 60 level, then when the Daily RSI gets above 60 level cloud color should be changed to accordingly. If the color change happens we will get to know that all time frames are in sync with RSI above 60 levels. Like that RSI drops below 40 level.

I have tried to write the code, but I'm unable to understand that how to write using iif or if or dynamic color options.

Thank you very much for spending your precious time.

Here is the code :

//Daily RSI 40-60 level cloud color change based on MTF RSI 40-60 level//

TimeFrameSet( inMonthly );
MonthlyRSI = RSI(14);
TimeFrameRestore();
Monthly_RSI = TimeFrameExpand( MonthlyRSI, inMonthly, expandLast );

TimeFrameSet( inWeekly );
WeeklyRSI = RSI(14);
TimeFrameRestore();
Weekly_RSI = TimeFrameExpand( WeeklyRSI, inWeekly, expandLast );

MRSI60 = IIf(Monthly_RSI>60,1,0);
MRSI40 = IIf(Monthly_RSI<40,1,0);
WRSI60 = IIf(Weekly_RSI>60,1,0);
WRSI40 = IIf(Weekly_RSI<40,1,0);

r = RSI(14);

Plot( r, "", colorGreen, styleLine | styleClipMinMax | styleNoLabel, 40, 0 );
Plot( r, "", colorRed, styleLine | styleClipMinMax | styleNoLabel, 100, 60 );
IIf( r > 40 AND r < 60, Plot( r, _DEFAULT_NAME(), colorLightOrange, styleLine  | styleClipMinMax ), Null );

PlotOHLC( r,r,50,r, "", IIf( r > 50 AND WRSI60=1, colorRed, colorGreen ), styleCloud | styleClipMinMax  | styleNoLabel, 40, 60 );


Plot(60, "", colorblack, styleLine); 
Plot(40, "", colorblack, styleLine); 
Plot(50, "", colorblack, styleLine);

The code is incorrect. IIF is not control flow statement

@Tomasz, okay. unfortunately I'm not able to understand that much of the depth in programming language. So, requested to some one's help for that code. Don't close this topic as solved. Thank you.

Your below line of code uses improper use of 'IIF'

As per @Tomasz reference. Should be used like so:

result = IIf( condition, YesValue, NoValue );

@Trendsurfer, make an attempt to do, but lots of syntax errors. This is more of complex for me. I think I have to write two conditions in this case. One is if daily RSI > 60 and WRSI >60. Really I'm not getting any idea to how to do this. As I referred some example in dynamic color reference :

dynamic_color = IIf( RSI(14) > 60 AND Weekly_RSI > 60, colorGreen, colorRed );

Using this code I'm not getting the desired results. Dual conditions I'm not doing code properly. I have expanded in time frame option for weekly_rsi but not getting correctly.

please do the needful. Thank you.

WRSI60=1

Incorrect, here you are using 'assignment [=]' where should be using 'equal to' [==].

So replace with just WRSI60 which is same (in this case) as WRSI60 == 1

Using the same above code applying on the chart for buy/sell shapes I'm getting correctly, without complex logical queries. But getting problem to write the code for the above needs.

Source : Amibroker help guide.

_SECTION_BEGIN("plot shapes");
//Daily RSI 40-60 level cloud color change based on MTF RSI 40-60 level//

TimeFrameSet( inMonthly );
MonthlyRSI = RSI(14);
TimeFrameRestore();
Monthly_RSI = TimeFrameExpand( MonthlyRSI, inMonthly, expandLast );

TimeFrameSet( inWeekly );
WeeklyRSI = RSI(14);
TimeFrameRestore();
Weekly_RSI = TimeFrameExpand( WeeklyRSI, inWeekly, expandLast );

MRSI60 = IIf(Monthly_RSI>60,1,0);
MRSI40 = IIf(Monthly_RSI<40,1,0);
WRSI60 = IIf(Weekly_RSI>60,1,0);
WRSI40 = IIf(Weekly_RSI<40,1,0);


Buy = Monthly_RSI > 60 AND weekly_RSI > 60 AND RSI(14) > 60;
Sell = Monthly_RSI < 40 AND weekly_RSI < 40 AND Cross(RSI(14),60);

PlotShapes( IIF( buy, shapeDigit9 + shapePositionAbove, shapeNone ), colorGreen );
PlotShapes( IIF( Sell, shapeuparrow + shapePositionAbove, shapeNone ), colorlightblue );
_SECTION_END();

@dragon I haven't looked at the rest of your code and I am not really familiar with the styleClipMinMax but below is an attempt to help you solve your multi-time-frame creation of a dynamic_color.

TimeFrameSet( inWeekly );
WeeklyRSI = RSI( 14 );
TimeFrameRestore();
wRSI = TimeFrameExpand( WeeklyRSI, inWeekly, expandLast ); // Weekly RSI

TimeFrameSet( inMonthly );
MonthlyRSI = RSI( 14 );
TimeFrameRestore();
mRSI = TimeFrameExpand( MonthlyRSI, inMonthly, expandLast ); // Monthly RSI

dRSI 	= RSI( 14 ); // daily RSI
dRSIhi	= dRSI > 60;
dRSIlo	= dRSI < 40;

wRSIhi = wRSI > 60;
wRSIlo = wRSI < 40;

mRSIhi = mRSI > 60;
mRSIlo = mRSI < 40;

DynamicColor = IIf( mRSIhi AND wRSIhi AND dRSIhi, colorRed, IIf( dRSIlo AND wRSIlo AND mRSIlo, colorGreen, colorblack ) );

Plot( dRSI, "Daily RSI", colorWhite, styleLine );
//Plot( wRSI, "Weekly RSI", colorAqua, styledashed );
//Plot( mRSI, "Monthly RSI", colorLightBlue, styleDots );

PlotOHLC( dRSI, dRSI, 50, dRSI, "", DynamicColor, styleCloud | styleClipMinMax | styleNoLabel, 40, 60 );
PlotGrid( 60, colorRed, 8); 
PlotGrid( 40, colorGreen, 8);

image

Or for a different look, if you uncomment the lines to visualize the other timeframe RSI's
image

I hope that is of some help, good luck!

3 Likes

@portfoliobuilder, Great. Definitely it will be help. I can do some modifications as per my needs with your input ideas. Thank you.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.