Checking conditions in an indicator
Forums › ProRealTime English forum › ProBuilder support › Checking conditions in an indicator
- This topic has 7 replies, 5 voices, and was last updated 5 years ago by GraHal.
-
-
05/09/2019 at 2:01 PM #98079
I wrote an indicator to signal when a price crosses over the middle line (50) of RSI for the first time, but the code I wrote always returns 0 (pic 1):
12345678IF BarIndex < 1 THENMyCond = 0ENDIFMyRsi = Rsi[14](close)IF MyCond = 0 THENMyCond = MyRsi CROSSES OVER 50ENDIFRETURN MyCondI could find this workaround, by adding a dummy condition to test if MyCond=1 (pic 2):
123456789IF BarIndex < 1 THENMyCond = 0ENDIFMyRsi = Rsi[14](close)IF MyCond = 1 THENELSEMyCond = MyRsi CROSSES OVER 50ENDIFRETURN MyCondWhy this behaviour (both on v10.3 and beta v11)?
05/09/2019 at 3:02 PM #9808605/09/2019 at 3:05 PM #98087It seems that from barindex = 0 to 14 the RSI(14) value is undefined. Just do like this:
12345678IF BarIndex < 15 THENMyCond = 0ENDIFMyRsi = Rsi[14](close)IF MyCond = 0 THENMyCond = MyRsi CROSSES OVER 50ENDIFRETURN MyCond05/09/2019 at 3:59 PM #98095It seems that from barindex = 0 to 14 the RSI(14) value is undefined.
This was my first thoughts but even if it is undefined then it should just be a case that myCond = 0 and there is no cross of RSI over 50 during the first 14 bars so MyCond should remain at zero but then once the RSI does have a defined value after 14 bars then MyCond should change to a value of 1 once the first cross of 50 happens – but it never changes.
05/09/2019 at 3:59 PM #98096I can also work it out by clearing MyCond everytime (same as IF BarIndex < 9999999 THEN) :
123456MyCond = 0MyRsi = Rsi[14](close)IF MyCond = 0 THENMyCond = MyRsi CROSSES OVER 50ENDIFRETURN MyCondbut it’s not what I need to do.
Thank you.
05/22/2019 at 10:58 AM #99146Here is the fixed code:
12345678910IF BarIndex < 1 THENMyCond = 0ENDIFMyRsi = Rsi[14](close)IF MyCond = 0 and barindex >= 14 THENMyCond = MyRsi CROSSES OVER 50ENDIFRETURN MyCondThe problem is that the code tries to check the MyRsi CROSSES OVER 50 condition if the barindex is equal to 1.
But at this moment there is not enough candlestick to calculate RSI.
So it returns that mycond = NaN (Not a Number)
And then we never go back into the loop because IF MyCond = 0 is never true.1 user thanked author for this post.
05/22/2019 at 11:03 AM #99148Great Nicolas, thank you!
05/22/2019 at 1:50 PM #99164 -
AuthorPosts
Find exclusive trading pro-tools on