ATH LuxAlgo conversion

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #254362 quote
    Ziggy
    Participant
    New

    //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 quote
    Iván González
    Moderator
    Master
    // -----------------------------------------------
    // PRC_All Time High (ATH) Levels [LuxAlgo]
    // version = 0
    // 09.12.2025
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    // -----------------------------------------------
    defparam drawonlastbaronly=true
    // -----------------------------------------------
    // --- Settings ---
    // -----------------------------------------------
    //showLast = 50           // Show Last ATH
    //duration = 3            // ATH Minimum Duration
    //distMult = 3.0          // Minimum Distance Between ATH (ATR Multiplier)
    //showClassification = 1  // 1 = True, 0 = False (Show SR%)
    //minSr = 0               // Minimum % for display
    // -----------------------------------------------
    // --- Colors (RGB Configuration) ---
    // -----------------------------------------------
    // Bullish (Support) - Teal
    bullR = 8
    bullG = 153
    bullB = 129
    // Bearish (Resistance) - Red
    bearR = 242
    bearG = 54
    bearB = 69
    // -----------------------------------------------
    // --- Variables Initialization ---
    // -----------------------------------------------
    ONCE maxPrice = 0
    ONCE athCount = 0
    ONCE x1 = 0
    ONCE currentATR = 0
    // Arrays to store ATH data
    ONCE $athsValue[0] = 0 // Stores the Price Level
    ONCE $athsBarIndex[0] = 0 // Stores the BarIndex of the ATH
    ONCE $priceDist[0] = 0 // Cumulative distance above level
    ONCE $totalPriceDist[0] = 0 // Cumulative absolute distance
    
    // -----------------------------------------------
    // 1. Track All Time High
    // We check if the current High is higher than the previous global Max
    // -----------------------------------------------
    IF BarIndex = 0 THEN
       maxPrice = High
    ELSE
       maxPrice = MAX(maxPrice, High)
    ENDIF
    
    // ATR Calculation for filtering
    currentATR = AverageTrueRange[200](Close) * distMult
    
    // Detect new ATH Candidate
    IF High > maxPrice[1] THEN
       x1 = BarIndex
    ENDIF
    // -----------------------------------------------
    // 2. Confirm ATH Recency and Store It
    // -----------------------------------------------
    IF BarIndex - x1 = duration THEN
       // Store data in arrays
       $athsValue[athCount] = maxPrice
       $athsBarIndex[athCount] = x1
       
       // Initialize distance counters for this new level
       $priceDist[athCount] = 0
       $totalPriceDist[athCount] = 0
       
       athCount = athCount + 1
    ENDIF
    // -----------------------------------------------
    // 3. Update SR calculations for ALL stored ATHs
    // -----------------------------------------------
    IF athCount > 0 THEN
       FOR i = 0 TO athCount - 1 DO
          currentLvl = $athsValue[i]
          
          // Calculate distances
          distPlus = MAX(Close - currentLvl, 0)
          absDist = ABS(Close - currentLvl)
          
          // Accumulate in arrays
          $priceDist[i] = $priceDist[i] + distPlus
          $totalPriceDist[i] = $totalPriceDist[i] + absDist
       NEXT
    ENDIF
    // -----------------------------------------------
    // --- Drawing Logic (Last Bar Only) ---
    // -----------------------------------------------
    IF IsLastBarUpdate THEN
       
       // 1. Draw the most recent ATH (Current Max)
       recentLvl = $athsValue[athCount - 1]
       recentIdx = $athsBarIndex[athCount - 1]
       
       DRAWSEGMENT(recentIdx, recentLvl, BarIndex + 10, recentLvl) COLOURED(bearR, bearG, bearB)
       
       IF showClassification THEN
          lev=round(recentLvl,2)
          DRAWTEXT("[R] #lev#", BarIndex + 25, recentLvl) COLOURED(bearR, bearG, bearB) ANCHOR(LEFT, INDEX, VALUE)
       ENDIF
       
       // 2. Draw Historical ATHs
       // We loop backwards to show the most recent ones first, respecting 'showLast'
       
       prevLvl = recentLvl
       countDisplayed = 0
       
       // Loop from the second to last stored ATH down to the first one
       // Check if athCount is sufficient to avoid loop errors
       IF athCount > 1 THEN
          FOR i = athCount - 2 DOWNTO 0 DO
             
             // Limit the number of lines displayed
             IF countDisplayed < showLast THEN
                
                currentHistLvl = $athsValue[i]
                dist = prevLvl - currentHistLvl
                
                // Filter: Only show if distance from previous drawn level is > ATR * Multiplier
                IF dist >= currentATR THEN
                   
                   // Calculate SR Percentage
                   pDist = $priceDist[i]
                   tDist = $totalPriceDist[i]
                   
                   normDist = 0
                   IF tDist > 0 THEN
                      normDist = (1 - (pDist / tDist)) * 100
                   ENDIF
                   
                   // Color Calculation (Gradient Simulation)
                   // 0 = Full Green (Support), 100 = Full Red (Resistance)
                   
                   colorFactor = normDist / 100
                   finalR = ROUND(bullR + (bearR - bullR) * colorFactor)
                   finalG = ROUND(bullG + (bearG - bullG) * colorFactor)
                   finalB = ROUND(bullB + (bearB - bullB) * colorFactor)
                   
                   displayPct = ABS(normDist - 50) * 2
    
                   // Check Minimum % Filter
                   IF displayPct >= minSr THEN
                      // Draw Line
                      thisX = $athsBarIndex[i]
                      DRAWSEGMENT(thisX, currentHistLvl, BarIndex + 10, currentHistLvl) COLOURED(finalR, finalG, finalB)
                      
                      // Draw Label
                      IF showClassification THEN
                         // Determine Label (Support or Resistance)
                         lev=round(currentHistLvl,2)
                         IF normDist < 50 THEN
                            
                            DRAWTEXT("[S] #lev#", BarIndex + 25, currentHistLvl) COLOURED(finalR, finalG, finalB) ANCHOR(LEFT, INDEX, VALUE)
                         ELSE
                            DRAWTEXT("[R] #lev#", BarIndex + 25, currentHistLvl) COLOURED(finalR, finalG, finalB) ANCHOR(LEFT, INDEX, VALUE)
                         ENDIF
                         
                      ENDIF
                      
                      // Update tracking variables
                      prevLvl = currentHistLvl
                      countDisplayed = countDisplayed + 1
                   ENDIF
                ENDIF
             ELSE
                BREAK // Stop loop if we reached showLast limit
             ENDIF
          NEXT
       ENDIF
    ENDIF
    // -----------------------------------------------
    // --- Background Plots ---
    // -----------------------------------------------
    COLORBETWEEN(Close, maxPrice, 200, 200, 255, 230) // Light Blue very transparent
    // -----------------------------------------------
    RETURN maxPrice AS "ATH Trace" COLOURED(0,0,255,35)
    
    Ziggy thanked this post
    #254390 quote
    Ziggy
    Participant
    New
    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
    LuxAlgo-All-Time-High-ATH-Levels.ex5
    #254394 quote
    Iván González
    Moderator
    Master
    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
    Ziggy thanked this post
    #254395 quote
    Ziggy
    Participant
    New
    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 quote
    Ziggy
    Participant
    New
    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
    Iván González thanked this post
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

TradingView to ProRealTime Translation Center

New Reply
Author
author-avatar
Ziggy @ziggy Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by Ziggy
4 months, 2 weeks ago.

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 12/08/2025
Status: Active
Attachments: 1 files
Logo Logo
Loading...