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
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter short positions
indicator1 = 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) THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
// Conditions to exit short positions
indicator7 = RSI[14](close)
c7 = (indicator7 CROSSES UNDER 30)
IF c7 THEN
EXITSHORT AT MARKET
ENDIF