AFL multi time frame explorer : Need help

Hi All,

I want to write an explorer to identify the scripts whose RSI in 5 min time frame >70 and RSI in 30 min time frame>70.
I wrote a code. It is returning scripts RSI for 5 min and RSI for 30 mins showing as same value. Checked the chart, it is showing daily RSI.
Please see the code here :

TimeFrameSet( in5Minute ); 
rs5=RSI(14);
TimeFrameSet( in30Minute );
rs30=RSI(14);
Filter=rs5>70 AND rs30>70;
AddColumn( rs5, "5 min rsi" );
AddColumn( rs1h, "1 hr rsi" );

Your help will be appreciated. Experts, can you guide me.

Moderator comment: Before posting you need to read How to use this site. Your code was improperly formatted and I had to edit it.

@snbarma Your code is wrong.

Read and learn the proper use of multiple time frames. Here are well documented examples to guide you,
https://www.amibroker.com/guide/h_timeframe.html

You should learn about
TimeFrameRestore()
and
TimeFrameExpand

I never use this but it a few minutes of reviewing the documentation, here is a possible sample (forgot to include it in my answer)

TimeFrameSet( in5Minute ); // switch to 5 minute time frame 
rs5=RSI(14);
TimeFrameRestore(); // restore time frame to original

TimeFrameSet( 2*in15Minute ); // switch to 30 minute time frame
rs30=RSI(14);
TimeFrameRestore(); // restore time frame to original 

// Charting //
Plot( TimeFrameExpand( rs5, in5Minute), "RSI(14) from 5 min bars", colorWhite, styleDashed ); 
Plot( TimeFrameExpand( rs30, 2*in15minute), "RSI(14) from 30 min bars", colorRed, styleThick );

image

1 Like

Thanks for your reply. I modified the code as below:

TimeFrameSet( in5Minute );
rs5=RSI(15);
TimeFrameRestore();

TimeFrameSet( inHourly );
rs1h=RSI(15);
TimeFrameRestore();

rs55=TimeFrameExpand( rs5, in15Minute);
rs11=TimeFrameExpand( rs1h, inHourly);

Filter=rs55>60 AND rs11>60;
AddColumn( rs55, "5 min rsi" );
AddColumn( rs11, "1 hr rsi" );

Still the output is showing same value for rs55 (5 min RSI) & rs11 (1 hour RSI).
Output :

image

Please have a look.

There is one typo…

The line written is:
rs55=TimeFrameExpand( rs5, in15Minute)

should be
rs55=TimeFrameExpand( rs5, in5Minute);

1 Like

I also tried the code provided here. RSIs on Chart is showing fine, but filtering on those 2 RSIs does not work and even RSIs values in added columns not showing correctly.

Can you guide me pl.

Code:
TimeFrameSet( in5Minute ); // switch to 5 minute time frame
rs5=RSI(14);
TimeFrameRestore(); // restore time frame to original

TimeFrameSet( 2*in15Minute ); // switch to 30 minute time frame
rs30=RSI(14);
TimeFrameRestore(); // restore time frame to original

// Charting //
a=TimeFrameExpand( rs5, in5Minute);
b= TimeFrameExpand( rs30, 2in15Minute);
Plot( TimeFrameExpand( rs5, in5Minute), "RSI(14) from 5 min bars", colorBlue, styleDashed );
Plot( TimeFrameExpand( rs30, 2
in15Minute), "RSI(14) from 30 min bars", colorRed, styleThick );

Filter=rs5>60 AND rs30>60;
//Filter=a>60 AND b>60;
//I tried this one also. Still showing same value in both columns(5 Mins RSI & 30 Mins RSI) though chart shows two different RSIs.
//filtering does NOT happen properly.

AddColumn(a, "RSI(14) from 5 min bars" );
//AddColumn(rs5, "RSI(14) from 5 min bars" );
//** this also did not work//

AddColumn(b, "RSI(14) from 30 min bars");
//AddColumn(rs30, "RSI(14) from 30 min bars" );
//** this also did not work

image

1 Like

Is there even more ignorance possible? I guess it is the ultimate one been seen so far. Would you please care to read How to use this site! @Tomasz has added a comment in first post of this thread and you still don’t even bother to read it. It is amazing.


BTW, in your first post you were writing

to identify the scripts whose RSI in 5 min time frame >70 …

