ATR Stop Loss Finder

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #197514 quote
    achraf
    Participant
    New

    bonjour

    je sais pas si je suis sur le bon forum, je cherche a convertir cet indicateur ATR STOP LOSS FINDER  version tradingview en version prorealtime.

     

    voici le code :

    //@version=4
    study(title=”Average True Range Stop Loss Finder”, shorttitle=”ATR”, overlay=true)
    length = input(title=”Length”, defval=14, minval=1)
    smoothing = input(title=”Smoothing”, defval=”RMA”, options=[“RMA”, “SMA”, “EMA”, “WMA”])
    m = input(1.5, “Multiplier”)
    src1 = input(high)
    src2 = input(low)
    pline = input(true, “Show Price Lines”)
    col1 = input(color.blue, “ATR Text Color”)
    col2 = input(color.teal, “Low Text Color”,inline =”1″)
    col3 = input(color.red, “High Text Color”,inline =”2″)

    collong = input(color.teal, “Low Line Color”,inline =”1″)
    colshort = input(color.red, “High Line Color”,inline =”2″)

    ma_function(source, length) =>
    if smoothing == “RMA”
    rma(source, length)
    else
    if smoothing == “SMA”
    sma(source, length)
    else
    if smoothing == “EMA”
    ema(source, length)
    else
    wma(source, length)

    a = ma_function(tr(true), length) * m
    x = ma_function(tr(true), length) * m + src1
    x2 = src2 – ma_function(tr(true), length) * m

    p1 = plot(x, title = “ATR Short Stop Loss”, color= colshort, transp=20, trackprice = pline ? true : false)
    p2 = plot(x2, title = “ATR Long Stop Loss”, color= collong, transp=20, trackprice = pline ? true : false)

    var table Table = table.new(position.bottom_center, 3, 1, border_width = 3)

    f_fillCell(_table, _column, _row, _value, _timeframe) =>

    _cellText = _timeframe+ tostring(_value, “#.#”)
    table.cell(_table, _column, _row, _cellText, text_color = col1)
    table.cell_set_text_color(Table, 1, 0, color.new(col3, transp = 0))
    table.cell_set_text_color(Table, 2, 0, color.new(col2, transp = 0))

    if barstate.islast
    f_fillCell(Table, 0, 0, a, “ATR: ” )
    f_fillCell(Table, 1, 0, x, “H: ” )
    f_fillCell(Table, 2, 0, x2, “L: ” )

    #197580 quote
    druby
    Participant
    New

    BJ…

    Quelque part, j’ai entendu le nom “Trading View” et le langage de codage “pin”. Mais c’est pour ça.

    En regardant le code, cela ne semblait pas si compliqué d’après ma connaissance des choses, alors j’ai décidé de relever le défi.

    Ci-dessous le fruit de mon travail. Ce n’est qu’une version de base pour prouver le concept et ne fait que la moyenne “RMA” avec une fonctionnalité limitée.

    Si vous copiez le code, vous devez configurer les variables dynamiques répertoriées en haut du fichier de code.
    L’importation du fichier à partir du bas doit inclure ces paramètres.
    La couleur/le style de la ligne peut être défini dans les paramètres de l’indicateur.

    Faites-moi savoir quelles autres moyennes et/ou fonctionnalités vous souhaitez être accordées.

    La lampe ne demande qu’à être frottée

     

    // HstopL v1  20-07-2022 druby
    //
    // Dynamic variable settings
    // NAME           Type      Default         (comment)
    // -------------------------------------------------------------------
    // Period       integer        14           lookback range
    // Mul          Decimal        1.5          multiply the ATR value by:
    
    defparam drawonlastbaronly = true
    
    // input limiters - limit the range of values used in code calculations
    period = max(min(Period,barindex),1) // (1 to barindex)
    mul = max(min(Mul,10),0)             // (0 to 10)
    
    //true range calculation
    tr1 = abs(high - low)
    tr2 = abs(high - close[1])
    tr3 = abs(low - close[1])
    trf = max(tr3,max(tr1,tr2))  // absolute maximum of (tr1,tr2,tr3)
    
    if barindex > period then  // delay average calculations till enough bars avaliable
     
    // manual RMA calculation
    k= 1/(period)
    RMA = range * k + RMA[1] * (1-k)
    xma = RMA
     
    //  Atr, HLline calculations
    // Atr value
    a = xma * mul
    // Atr +/- high/low values
    x = xma * mul + high
    x2 = low - xma * mul
    
    endif // barindex > period
    
    // Drawing main text and values
    Drawtext("ATR: #a#",-255,10,dialog,bold,20)anchor(bottom) coloured ("dodgerblue")
    Drawtext("H: #x#",   -70,10,dialog,bold,20)anchor(bottom) coloured ("red")
    Drawtext("L: #x2#",  100,10,dialog,bold,20)anchor(bottom) coloured ("teal")
    
    // draw averageType label
    Drawtext("RMA",40,10,dialog,bold,20)anchor(bottomLeft) coloured ("grey")
    
    // return (atr * mul) high and low lines
    return x as"Hstop",x2 as"Lstop"
    
    // Known limitations not limited to:
    
    // There's 'NO' feedback between, the changing of the value a dynamic variable from its
    //   default value and what value is used in the executing code if changed internally.
    // It is permitted to change the value of dynamic variables while the code is being
    //   executed, however setting a value outside a valid range, suitable for the 
    //   application at hand, could lead to erroneous data or the indicator to crash.
    // Though some input limiting is done above, a value outside the valid range will adopt 
    //   the closest valid value and will 'not' issue any error or notification. Also an 
    //   'out of range' value other than appearing in the indicator settings will also 
    //   appear in the indicator label box on the chart panel and in the cursor info label(s).
    //  
    // Feedback Welcome!
    Nicolas thanked this post
    HstopL-v1.itf
    #205226 quote
    achraf
    Participant
    New

    bonjour

    désole de mon feedback au tardivement j’ai testé le code que tu m’as envoyé franchement je suis hyper satisfait tu as fait un travail de pro je sais pas comment te remercier tu es un amour merci beaucoup.

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

ATR Stop Loss Finder


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
achraf @achraf Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by achraf
3 years, 2 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 07/19/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...