ATH LuxAlgo conversion (Iván )

Forums ProRealTime English forum ProBuilder support ATH LuxAlgo conversion (Iván )

  • This topic has 5 replies, 2 voices, and was last updated 2 days ago by avatarZiggy.
Viewing 6 posts - 1 through 6 (of 6 total)
  • #254362

    //can you please translate this ATH algo to Prorealcode please..(I have tried some myself but keep having some errors here and there)

    Am posting here the Pine code as a reference. TIA

    Ziggy

    // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
    // © LuxAlgo

    //@version=5
    indicator(“All Time High (ATH) Levels [LuxAlgo]”, “LuxAlgo – All Time High (ATH) Levels”, overlay = true, max_lines_count = 500, max_labels_count = 500)
    //———————————————————————————————————————}
    //Settings
    //———————————————————————————————————————{
    showLast = input.int(50, ‘Show Last ATH’, minval = 1)
    duration = input(3, ‘ATH Minimum Duration’)
    distMult = input.float(3., ‘Minimum Distance Between ATH’, step = .25)

    //Interval Filter
    showClassification = input(true, ‘Show SR%’, group = ‘SR% Classification’)
    minSr = input.float(0, ‘Minimum %’, minval = 0, maxval = 100, group = ‘SR% Classification’)

    //Style
    bullCss = input(#089981, ‘Support Color’, group = ‘Style’)
    bearCss = input(#f23645, ‘Resistance Color’, group = ‘Style’)

    trailCss1 = input(#0a0032, ‘Trailing Gradient’, inline = ‘trail’, group = ‘Style’)
    trailCss2 = input(#ff5d00, ”, inline = ‘trail’, group = ‘Style’)
    trailCss3 = input(#2962ff, ”, inline = ‘trail’, group = ‘Style’)

    //———————————————————————————————————————}
    //Functions
    //———————————————————————————————————————{
    n = bar_index

    set_elements(x1, lvl, txt, css)=>
    line.new(x1, lvl, time, lvl, xloc.bar_time, color = css)
    line.new(n, lvl, n+100, lvl, color = css)

    if showClassification
    label.new(n+100, lvl, txt, color = color(na), style = label.style_label_left, textcolor = css, size = size.tiny)

    //———————————————————————————————————————}
    //Variables
    //———————————————————————————————————————{
    var aths = array.new<float>(0)
    var aths_x1 = array.new<int>(0)
    var price_dist = array.new<float>(0)
    var total_price_dist = array.new<float>(0)

    var x1 = 0
    var time_x1 = 0
    var max = high

    max := math.max(high, max)
    atr = nz(ta.atr(200), ta.cum(high – low) / (n+1)) * distMult

    if max > max[1]
    x1 := n
    time_x1 := time

    //Test for ATH recency
    if n – x1 == duration
    aths.unshift(max)
    aths_x1.unshift(time_x1)

    //Relative Dist Calculation
    price_dist.unshift(0)
    total_price_dist.unshift(0)

    //Set ATH’s
    for [index, element] in aths
    price_dist.set(index, price_dist.get(index) + math.max(close – element, 0))
    total_price_dist.set(index, total_price_dist.get(index) + math.abs(close – element))

    //———————————————————————————————————————}
    //Display ATH’s
    //———————————————————————————————————————{
    //Delete existing graphical elements
    for element in line.all
    element.delete()
    for element in label.all
    element.delete()

    if barstate.islast
    //Recent ATH
    lvl = aths.get(0)

    //Set display elements
    set_elements(aths_x1.get(0), lvl, ‘[R] 100%’, bearCss)

    //Display Historical ATH’s
    for i = 1 to math.min(showLast-1, aths.size()-1)
    dist = lvl – aths.get(i)

    //Display level if distance between currently evaluated level and previous level is greater than threshold
    if dist >= atr
    norm_dist = (1 – price_dist.get(i) / total_price_dist.get(i)) * 100
    sr = norm_dist < 50 ? ‘[S] ‘ : ‘[R] ‘
    css = color.from_gradient(norm_dist, 0, 100, bullCss, bearCss)

    norm_dist := math.abs(norm_dist – 50) * 2

    //Display level if percentage is higher than user set threshold
    if norm_dist >= minSr

    //Set display elements
    set_elements(aths_x1.get(i), aths.get(i), sr + str.tostring(norm_dist, format.percent), css)

    lvl := aths.get(i)

    //———————————————————————————————————————}
    //Plots
    //———————————————————————————————————————{
    bg_css1 = color.from_gradient(n, 0, last_bar_index/2, trailCss1, trailCss2)
    bg_css2 = color.from_gradient(n, last_bar_index/2, last_bar_index, bg_css1, trailCss3)

    plot_price = plot(close, display = display.none, editable = false)
    plot_max = plot(max, color = bg_css2)

    fill(plot_price, plot_max, color = color.new(bg_css2, 90))

    //———————————————————————————————————————}

     

     

     

     

    #254379
    1 user thanked author for this post.
    #254390

    Tks Iván    It is almost good but there is something strange in the plot. As instead of support and resistance lines it depcits everything as in those Mountain Charts. Beside I have tried to modify some the variables and it has staled.     Find in attachment the MQL5 or EX5 code for the same indicator, maybe it is a tad different from the versions for Tradingivew.

     

    Ziggy

    #254394

    I don`t know… I’ve translated the tradingview code. I can’t open the file you sent. Maybe you can use my code and ask the IA to check the difference with mql5

    1 user thanked author for this post.
    #254395

    Tks I’ll have a look at later on or tom and go trough it once again. More slowly! In the meantime am attaching also the code written for Ninja Trader (if you can see it). Beside the TradingView code from the source been taken, see  https://www.tradingview.com/script/SOgEeE2C-All-Time-High-ATH-Levels-LuxAlgo/

    Tks again

    Ziggy

    att.:// 2 files Ninja

    #254397

    Todo bien Iván. Solved that Mountain chart by simply deleting the last 3 lines   from 176 COLORBETWEEN and to 178 RETURN …COLOURED ….    and put simply a standrd RETURN  down there… and it works bienito…    or bonito como es… had even some fun with Grok discoreding this was basically PASCAL language written back in the 1970s… nice simple clean coding of once… So If you wish to give the code to your subscribers there, feel free to use It and gracias ….    vamos adelante… nos vemos

     

    Ziggy

    1 user thanked author for this post.
Viewing 6 posts - 1 through 6 (of 6 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login