Since we are talking about programming software here a script is a piece of code, a program! See Meaning of “script”. Instead the one that you actually mean is ticker or symbol! Please write proper English that is understood by everyone. But please don’t invent new meanings that don’t exist and may cause confusion. Thank you!


And last but not least… the reason of why result output shows same values in your analysis is a simple one (it has been posted two times in different threads already):
Analysis interval setting is independently set from chart interval!
So just go to Analysis settings -> General <- tab and choose -> Periodicity <- there.

In your case it would have to be minimum 5-min. Since you are applying timeframe functions on 5-min interval too just set to minimum 1-min interval in analysis settings.

And another hint… if you want to know the set analysis interval being applied on each exploration run then simply add a line of AddTextColumn() to your code (-> script).

So,

AddTextColumn( Interval(2), "Set Interval", 1 );
3 Likes

Fixed code:

/// @link https://www.amibroker.com/guide/h_timeframe.html
/// discussed topic at 
/// @link http://forum.amibroker.com/t/afl-multi-time-frame-explorer-need-help/2484/7

/// Setting time frames
/// @link https://www.amibroker.com/guide/afl/timeframeset.html
/// @link https://www.amibroker.com/guide/afl/timeframerestore.html
tf1 = in5Minute;
TimeFrameSet( tf1 ); // switch to 5 minute time frame
rs5 = RSI(14);
TimeFrameRestore(); // restore time frame to original

tf2 = 2*in15Minute;
TimeFrameSet( tf2 ); // switch to 30 minute time frame
rs30 = RSI(14);
TimeFrameRestore(); // restore time frame to original

/// Expanding to original interval
/// @link https://www.amibroker.com/guide/afl/timeframeexpand.html
expandmode = expandLast;
rs5 = TimeFrameExpand( rs5, tf1, expandmode );
rs30 = TimeFrameExpand( rs30, tf2, expandmode);

// Plotting
Plot( rs5, "RSI(14) from 5 min bars", colorBlue, styleDashed );
Plot( rs30,"RSI(14) from 30 min bars", colorRed, styleThick );

// Analysis
Filter = rs5 > 60 AND rs30 > 60;

AddTextColumn( Interval(2), "Set Interval", 1 );
AddColumn(rs5, "RSI(14) from 5 min bars" );
AddColumn(rs30, "RSI(14) from 30 min bars");
5 Likes

Hi fxshrat,

Thanks for your help. Hope to become an expert like you one day.
I am very new to Amibroker, to be precise 3 days old. Navigation, basic fundamentals I am going thru now.

The main thing is, the pointers you have given seem to be working properly. There is a slight difference in data output, I am looking into those.

Thanks again for the great help.

The fact that you are new does not free you from READING. You have ignored forum rules a number of times even being reminded about your wrong doings. Your account is suspended for 2 weeks for totally ignoring forum rules.
If you fail to follow rules after two weeks you will be kicked out, especially considering the fact that you are “free rider” who did not purchase the software.

1 Like

Hi there,
I was intrigued by the STOCKS & COMMODITIES 2015 Jul issue on the SlowRSI and was thinking of making a weekly version of that. Luckily Thomas and fxshrat already did the hard work so this was easily done. However, when I test it using a filter to look for when the indicator is above 60, the result does not match the plot. I've check it quite a lot time but still couldn't figure out what's wrong so would appreciate any help on this.

Thanks a million

/ use current symbol close 
price = Close; 

// but can use other security data too 
// price =  Foreign( "?SPX", "C" ); 

R1 = EMA( price, periods ); 
R2 = IIf( price > r1, price - R1, 0 ); 
R3 = iIf( price < r1, r1 - price, 0 ); 
R4 = Wilders( R2, smooth ); 
R5 = Wilders( R3, smooth ); 
SRSI = IIf( R5 == 0, 100, 100 - ( 100 / ( 1 + ( R4 / R5 ) ) ) ); 

TF1 = inWeekly;
TimeFrameSet(TF1);
SRSIWK = SRSI;
TimeFrameRestore();
expandmode = expandLast;
SRSIWK = TimeFrameExpand( SRSIWK, TF1, expandmode );

Filter = SRSIWK > 60 ;
AddColumn(SRSIWK,"SRSIWK",1);

Plot( SRSIWK, "SRSIWK" , ParamColor("SRSIWK",colorCycle),ParamStyle("Style"));

image

image