Stuck with coding indicator about RSI divergences
Forums › ProRealTime English forum › ProBuilder support › Stuck with coding indicator about RSI divergences
- This topic has 10 replies, 3 voices, and was last updated 5 years ago by ladis.
Tagged: divergences
-
-
03/14/2019 at 12:36 PM #93623
Dear All,
I am new to this forum so I don’t know if I am at the right place here so please forgive me if I am wrong. I attatched an printscreen of a FDAX 5′ PRT chart from 14-15/01/2019.
I have an idea for an indicator and someone helped me to code it in PRT but has no more time and the code doesn’t work properly and I don’t know anything about coding and unfortunately, at the moment, don’t have the time to learn it.
I have the following variables: LOW1, LOW2 and LOW3, CLOSE1, CLOSE2 and CLOSE3, RSI1, RSI2 and RSI3
1. With the red candle at 1 the RSI goes below 29 (RSIBottom1). Then the “system” starts and I get a 1st value for the variable RSI1 = the rsi value of that current candle, nml 28.93 so RSI1 = 28.93 This is also linked to a low nml LOW1 = low value of that current candle, here 10881 and also a value for the current close = CLOSE1 = here 10883.5.
2. The following candle has a lower low but a higher close (1 point higher close is enough) and that close is also higher than the “open”. Here the current candle is low <LOW1 and so the value of the variable LOW1 becomes the new low of the current green candle, here 10876.5. So LOW1 = 10876.5 The rsi is not lower so RSI1 remains the same (RSI1 = 28.93). From that close current bar> = CLOSE1 +1 point the candleteller also starts to run (numberofbars) CLOSE1 also remains at the same value (CLOSE1 = 10883.5)
3. With the third candle we have no lower low nor rsi so the values for RSI1 and LOW1 remain the same
4. In the fourth candle the index is about 10896.5 and therefore more than 20 points difference with LOW1 (moveupafterlow). From now on we will search / see if we get a new low that <LOW1 (10881) with a close that <CLOSE1 and rsi> RSI1. The variables CLOSE1, RSI1 and LOW1 remain the same. (Note: If from now on the index should rise so fast that the RSI exceeds 70, the whole system will be canceled and we have to start from the beginning.)
5. The lower low <10881 only arrives at the red candle “2”.
- The low of this red candle to 2 is 10862 this is <LOW1 so we have a value for LOW2;
- The corresponding rsi value of this candle is 31.04 and this is> RSI1 so new variable RSI2 = 31.04 and
- the close of this candle is 10863 what <CLOSE1 so new variable CLOSE2 = 10863 and
- the number of candles is <30 (numerofbars)
All first conditions are met. Now the last one
6. The next candle MUST be a green candle where the close of this green candle> = 10865 (or CLOSE2 +2 points) and it must be a real hammercandle so (high-close) +2 <(open-low) The low of this candle may be <LOW2 but that’s not obligatory.
If all these criteria are met then the indicator should mention “1” AND all variabeles should be reset. Only if thereafter the RSI drops below 29, the system should restart from the beginning.
Hence nothing happens at 4 (1st green candle after 4 is not a hammer), but something should happen at the red 5 because here again there is a lower low (LOW3 <LOW2) and a lower close (CLOSE3 <CLOSE2) and rsi (RSI3> RSI1) and index has risen more than 20 points since LOW2and the green candle 5 is a hammer with close> = CLOSE3 + 2 points.
Ladis out 3123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139//Creating signals based on past divergences. Coding backwards. Check each new candle on the indicated setup.//Building on the 5-min chart//Max length of setup : 40 candles//Version 22feb2019RSIind = RSI[14](close)//Find lowest low in RSI over the last NumberOfBars candlesRSILow1 = Lowest[NumberOfBars](RSIind)IF RSILow1 < RSIBottom1 THEN//reset all valuesNoSignal = 0NoSignalPart1 = 1NoSignalPart2 = 1NoSignalPart3 = 1PriceLow1 = 0PriceClose1 = 0RSIBarindexLow1 = 0PriceClose1NextBar = 0GreenBarCondition = 0BarindexDistanceToHigh = 0MoveUpBarindex = 0RSILow2 = 0PriceLow2 = 0GreenBarClose2Condition = 0//Part 1//find the barindex of the lowest RSI low, to also find the corresponding Price Low//if RSI not below 29, stop calculating => No signalFOR i=0 to NumberOfBars doIF RSIind[i] = RSILow1 THENRSIBarindexLow1 = barindex[i]PriceLow1 = low[i]PriceClose1 = close[i]IF i=0 then//At this point cannot calc the close of next bar, so no signal yetNoSignal = 1ENDIFIF NoSignal = 0 THEN//Calc the Next bar closePriceClose1NextBar = close[i-1]//Addition : If low of this next bar is lower then PriceLow1 then update the lowIF low[i-1] < PriceLow1 THENPriceLow1 = low[i-1]ENDIF//Check if the candle following the 1st low is a green bar -> If not, no signalGreenBarCondition = PriceClose1NextBar - PriceClose1//If the next bar close is not 2 points higher then Close1 then no signalif GreenBarCondition < MinGreenBar1 THENNoSignal = 1endifBREAKENDIFENDIF//If condition is still valid, this section part is DONEIF NoSignal = 0 THENNoSignalPart1 = 0ENDIFNEXT//END Part 1//Part 2 :Find the first Barindex after the RSILow where the distance is 20BarindexDistanceTo1stLow = barindex - RSIBarindexLow1if BarindexDistanceTo1stLow > 0 THENn = BarindexDistanceTo1stLowCount = 0Signal = 0WHILE n <> 0 DOIF High[n-1] - PriceLow1 > MaxUpAfterLow1 THENn = 0Count = Count + 1signal = 1ELSEn = n - 1Count = Count +1ENDIFWENDif signal = 1 THENMoveUpBarindex = RSIBarindexLow1 + CountNoSignalPart2 = 0ELSEMoveUpBarindex = 0NoSignalPart2 = 1ENDIFENDIF//END Part 2//Part 3 : Find RSI2 lowIF NoSignal = 0 and MoveUpBarindex > 0 THENBarindexDistanceToHigh = barindex - MoveUpBarindexIF BarindexDistanceToHigh > 0 THENRSILow2 = Lowest[BarindexDistanceToHigh](RSIind)//Find barindex of the lowest 2nd RSI lowFOR l=0 to BarindexDistanceToHigh doIF RSIind[l] = RSILow2 THENPriceLow2 = low[l]IF l=0 then//Cannot calc the close of next bar at this moment, so no signal yetNoSignal = 1ENDIFIF NoSignal = 0 THEN//Check if the candle following the low is a green one -> If not, no signalGreenBarClose2Condition = close[l-1] - close[l]if GreenBarClose2Condition < MinGreenBar2 THENNoSignal = 1endifENDIFBREAKENDIFNEXT//PriceLow2 must be 2 points lower then pricelow1IF PriceLow1 - PriceLow2 < PriceLowerLow2 THENNoSignal = 1ENDIF//2nd RSI low must be at least 2 points higher then the first low, if not, no signalIF RSILow2 - RSILow1 < RSIHigherLow2 THENNoSignal = 1ENDIFELSENoSignal = 1ENDIFIF NoSignal = 0 THENNoSignalPart3 = 0ENDIFENDIFELSENoSignal = 1ENDIFIF NoSignal = 0 and NoSignalPart1 = 0 and NoSignalPart2 = 0 and NoSignalPart3 = 0 THENAlarm = 1ELSEAlarm = 0ENDIFreturn Alarm as "Alarm"Normally the indicator should also be usable in the 1 “, 10”, 30 “etc …
03/14/2019 at 12:40 PM #9362403/14/2019 at 3:57 PM #93650What about using some code in the library?
https://www.prorealcode.com/prorealtime-indicators/rsi-classical-hidden-divergences-indicator/
https://www.prorealcode.com/topic/rsi-divergence/
1 user thanked author for this post.
03/15/2019 at 10:34 AM #93757Dear Roberto,
Many thanks for your reply. If I try to use the first, my program says that there are coding errors (printscreen)
The second (open source) indeed gives a signal when there is a divergence, but not exactly as my needed specifications.
I want a signal exactly when the requirements are met. In this way I can save serious in-front-of-screen time 🙂
How can I adjust this?
Many thanks for your effort and time!
03/15/2019 at 10:58 AM #93775Those reported errors seem related to some missing/mispelled IF…ELSIF…ENDIF or maybe due too many nested structures, you have several IF’s within a FOR…NEXT structure which belongs to another outside IF…ENDIF.
03/15/2019 at 2:06 PM #93800Dear Roberto,
The printscreen if from when I open the /rsi-classical-hidden-divergences-indicator/
So I don’t know what I do wrong.
I have the same problem when I import other indicators from the library here.
Sometimes it’s ok and sometimes I get an error mention, but unfortunately I don’t know anything about coding.
Do you have any suggestions?
Kind regards,
Ladis
03/15/2019 at 2:45 PM #93807The code runs finely, it’s something missing, check if you did Copy & Paste. Try importing the .ITF file
03/15/2019 at 3:19 PM #9380803/15/2019 at 3:25 PM #9380903/15/2019 at 3:30 PM #9381103/15/2019 at 3:37 PM #93812 -
AuthorPosts
Find exclusive trading pro-tools on