Stuck with coding indicator about RSI divergences

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #93623 quote
    ladis
    Participant
    Junior
    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”.

    1.  The low of this red candle to 2 is 10862 this is <LOW1 so we have a value for LOW2; 
    2. The corresponding rsi value of this candle is 31.04 and this is> RSI1 so new variable RSI2 = 31.04 and 
    3. the close of this candle is 10863 what <CLOSE1 so new variable CLOSE2 = 10863 and
    4. 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.
    //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 22feb2019
    
    RSIind = RSI[14](close)
    
    //Find lowest low in RSI over the last NumberOfBars candles
    RSILow1 = Lowest[NumberOfBars](RSIind)
    
    IF RSILow1 < RSIBottom1 THEN
    //reset all values
    NoSignal = 0
    NoSignalPart1 = 1
    NoSignalPart2 = 1
    NoSignalPart3 = 1
    PriceLow1 = 0
    PriceClose1 = 0
    RSIBarindexLow1 = 0
    PriceClose1NextBar = 0
    GreenBarCondition = 0
    BarindexDistanceToHigh = 0
    MoveUpBarindex = 0
    RSILow2 = 0
    PriceLow2 = 0
    GreenBarClose2Condition = 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 signal
    FOR i=0 to NumberOfBars do
    IF RSIind[i] = RSILow1 THEN
    RSIBarindexLow1 = 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 yet
    NoSignal = 1
    ENDIF
    IF NoSignal = 0 THEN
    //Calc the Next bar close
    PriceClose1NextBar = close[i-1]
    //Addition : If low of this next bar is lower then PriceLow1 then update the low
    IF low[i-1] < PriceLow1 THEN
    PriceLow1 = low[i-1]
    ENDIF
    //Check if the candle following the 1st low is a green bar -> If not, no signal
    GreenBarCondition = PriceClose1NextBar - PriceClose1
    //If the next bar close is not 2 points higher then Close1 then no signal
    if GreenBarCondition < MinGreenBar1 THEN
    NoSignal = 1
    endif
    BREAK
    ENDIF
    ENDIF
    //If condition is still valid, this section part is DONE
    IF NoSignal = 0 THEN
    NoSignalPart1 = 0
    ENDIF
    NEXT
    //END Part 1
    
    //Part 2 :Find the first Barindex after the RSILow where the distance is 20
    BarindexDistanceTo1stLow = barindex - RSIBarindexLow1
    if BarindexDistanceTo1stLow > 0 THEN
    n = BarindexDistanceTo1stLow
    Count = 0
    Signal = 0
    WHILE n <> 0 DO
    IF High[n-1] - PriceLow1 > MaxUpAfterLow1 THEN
    n = 0
    Count = Count + 1
    signal = 1
    ELSE
    n = n - 1
    Count = Count +1
    ENDIF
    WEND
    if signal = 1 THEN
    MoveUpBarindex = RSIBarindexLow1 + Count
    NoSignalPart2 = 0
    ELSE
    MoveUpBarindex = 0
    NoSignalPart2 = 1
    ENDIF
    ENDIF
    //END Part 2
    
    //Part 3 : Find RSI2 low
    IF NoSignal = 0 and MoveUpBarindex > 0 THEN
    BarindexDistanceToHigh = barindex - MoveUpBarindex
    IF BarindexDistanceToHigh > 0 THEN
    RSILow2 = Lowest[BarindexDistanceToHigh](RSIind)
    //Find barindex of the lowest 2nd RSI low
    FOR l=0 to BarindexDistanceToHigh do
    IF RSIind[l] = RSILow2 THEN
    PriceLow2 = low[l]
    
    IF l=0 then
    //Cannot calc the close of next bar at this moment, so no signal yet
    NoSignal = 1
    ENDIF
    IF NoSignal = 0 THEN
    //Check if the candle following the low is a green one -> If not, no signal
    GreenBarClose2Condition = close[l-1] - close[l]
    if GreenBarClose2Condition < MinGreenBar2 THEN
    NoSignal = 1
    endif
    ENDIF
    BREAK
    ENDIF
    NEXT
    
    //PriceLow2 must be 2 points lower then pricelow1
    IF PriceLow1 - PriceLow2 < PriceLowerLow2 THEN
    NoSignal = 1
    ENDIF
    //2nd RSI low must be at least 2 points higher then the first low, if not, no signal
    IF RSILow2 - RSILow1 < RSIHigherLow2 THEN
    NoSignal = 1
    ENDIF
    ELSE
    NoSignal = 1
    ENDIF
    IF NoSignal = 0 THEN
    NoSignalPart3 = 0
    ENDIF
    ENDIF
    ELSE
    NoSignal = 1
    ENDIF
    
    IF NoSignal = 0 and NoSignalPart1 = 0 and NoSignalPart2 = 0 and NoSignalPart3 = 0 THEN
    Alarm = 1
    ELSE
    Alarm = 0
    ENDIF
    
    return Alarm as "Alarm"
      Normally the indicator should also be usable in the 1 “, 10”, 30 “etc …
    #93624 quote
    ladis
    Participant
    Junior
    I hereby resend the printscreen
    Test-indicator-uitleg.jpg Test-indicator-uitleg.jpg
    #93650 quote
    robertogozzi
    Moderator
    Master
    #93757 quote
    ladis
    Participant
    Junior
    Dear 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!
    2019-03-15-2.png 2019-03-15-2.png printscreen.jpg printscreen.jpg Ladis_Indicator_out3.itf
    #93775 quote
    robertogozzi
    Moderator
    Master
    Those 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.
    #93800 quote
    ladis
    Participant
    Junior
    Dear 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
    #93807 quote
    robertogozzi
    Moderator
    Master
    The code runs finely, it’s something missing, check if you did Copy & Paste. Try importing the .ITF file
    #93808 quote
    ladis
    Participant
    Junior
    I imported te itf file. I will try to copy and paste.
    #93809 quote
    ladis
    Participant
    Junior
    I tried thaty but it didn’t work. I imported it and then applied on “validate program” and then the error box opens?! (see printscreen)
    printscreen-2.jpg printscreen-2.jpg
    #93811 quote
    Vonasi
    Moderator
    Master
    Which version of PRT are you using? I think it needs to be 10.3 for the graphic instructions to work.
    #93812 quote
    ladis
    Participant
    Junior
    V10.2 It comes with my brokers (Binckbank) software Thank you.
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

Stuck with coding indicator about RSI divergences


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
ladis @ladis Participant
Summary

This topic contains 10 replies,
has 3 voices, and was last updated by ladis
6 years, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/14/2019
Status: Active
Attachments: 5 files
Logo Logo
Loading...