Hi, I’m trying to build an indicator that I can later use in a back test and auto trade that opens positions on the second occurrence of an RSI cross.
So when the RSI crosses above 30 once, the indicator shows 1, then if it dips below and crosses above again (without going above 70), it shows 2 (and I enter long).
If the RSI crosses above 30 once, it show 1, then goes over 70 and crosses back down the indicator shows -1.
Likewise in opposite direction entering short at -2. So I only want to open long when its crosses above 30 a second time and only open short when it crosses below 70 twice in a row without reaching below 30.
Hope that makes sense?
Thanks in advance
Hi, something like that, count is there for visual check, for easier visualisation of separate indicator lines, “result” is set at +0.5 for when buy would occur or -0.5 for short entry
myrsi=RSI[14](close)
result=0
if myrsi crosses over 30 and count=1 then
count=2
result=+0.5
endif
if myrsi crosses over 30 and count=0 then
count=1
endif
if myrsi crosses over 70 and count>0 then
count=0
endif
if myrsi crosses under 70 and count=-1 then
count=-2
result=-0.5
endif
if myrsi crosses under 70 and count=0 then
count=-1
endif
if myrsi crosses under 30 and count<0 then
count=0
endif
return count, result
Excellent, just what I wanted, thank you