RSI trigger – simplified coding?
Forums › ProRealTime English forum › ProOrder support › RSI trigger – simplified coding?
- This topic has 8 replies, 4 voices, and was last updated 8 years ago by JC_Bywan.
-
-
01/10/2017 at 11:01 AM #20413
Happy New Year all. Wow, the holiday passed quickly.
My brain may be being a bit slow. See the code below. Is there a more efficient way of coding this simple trigger? I was thinking it could also be useful when used with a market scanner to find setups. Eg: scan to find anything with a RSI passing below 70, then have the automated code to trigger when it passes below 70 again.
Apologies if this has been covered in another topic. I had a quick search and couldn’t find anything.
Example product: Platinum. Code PLXXXX. Just end of day data (I think everyone will therefore have access).
Date: Look back to Aug 2016.
Trigger: RSI passing under 70 level to sell 1 lot. Easy so far. However, I’ve seen on a few occasions that the trigger should not be the first “passing under” of the 70 level, instead it is better to wait and see if the break below 70 is real, let it retest the overbought level by returning above 70, and then waiting for it to pass under 70 again (within a specified time period). I hope this makes sense. Just look back at the RSI for Platinum for last Aug and you will see. There is a nice selloff when it passes under 70 the second time. Also note that there is a divergence on 10th Aug: up candle with RSI increasing above 70.
5th Aug: this is the first break under 70 level. Wait and see.
10th Aug: RSI goes back above 70
11th Aug: passes under 70 again. Trigger to sell 1 lot on open of 12th Aug.
Question: can the code be made more efficient instead of manually having to stipulate each indicator[1], indicator[2], indicator….[x]? E.g. if I wanted to look at 5min bars for another product (I’ve nothing in mind at the moment), is it easy to stipulate that instead of looking for RSI breaks 70 level twice within last (say) 5 bars it can be changed to 20 bars easily. Or 50 bars? I hope you get what I mean.
I can’t attach screenshots or files hence this long request.
Any thoughts appreciated. Thanks
12345678910111213141516171819202122232425262728// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter short positionsindicator1 = RSI[14](close)c1 = (indicator1 CROSSES UNDER 70)indicator2 = RSI[14](close)c2 = (indicator2[1] CROSSES UNDER 70)indicator3 = RSI[14](close)c3 = (indicator3[2] CROSSES UNDER 70)indicator4 = RSI[14](close)c4 = (indicator4[3] CROSSES UNDER 70)indicator5 = RSI[14](close)c5 = (indicator5[4] CROSSES UNDER 70)indicator6 = RSI[14](close)c6 = (indicator6[5] CROSSES UNDER 70)IF c1 AND (c2 OR c3 OR c4 OR c5 OR c6) THENSELLSHORT 1 SHARES AT MARKETENDIF// Conditions to exit short positionsindicator7 = RSI[14](close)c7 = (indicator7 CROSSES UNDER 30)IF c7 THENEXITSHORT AT MARKETENDIF01/10/2017 at 5:25 PM #20561You can easily make a summation of how many times the RSI cross below the 70 level in the past X candlesticks:
1234X = 10 //lookback periods to check the RSI crosscount = summation[X](RSI[14](close) crosses under 70)RETURN countIn this example, the ‘count’ variable will give you the sum of the boolean condition under parenthesis that return true.
1 user thanked author for this post.
01/11/2017 at 10:17 AM #20673Thanks Nicolas.
Easy and neat solution.
However I’m having a problem and keep getting a syntax error message. I’ve tried in vain many variations of the code below. I just want it to trigger on occasions where, over the last 5 bars, the 70 level is passed twice. Any chance to you take a look?
I’m preparing to shoot myself for a stupid error 😉
12345678X = 5 //lookback periods to check the RSI crosscount = summation[X](RSI[14](close) crosses under 70)RETURN countIF count = 2SELLSHORT 1 SHARES AT MARKETENDIF01/11/2017 at 10:37 AM #20676Hi,
Your syntax error is because you used “return” (last line of an Indicator in Probuilder module) and “sellshort” (from Probacktest/proorder module to build trading strategies rather than indicators) in the same piece of code.
You can’t mix the 2, you have to choose, either you build an indicator ending with “return” and no buy or sell order, or you build a strategy buying and selling but without “return” line.
But please don’t shoot yourself, we enjoy our forum members staying alive… 🙂
1 user thanked author for this post.
01/11/2017 at 10:56 AM #20677Ah, I get it now. I kinda knew it / I had seen that before. Got it to work now through your help and luck. Perhaps just a graze to a toe?
I hope you don’t mind me putting down my steps here for others to follow:
- Create a new indicator (I’ve named it “# RSI crosses”)
12345// Conditions to enter short positionsX = 5 //lookback periods to check the RSI crosscount = summation[X](RSI[14](close) crosses under 70)RETURN countThis then adds a new indicator at the bottom of the chart.
2. Create a new strategy and get it to reference the “# RSI crosses” indicator. Got the sell trigger where the indicator = 2
123456789101112131415161718// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter short positionsindicator1 = CALL "# RSI crosses"c1 = (indicator1 = 2)IF c1 THENSELLSHORT 1 SHARES AT MARKETENDIF// Conditions to exit short positionsindicator2 = RSI[14](close)c2 = (indicator2 CROSSES UNDER 30)IF c2 THENEXITSHORT AT MARKETENDIF01/12/2017 at 12:46 AM #20805Nice indicator JonJon – I’ve already named it after you…:-)
“Long” Version
// Conditions to enter short positions
X = 5 //lookback periods to check the RSI cross
count = summation[X](RSI[14](close) crosses over 30)RETURN count
1 user thanked author for this post.
01/12/2017 at 1:38 AM #20806Edited “Short” to “Long”
Nice indicator JonJon – I’ve already named it after you…:-)
“Long” Version
// Conditions to enter Long positions
X = 5 //lookback periods to check the RSI cross
count = summation[X](RSI[14](close) crosses over 30)
RETURN count
1 user thanked author for this post.
01/12/2017 at 9:00 AM #2082701/12/2017 at 10:05 AM #20831Thanks Jonjon, that’s very kind of you, especially considering sometimes we answer questions not always easy to solve, and don’t even get a thank you. So you’re very kind and I appreciate it and I wish all forum members were as kind as you all the time, but in this case I didn’t contribute to the logic of the indicator, I only helped quickly with the syntax error. That’s far from enough to put my name on it.
Jonjon or Jonjon-Nicolas indicator sounds good to me if you want a name with names. RSI trigger sounded good too. Maybe Nicolas would agree that “Jonjon RSI trigger” could be best name choice. To be honest after you’ve developped a few, you’ll soon find out naming an indicator with a hint on its function rather than a hint on every single person who contributed to it will go a long way to find it faster in your PRT personal indicators list.
-
AuthorPosts
Find exclusive trading pro-tools on