RSI SAB strategy
Forums › ProRealTime English forum › ProOrder support › RSI SAB strategy
- This topic has 8 replies, 2 voices, and was last updated 8 years ago by Nicolas.
-
-
05/24/2016 at 10:24 AM #7859
Hey guys!
When i trade manually I use the RSI indicator with self adjusting bands tho it´s much more accurate than the standard RSI. Is there someone who whant to help me code a automatic trading with this indicator.
Something that i think had been nice is that for example: To buy long = Rsi have to be 28 and when it goes up to 31 then buy long.
And the same for short. First 72 and when it crosses under 69 then sellshort.
Anyone who has an idea how to do this? 🙂
05/24/2016 at 11:51 AM #786605/24/2016 at 7:00 PM #7907Thanks for your response Nicolas.
That´s right. I want the code to registrate when price hits rsi 32 and after that have happened and when price hits rsi 28 i want it to buy long. – Exit long when rsi hits 70.
And I want the code to registrate when price hits rsi 72 and after when it hits rsi 69 then sellshort. Exit short when rsi hits 30.
I think that I have seen a similar code somewhere before but I don´t remember where, the big difference as I see it is also that I want to do it with RSI with self adjusting band.
05/24/2016 at 7:09 PM #7911Ok so it’s a bit more complicated than a simple cross of the higher and lower bands. If you need to “registrate” that RSI has already visit a level before taking the decision to launch a trade, we need to make a loop in the past to see if it’s true. So what we also need is how much bars in the past would you like to fetch is the RSI has visited the 72 level for example?
05/25/2016 at 7:46 PM #802305/25/2016 at 9:42 PM #804105/26/2016 at 8:56 AM #8070Hello, here is the code of this strategy. I like mean reversion, this is my favourite concept in trading, I’m not so in love with trend following I must admit.
Your idea to count how much bars were above or below the auto-adjusted bands which act as dynamic overbought/oversold levels is quiet interesting. Please find below and attached the code. I let you test and propose improvement if any.
12345678910111213141516171819202122232425262728293031323334353637383940defparam cumulateorders = false//parametersP = 14 //RSI perioddev = 1.8 //deviation factorminbarcount = 5 //quantity of bars that the RSI needs to be above or below its bands//RSI SABrsiplus = RSI[P](close)bsup = 50+ (dev*STD(rsiplus))binf = 50 - (dev*STD(rsiplus))//RSI above buylevel and selllevel countcountB = 0countS = 0for i = 0 to minbarcount doif rsiplus[i]>bsup[i] thencountB=countB+1elsif rsiplus[i]<binf[i] thencountS=countS+1endifnext//case BUYif rsiplus crosses over binf and countS>=minbarcount thenBUY 1 SHARE AT MARKETendifif longonmarket and rsiplus>=70 thenSELL AT MARKETendif//case SELLif rsiplus crosses under bsup and countB>=minbarcount thenSELLSHORT 1 SHARE AT MARKETendifif shortonmarket and rsiplus<=30 thenEXITSHORT AT MARKETendif06/01/2016 at 12:12 AM #8556Hello again!
Sorry for late answer. Thanks alot! I´ve looked at the code and it looks good. If you switch buy-sell with sellshort-exitshort you will get a better result.
I came up with an another idea that i think will work better.
Since the self adjusting Rsi adjust its upper and lower band when the price is oversold or overbought it dosen´t really make sense to have any RSI numbers in the code. It should be something like=
//Longside
If price cross under lowerband and within 5 bars cross over lowerband then
Buy one contract
If price cross over upperband then
Sell one contract
//Shortside
If price cross over upperband and within 5 bars cross under upperband then
Sellshort one contract
If price cross under lowerband then
Exitshort one contract
What do you think about that?
06/01/2016 at 8:26 AM #8559Well, it would not make a lot of difference I believe, but here is the code changed accordingly to this modified exit rule:
12345678910111213141516171819202122232425262728293031323334353637383940defparam cumulateorders = false//parametersP = 14 //RSI perioddev = 1.8 //deviation factorminbarcount = 5 //quantity of bars that the RSI needs to be above or below its bands//RSI SABrsiplus = RSI[P](close)bsup = 50+ (dev*STD(rsiplus))binf = 50 - (dev*STD(rsiplus))//RSI above buylevel and selllevel countcountB = 0countS = 0for i = 0 to minbarcount doif rsiplus[i]>bsup[i] thencountB=countB+1elsif rsiplus[i]<binf[i] thencountS=countS+1endifnext//case BUYif rsiplus crosses over binf and countS>=minbarcount thenBUY 1 SHARE AT MARKETendifif longonmarket and rsiplus>=bsup thenSELL AT MARKETendif//case SELLif rsiplus crosses under bsup and countB>=minbarcount thenSELLSHORT 1 SHARE AT MARKETendifif shortonmarket and rsiplus<=binf thenEXITSHORT AT MARKETendif -
AuthorPosts
Find exclusive trading pro-tools on