Conversion Indicateur RSI cyclic smoothed v2 de TV à PRT

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #240510 quote
    Med5
    Participant
    Junior

    Bonjour à toute l’équipe ProRealCode,

    Tout d’abord, merci pour votre travail exceptionnel et votre contribution à la communauté ProRealTime.

    SVP est il possible de convertir cet indicateur TradingView en ProRealTime : Lien vers l’indicateur TV. De plus, serait-il envisageable d’y ajouter des divergences haussières et baissières (ligne verte et rouge) similaires à celles décrites dans cet indicateur RSI de votre forum : Lien vers l’indicateur PRT.

    Cet outil serait précieux pour identifier les renversements. Merci d’avance pour votre aide !

    Cordialement,

    //@version=4
    // 
    // Copyright (C) 2017 CC BY, whentotrade / Lars von Thienen
    // Source:
    // Book: Decoding The Hidden Market Rhythm - Part 1: Dynamic Cycles (2017)
    // Chapter 4: "Fine-tuning technical indicators for more details on the cRSI Indicator
    // 
    // Usage: 
    // You need to derive the dominant cycle as input parameter for the cycle length as described in chapter 4.
    //
    // License: 
    // This work is licensed under a Creative Commons Attribution 4.0 International License.
    // You are free to share the material in any medium or format and remix, transform, and build upon the material for any purpose, 
    // even commercially. You must give appropriate credit to the authors book and website, provide a link to the license, and indicate 
    // if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. 
    //
    study(title="RSI cyclic smoothed", shorttitle="cRSI")
    src = close
    domcycle = input(20, minval=10, title="Dominant Cycle Length")
    crsi = 0.0
    cyclelen = domcycle / 2
    vibration = 10
    leveling = 10.0
    cyclicmemory = domcycle * 2
    //set min/max ranges?
    
    h1 = hline(30, color=color.silver, linestyle=hline.style_dashed)
    h2 = hline(70, color=color.silver, linestyle=hline.style_dashed)
    
    torque = 2.0 / (vibration + 1)
    phasingLag = (vibration - 1) / 2.0
    
    up = rma(max(change(src), 0), cyclelen)
    down = rma(-min(change(src), 0), cyclelen)
    rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
    crsi := torque * (2 * rsi - rsi[phasingLag]) + (1 - torque) * nz(crsi[1])
    
    lmax = -999999.0
    lmin = 999999.0
    for i = 0 to cyclicmemory - 1 by 1
        if nz(crsi[i], -999999.0) > lmax
            lmax := nz(crsi[i])
            lmax
        else
            if nz(crsi[i], 999999.0) < lmin
                lmin := nz(crsi[i])
                lmin
    
    mstep = (lmax - lmin) / 100
    aperc = leveling / 100
    
    db = 0.0
    for steps = 0 to 100 by 1
        testvalue = lmin + mstep * steps
        above = 0
        below = 0
        for m = 0 to cyclicmemory - 1 by 1
            below := below + iff(crsi[m] < testvalue, 1, 0)
            below
    
        ratio = below / cyclicmemory
        if ratio >= aperc
            db := testvalue
            break
        else
            continue
    
    ub = 0.0
    for steps = 0 to 100 by 1
        testvalue = lmax - mstep * steps
        above = 0
        for m = 0 to cyclicmemory - 1 by 1
            above := above + iff(crsi[m] >= testvalue, 1, 0)
            above
    
        ratio = above / cyclicmemory
        if ratio >= aperc
            ub := testvalue
            break
        else
            continue
    
    
    lowband = plot(db, "LowBand", color.aqua)
    highband = plot(ub, "HighBand", color.aqua)
    fill(h1, h2, color=color.silver, transp=90)
    fill(lowband, highband, color=color.gray, transp=90)
    plot(crsi, "CRSI", color.fuchsia)
    
    #240537 quote
    Iván González
    Moderator
    Master

    Voici ce que vous avez :

    //-------------------------------------//
    //PRC_RSI Cyclic Smoothed
    //version = 0
    //19.11.2024
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-------------------------------------//
    //Inputs
    //-------------------------------------//
    src=close
    domcycle=20 
    cyclelen=domcycle/2
    vibration=10
    leveling=10
    cyclicmemory=domcycle*2
    
    once crsi=0
    //-------------------------------------//
    // CRSI calculation
    //-------------------------------------//
    torque=2/(vibration+1)
    phasinglag=floor((vibration-1)/2)
    
    length = cyclelen
    alpha = 1/length
    
    srcUp = max(src-src[1],0)
    if barindex = length then
    up = average[length](srcUp)
    else
    up = alpha*srcUp + (1-alpha)*up[1]
    endif
    
    srcDw = -min(src-src[1],0)
    if barindex = length then
    dw = average[length](srcdw)
    else
    dw = alpha*srcdw + (1-alpha)*dw[1]
    endif
    
    if dw=0 then
    myrsi=100
    elsif up=0 then
    myrsi=0
    else
    myrsi=100-100/(1+up/dw)
    endif
    if barindex>cyclicmemory then
    crsi=torque*(2*myrsi-myrsi[phasinglag])+(1-torque)*crsi[1]
    endif
    //-------------------------------------//
    // LowBand and HighBand calculation
    //-------------------------------------//
    Period=cyclicMemory
    percent = leveling/100
    periodMinusone = period-1
    maxima = -999999.0
    minima =  999999.0
    
    for i=0 to periodMinusone do
    
    if crsi[i] > maxima then
    maxima = crsi[i]
    elsif crsi[i] < minima then
    minima = crsi[i]
    endif
    next
    
    stepfactor = (maxima-minima)/100
    lowband = 0
    
    for steps=0 to 100 do
    testvalue = minima+stepfactor*steps
    below=0
    for m=0 to periodMinusone do
    if crsi[m]<testvalue then
    below=below+1
    endif
    next
    if below/period >= percent then
    lowband = testvalue
    break
    endif
    next
    
    highband=0
    for steps=0 to 100 do
    testvalue=maxima-stepfactor*steps
    above=0
    for m=0 to periodMinusone do
    if crsi[m]>=testvalue then
    above=above+1
    endif
    next
    if above/Period >= percent then
    highband=testvalue
    break
    endif
    next
    colorbetween(highband,lowband,204,204,119,90)
    //-------------------------------------//
    // Plot 
    //-------------------------------------//
    h1=30
    h2=70
    //-------------------------------------//
    return highband as "UpperBand"coloured("aqua"),lowband as "LowerBand"coloured("aqua"),crsi as "CRSI"coloured("fuchsia")style(line,2), h1 as "OB level"style(dottedline), h2 as "OS level"style(dottedline)
    Med5 thanked this post
    #240542 quote
    Med5
    Participant
    Junior

    Super merci bcp , c ‘est génial ,   Stp , serait-il envisageable d’y ajouter des divergences haussières et baissières (ligne verte et rouge) similaires à celles décrites dans cet indicateur RSI de votre forum : Lien vers l’indicateur PRT. ? merci

    #240564 quote
    finplus
    Participant
    Master

    Alors là le RSI paramétré comme indiqué avec une “mémoire” des cycles me parait hyper intéressant.

    Merci d’y avoir pensé et de l’avoir codé pour PRT.

    Med5 thanked this post
    #240565 quote
    Iván González
    Moderator
    Master

    Bonjour. Pour les divergences il vous suffit de copier le code indiqué dans votre lien en dessous de l'indicateur et de changer la ligne dans laquelle est définie la variable irsi :

    minimalBars=5
    obLevel=h2
    osLevel=h1
    irsi = crsi
    Med5 thanked this post
    #240574 quote
    Med5
    Participant
    Junior

    oui je viens de faire ca mais j ‘ai une erreur au niveau de la ligne 119 , ci-joint une photo et voici le code mixé , pourrais tu m’aider à résoudre ca ? merci bcp pour ton aide Ivan.

     

    //-------------------------------------//
    //PRC_RSI Cyclic Smoothed
    //version = 0
    //19.11.2024
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-------------------------------------//
    defparam drawonlastbaronly=true
    DEFPARAM CALCULATEONLASTBARS = 300
    
    //Inputs
    //-------------------------------------//
    src=close
    domcycle=32
    cyclelen=domcycle/2
    vibration=10
    leveling=10
    cyclicmemory=domcycle*2
    
    once crsi=0
    //-------------------------------------//
    // CRSI calculation
    //-------------------------------------//
    torque=2/(vibration+1)
    phasinglag=floor((vibration-1)/2)
    
    length = cyclelen
    alpha = 1/length
    
    srcUp = max(src-src[1],0)
    if barindex = length then
    up = average[length](srcUp)
    else
    up = alpha*srcUp + (1-alpha)*up[1]
    endif
    
    srcDw = -min(src-src[1],0)
    if barindex = length then
    dw = average[length](srcdw)
    else
    dw = alpha*srcdw + (1-alpha)*dw[1]
    endif
    
    if dw=0 then
    myrsi=100
    elsif up=0 then
    myrsi=0
    else
    myrsi=100-100/(1+up/dw)
    endif
    if barindex>cyclicmemory then
    crsi=torque*(2*myrsi-myrsi[phasinglag])+(1-torque)*crsi[1]
    endif
    //-------------------------------------//
    // LowBand and HighBand calculation
    //-------------------------------------//
    Period=cyclicMemory
    percent = leveling/100
    periodMinusone = period-1
    maxima = -999999.0
    minima =  999999.0
    
    for i=0 to periodMinusone do
    
    if crsi[i] > maxima then
    maxima = crsi[i]
    elsif crsi[i] < minima then
    minima = crsi[i]
    endif
    next
    
    stepfactor = (maxima-minima)/100
    lowband = 0
    
    for steps=0 to 100 do
    testvalue = minima+stepfactor*steps
    below=0
    for m=0 to periodMinusone do
    if crsi[m]<testvalue then
    below=below+1
    endif
    next
    if below/period >= percent then
    lowband = testvalue
    break
    endif
    next
    
    highband=0
    for steps=0 to 100 do
    testvalue=maxima-stepfactor*steps
    above=0
    for m=0 to periodMinusone do
    if crsi[m]>=testvalue then
    above=above+1
    endif
    next
    if above/Period >= percent then
    highband=testvalue
    break
    endif
    next
    colorbetween(highband,lowband,204,204,119,90)
    //-------------------------------------//
    // Plot
    //-------------------------------------//
    h1=30
    h2=70
    //-------------------------------------//
    return highband as "UpperBand"coloured("aqua"),lowband as "LowerBand"coloured("aqua"),crsi as "CRSI"coloured("fuchsia")style(line,2), h1 as "OB level"style(dottedline), h2 as "OS level"style(dottedline)
    
    //-------------------------------------//
    //PRC_AnotherRSIdivergences | indicator
    //25.02.2019
    //Nicolas @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    
    // --- settings
    RSIp=14 //RSI period
    minimalBars=5 //minimal count of bars where RSI is ob or os
    obLevel=h2 // Adjusted to match the previous h2
    osLevel=h1 // Adjusted to match the previous h1
    // --- end of settings
    
    irsi = crsi // Adjusted irsi to use crsi
    
    ob = irsi>obLevel
    os = irsi<osLevel
    
    if ob then
    if not ob[1] then
    maxrsi = 0
    maxprice = 0
    firstobbar = barindex
    endif
    maxrsi=max(maxrsi,irsi)
    maxprice=max(maxprice,high)
    if maxrsi<>maxrsi[1] then
    maxrsibar=barindex
    endif
    endif
    
    if os then
    if not os[1] then
    minrsi = 100
    minprice = close*100
    firstosbar = barindex
    endif
    minrsi=min(minrsi,irsi)
    minprice=min(minprice,low)
    if minrsi<>minrsi[1] then
    minrsibar=barindex
    endif
    endif
    
    divsell=0
    if irsi crosses under obLevel then
    //verif divergence
    div = maxprice>oldmaxprice and maxrsi<oldmaxrsi and (barindex-firstobbar)>=minimalBars
    if div then
    drawsegment(oldmaxrsibar,oldmaxrsi,maxrsibar,maxrsi) coloured(200,0,0)
    drawarrowdown(maxrsibar,maxrsi) coloured(200,0,0)
    divsell=osLevel
    endif
    oldmaxrsi = maxrsi
    oldmaxprice = maxprice
    oldmaxrsibar = maxrsibar
    endif
    
    divbuy=0
    if irsi crosses over osLevel then
    //verif divergence
    div = minprice<oldminprice and minrsi>oldminrsi and (barindex-firstosbar)>=minimalBars
    if div then
    drawsegment(oldminrsibar,oldminrsi,minrsibar,minrsi) coloured(0,200,0)
    drawarrowup(minrsibar,minrsi) coloured(0,200,0)
    divbuy=osLevel
    endif
    oldminrsi = minrsi
    oldminprice = minprice
    oldminrsibar = minrsibar
    endif
    
    return irsi style(line,2) as "RSI",obLevel coloured(168,168,168) style(dottedline,1) as "overbought level", osLevel coloured(168,168,168) style(dottedline,1) as "oversold level", divsell coloured(200,0,0) style(histogram) as "sell divergence", divbuy coloured(0,200,0) style(histogram) as "buy divergence"
    #240581 quote
    jacquesgermain
    Participant
    Senior

    hello

    votre erreur ligne 119 est causée par le return de la ligne 110 , il ne doit y avoir qu’un seul return en fin de code .

    Med5 thanked this post
    #240583 quote
    Med5
    Participant
    Junior

    hello , merci pour ta réponse ,  il faut que je fasse quoi ?  supprimer le return de la ligne 110  et garder que ca  : ” highband as UpperBand”coloured(“aqua”),lowband as “LowerBand”coloured(“aqua”),crsi as “CRSI”coloured(“fuchsia”)style(line,2), h1 as “OB level”style(dottedline), h2 as “OS level”style(dottedline) ”

    j’ai fais ca mais tjrs une erreur enfait au niveau de la ligne 178 179 .. désolé mais j ai aucune connaissance en programmation je m’aide avec GPT ..

    //-------------------------------------//
    // PRC_RSI Cyclic Smoothed
    // version = 0
    // 19.11.2024
    // Iván González @ www.prorealcode.com
    //-------------------------------------//
    
    defparam drawonlastbaronly = true
    defparam calculateonlastbars = 300
    
    // Inputs
    src = close
    domcycle = 32
    cyclelen = domcycle / 2
    vibration = 10
    leveling = 10
    cyclicmemory = domcycle * 2
    
    once crsi = 0
    
    //-------------------------------------//
    // CRSI Calculation
    //-------------------------------------//
    torque = 2 / (vibration + 1)
    phasinglag = floor((vibration - 1) / 2)
    
    length = cyclelen
    alpha = 1 / length
    
    srcUp = max(src - src[1], 0)
    if barindex = length then
        up = average[length](srcUp)
    else
        up = alpha * srcUp + (1 - alpha) * up[1]
    endif
    
    srcDw = -min(src - src[1], 0)
    if barindex = length then
        dw = average[length](srcDw)
    else
        dw = alpha * srcDw + (1 - alpha) * dw[1]
    endif
    
    if dw = 0 then
        myrsi = 100
    elsif up = 0 then
        myrsi = 0
    else
        myrsi = 100 - 100 / (1 + up / dw)
    endif
    
    if barindex > cyclicmemory then
        crsi = torque * (2 * myrsi - myrsi[phasinglag]) + (1 - torque) * crsi[1]
    endif
    
    //-------------------------------------//
    // LowBand and HighBand Calculation
    //-------------------------------------//
    period = cyclicmemory
    percent = leveling / 100
    periodMinusone = period - 1
    maxima = -999999.0
    minima = 999999.0
    
    for i = 0 to periodMinusone do
        if crsi[i] > maxima then
            maxima = crsi[i]
        elsif crsi[i] < minima then
            minima = crsi[i]
        endif
    next
    
    stepfactor = (maxima - minima) / 100
    lowband = 0
    
    for steps = 0 to 100 do
        testvalue = minima + stepfactor * steps
        below = 0
        for m = 0 to periodMinusone do
            if crsi[m] < testvalue then
                below = below + 1
            endif
        next
        if below / period >= percent then
            lowband = testvalue
            break
        endif
    next
    
    highband = 0
    for steps = 0 to 100 do
        testvalue = maxima - stepfactor * steps
        above = 0
        for m = 0 to periodMinusone do
            if crsi[m] >= testvalue then
                above = above + 1
            endif
        next
        if above / period >= percent then
            highband = testvalue
            break
        endif
    next
    
    colorbetween(highband, lowband, 204, 204, 119, 90)
    
    //-------------------------------------//
    // Divergence Detection and Plot
    //-------------------------------------//
    h1 = 30
    h2 = 70
    
    RSIp = 14
    minimalBars = 5
    obLevel = h2
    osLevel = h1
    
    irsi = crsi
    
    // Overbought logic
    ob = irsi > obLevel
    if ob then
        if not ob[1] then
            maxrsi = 0
            maxprice = 0
            firstobbar = barindex
        endif
        maxrsi = max(maxrsi, irsi)
        maxprice = max(maxprice, high)
        if maxrsi <> maxrsi[1] then
            maxrsibar = barindex
        endif
    endif
    
    // Oversold logic
    os = irsi < osLevel
    if os then
        if not os[1] then
            minrsi = 100
            minprice = close * 100
            firstosbar = barindex
        endif
        minrsi = min(minrsi, irsi)
        minprice = min(minprice, low)
        if minrsi <> minrsi[1] then
            minrsibar = barindex
        endif
    endif
    
    // Divergence Logic
    divsell = 0
    if irsi crosses under obLevel then
        div = maxprice > oldmaxprice and maxrsi < oldmaxrsi and (barindex - firstobbar) >= minimalBars
        if div then
            drawsegment(oldmaxrsibar, oldmaxrsi, maxrsibar, maxrsi) coloured(200, 0, 0)
            drawarrowdown(maxrsibar, maxrsi) coloured(200, 0, 0)
            divsell = osLevel
        endif
        oldmaxrsi = maxrsi
        oldmaxprice = maxprice
        oldmaxrsibar = maxrsibar
    endif
    
    divbuy = 0
    if irsi crosses over osLevel then
        div = minprice < oldminprice and minrsi > oldminrsi and (barindex - firstosbar) >= minimalBars
        if div then
            drawsegment(oldminrsibar, oldminrsi, minrsibar, minrsi) coloured(0, 200, 0)
            drawarrowup(minrsibar, minrsi) coloured(0, 200, 0)
            divbuy = osLevel
        endif
        oldminrsi = minrsi
        oldminprice = minprice
        oldminrsibar = minrsibar
    endif
    
    // Unified return
    return highband as "UpperBand" coloured("aqua"), 
           lowband as "LowerBand" coloured("aqua"), 
           crsi as "CRSI" coloured("fuchsia") style(line, 2), 
           h1 as "OB level" style(dottedline), 
           h2 as "OS level" style(dottedline), 
           divsell coloured(200, 0, 0) style(histogram) as "sell divergence", 
           divbuy coloured(0, 200, 0) style(histogram) as "buy divergence"
    
    #240584 quote
    finplus
    Participant
    Master

    le “return” doit être placé uniquement en fin de code. C’est une instruction qui affichent les informations définies juste après.

    Med5 thanked this post
    #240585 quote
    jacquesgermain
    Participant
    Senior
    il faut  supprimer la ligne 110 et  grouper en derniere ligne
    return highband as “UpperBand”coloured(“aqua”),lowband as “LowerBand”coloured(“aqua”),crsi as “CRSI”coloured(“fuchsia”)style(line,2), h1 as “OB level”style(dottedline), h2 as “OS level”style(dottedline),irsi style(line,2) as “RSI”,obLevel coloured(168,168,168) style(dottedline,1) as “overbought level”, osLevel coloured(168,168,168) style(dottedline,1) as “oversold level”, divsell coloured(200,0,0) style(histogram) as “sell divergence”, divbuy coloured(0,200,0) style(histogram) as “buy divergence”
    Med5 thanked this post
    #240586 quote
    RicLg
    Participant
    Senior

    Mettez le Return sur une seule ligne pour voir.

    // Unified return
    return highband as "UpperBand" coloured("aqua"),lowband as "LowerBand" coloured("aqua"),crsi as "CRSI" coloured("fuchsia") style(line, 2),h1 as "OB level" style(dottedline),h2 as "OS level" style(dottedline),divsell coloured(200, 0, 0) style(histogram) as "sell divergence",divbuy coloured(0, 200, 0) style(histogram) as "buy divergence"
    Med5 thanked this post
    #240588 quote
    Iván González
    Moderator
    Master

    Et enfin, une chose importante. Supprimez la ligne 8. Sinon vous n’obtiendrez de résultats que dans la dernière bougie. Vous pouvez également modifier le nombre de bougies dans lesquelles l'indicateur est calculé pour accélérer les calculs en modifiant la ligne 9.

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Conversion Indicateur RSI cyclic smoothed v2 de TV à PRT


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
Med5 @adilmed10 Participant
Summary

This topic contains 11 replies,
has 5 voices, and was last updated by Iván González
1 year, 2 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 11/18/2024
Status: Active
Attachments: 1 files
Logo Logo
Loading...