the solution was so simple.
bool FirstTouchLevel20() { int Lvl20TouchCount = 0; for(int i = 1; i <= 100; i++) { double rsi = iRSI(Symbol(), Period(), 14, 0, i); if(rsi <= 20) { Lvl20TouchCount++; } if(rsi >= 50.0) { break; } } return (Lvl20TouchCount == 1); }
Omran Alturk #:
You Said to count only when it comes down from 50 to 20… this means if now is 51 and it comes down to 19 you count one … if is going up to 21 and come down again to 19 you count again… it shouldn’t … you said to count only when it comes from above 50…
No it does, i checked it, but i will be appreciate if you could give another solution because i think it is cranky.
Exactly. So do it, exactly that, but forward in time.
bool FirstTouchLevel20() { enum State{eInit, eEnabled, eFirst, eFirstDone, eSecond }; State s=eInit; for(int i = 100; i > 0; --i) { double rsi = iRSI(Symbol(), Period(), 14, 0, i); if(rsi >= 50) s=Enabled; // Reset, above 50. if(s == eInit) continue; // No above 50 yet. if(rsi > 20){ if(s==eFirst) s=eFirstDone; // Touch complete. continue; } // Not touching yet. if(s == eEnabled) s=eFirst; // Second touch w/o reset. else s=eSecond; } return s==isFirst || s==eFirstDone; // Saw 50, saw 20, not above 50, no second touch. }
Or maybe like this?
void FirstTouch() { int static flagabove50 =0; bool firsttouch =false; double rsi=iRSI(_Symbol,_Period,6,PRICE_CLOSE,1); if(rsi>=50) flagabove50=1; if(rsi<20 && flagabove50==1) { firsttouch=true; flagabove50=0; } Print("rsi",rsi); Print("flag=",flagabove50); Print("firsttouch",firsttouch); }
Thank you guys, that was very helpful.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi everyone,
i want to check when RSI cross some level (let say 20) for the first time after it came down from level 50,
the second cross to same level i dont want it just the first one, and this is my attempt: