# RSI - condition check above 30 for certain period

Thanks for all the help guys.
In my AFL, i am using my entry time frame as 1 minute and also using 5 min chart for one confirmation .

For shorting purpose I want to make sure that in the last 20 candles of 5 min each, most recently the RSI was above 70 and not below 30. So it might happen that rsi is currently above 70 or not. But I don't want rsi to be below 30 currently or below 30 most recently. In the last 20 candles, RSI might be below 30 but RSI then must have gone above 70 too. If RSI was not above 70 most recently, then scanner should not give me anything.

By recently, you mean "20 bars of 5m"?

Then in you 5m TF chart, use LLV() Lowest Low Value

rsi14 = RSI( 14 );
Lrsi = LLV( rsi14, 20 );

if( LastValue( Lrsi ) > 30) {
// rsi14 never dipped below 30 in latest 20 bars
}
else {
}

Ambiguity is you say using 5m chart for confirmation and then saying scanner shouldn't Filter it.
In spite of the post and conditions still not very clear, i've attempted to address it.

You should instead list the conditions point wise and then explain whether valid or not instead of the paragraph or write a pseudocode trying to explain the flow of conditions.

Go through the forum rules, you'll get better responses.

Very sorry for the confusion. The scanner should signal me in the following cases

1. RSi is currently above 70 or
2. RSI is currently below 70 but recently (in the last 20 candles) it was above 70 and after this RSi did not go below 30.

I don't want a signal in below both these cases.

1. RSI is currently below 30 or
2. RSI went below 30 but did not go above 70 after this.

So in a nutshell, most RECENTY in the last 20 candles RSI should have gone above 70 and not below 30.

@besttrader, then in addition to LLV() you'll also want to review the arithmetic operators =, +, < and > and the logical operator AND may be helpful.
Start here: https://www.amibroker.com/guide/a_language.html
Be sure to post your code so we can all benefit from your efforts.