Modified RSI formula in Amibroker (AB) - Aussie Stock Forums

# Thread: Modified RSI formula in Amibroker (AB)

1. ## Modified RSI formula in Amibroker (AB)

Hi all
I am new to AB and am wanting to scan over selected periods (eg 1 year up to 10 years) a stock or set of stocks to only return:

a. the day after RSI is less than 30 with closing price, and

b. the day after RSI is greater than 70 with opening price.

Is this possible and can anyone assist with the code?

Marty

2. ## Re: Modified RSI formula in Amibroker (AB)

Do you mean something like the following?

COND1 = Ref(RSI(14),-1) < 30;
COND2 = Ref(RSIa(O,14),-1) > 70;

3. ## Re: Modified RSI formula in Amibroker (AB)

Originally Posted by AlterEgo
Do you mean something like the following?

COND1 = Ref(RSI(14),-1) < 30;
COND2 = Ref(RSIa(O,14),-1) > 70;
Hi Alterego

Thank you for your quick response.

As I said previously I new at this and not sure. I have tried to insert your suggestion into analyser and get a message to insert a Buy filter.

Any thoughts? When I tested RSI(14)< 30 what returned was every close value that meet the condition which could be quite large while the RSI stays below 30. What I am wanting is only the second day that meets the condition,(ie if condition is first met on say yesterday 10 May 2011 then I want the close for today 11 May 2011) Can this be done? And similarly for a sell (ie RSI (14) >70. So for any stock the report should have something like:

BHP........Sell............12/3/11.....................46.23
RIO........Sell............16/4/11.....................85.75

Many thanks

Marty

4. ## Re: Modified RSI formula in Amibroker (AB)

Any thoughts? When I tested RSI(14)< 30 what returned was every close value that meet the condition which could be quite large while the RSI stays below 30. What I am wanting is only the second day that meets the condition,(ie if condition is first met on say yesterday 10 May 2011 then I want the close for today 11 May 2011)
I'm still not quite sure what you're trying to do. The stock could stay below 30 for many days, so do you want the close of every day while it's below 30? But then you said "only the second day that meets the condition" - so are you looking for 2 consecutive days below 30??

What buy and sell conditions are you trying to do? Buy on a cross below 30, and sell on a cross above 70? If so, why are you waiting to buy on the following close after the entry signal (instead of at the open), while you're exiting on the open the day following the sell signal? Or have I misunderstood?

5. ## Re: Modified RSI formula in Amibroker (AB)

Originally Posted by AlterEgo
I'm still not quite sure what you're trying to do. The stock could stay below 30 for many days, so do you want the close of every day while it's below 30? But then you said "only the second day that meets the condition" - so are you looking for 2 consecutive days below 30??

What buy and sell conditions are you trying to do? Buy on a cross below 30, and sell on a cross above 70? If so, why are you waiting to buy on the following close after the entry signal (instead of at the open), while you're exiting on the open the day following the sell signal? Or have I misunderstood?
Hi again Alterego

Thanks again for following up on my query. I must not have been clear enough and as you correctly stated the "The stock could stay below 30 for many days". So what I am wanting to is to buy on the second day's close after the stock crosses below 30 on its on its RSI. And similarly I want to sell on the second day's open after the stock has crossed above 70 on its RSI. Is that any clearer?

Marty

6. ## Re: Modified RSI formula in Amibroker (AB)

Well if I understand you correctly, and say Day 1 is the day that the RSI crosses below 30, and you're wanting to buy on Day 2 close, and for the sell if Day 1 is the day the RSI crosses above 70 and you want to sell the next Open, then I think you'd want something like:

Sell = Cross(RSI(14),70);

SellPrice = Open;

7. ## Re: Modified RSI formula in Amibroker (AB)

Originally Posted by AlterEgo
Well if I understand you correctly, and say Day 1 is the day that the RSI crosses below 30, and you're wanting to buy on Day 2 close, and for the sell if Day 1 is the day the RSI crosses above 70 and you want to sell the next Open, then I think you'd want something like:

Sell = Cross(RSI(14),70);

SellPrice = Open;
Hi again Alterego

You have done great. Unfortunately I hadn't accounted for the situation where the RSI may cross the 30 level more than once before it then crosses the 70 level. So what would be perfect is if the first buy opportunity is returned and then followed by the first sell opportunity. Your code returned every time the RSI crossed below 30 before it then crossed the 70 level. And similarly it returned every time the RSI crossed above the 70 level before it then crossed below the 30 level. I would like to eliminate all but the first occasion that the RSI crosses the 30 level and then the 70 level remembering that I want the buy to be the close of the day after the crossing the 30 level and the sell to be the open of the day after the RSI crosses the 70 level.

Hope I am clear this time. It is just isolating the first occurrences for buy and sell.

Much appreciation

Marty

8. ## Re: Modified RSI formula in Amibroker (AB)

Try adding the following 2 lines to the bottom of the code. This removes excess trade signals.

9. ## Re: Modified RSI formula in Amibroker (AB)

Originally Posted by AlterEgo
Try adding the following 2 lines to the bottom of the code. This removes excess trade signals.

Hi Alterego

You're a genius! It works... Can you enlighten me on two points:

a. can you explain what do the ones in SetTradeDelays(1,1,1,1); actually relate to...and

Once again thank you and well done.

Much appreciated ...

Marty

10. ## Re: Modified RSI formula in Amibroker (AB)

Hi Alterego

You're a genius! It works... Can you enlighten me on two points:

a. can you explain what do the ones in SetTradeDelays(1,1,1,1); actually relate to...and

Once again thank you and well done.

Much appreciated ...

Marty
Hi Marty,

SetTradeDelays(1,1,1,1) delays the entry and exit by 1 day from when the trade signal is given. So the RSI cross occurs today, it enters tomorrow. The first 1 is the Buy Delay, the next is the Sell Delay, then Short Delay, then Cover Delay.

The ExRem lines remove all excess buy & sell signals. Ie, it gives you the first buy signal, followed by the next sell signal, then next buy signal, etc. So removes any extra signals in between. So it will only buy once, and won't produce another buy signal until it's had a sell signal first, and won't produce another sell signal until there's been a buy signal first.

11. ## Re: Modified RSI formula in Amibroker (AB)

Originally Posted by AlterEgo
Hi Marty,

SetTradeDelays(1,1,1,1) delays the entry and exit by 1 day from when the trade signal is given. So the RSI cross occurs today, it enters tomorrow. The first 1 is the Buy Delay, the next is the Sell Delay, then Short Delay, then Cover Delay.

The ExRem lines remove all excess buy & sell signals. Ie, it gives you the first buy signal, followed by the next sell signal, then next buy signal, etc. So removes any extra signals in between. So it will only buy once, and won't produce another buy signal until it's had a sell signal first, and won't produce another sell signal until there's been a buy signal first.
HI Alterego

Many thanks for your insights and explanation. If I can indulge and ask your thoughts on where can I get started on the programming journey for AFL given I am a newbie.

Cheers and thanks again

Marty

12. ## Re: Modified RSI formula in Amibroker (AB)

HI Alterego

Many thanks for your insights and explanation. If I can indulge and ask your thoughts on where can I get started on the programming journey for AFL given I am a newbie.

Cheers and thanks again

Marty
"Introduction to AmiBroker" book, by Howard Bandy
see http://www.blueowlpress.com/

and of course, the Amibroker manual which you should already have I assume.

13. ## Re: Modified RSI formula in Amibroker (AB)

Originally Posted by AlterEgo
"Introduction to AmiBroker" book, by Howard Bandy
see http://www.blueowlpress.com/

and of course, the Amibroker manual which you should already have I assume.
Hi Alterego

Once again many thanks for your assistance and info.

Regards

Marty

14. ## Re: Modified RSI formula in Amibroker (AB)

This weekly RSI divergence code is available at Amibroker library and because I have a trade in NFE at the moment which reflects the low turning point, this is what it looks like over a longer period. Since it is on the right hand side of the screen and a real money trade, whatever happens from here in reference to the divergence will stay true or be changed by the participants.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Aussie Stock Forums