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
Ziggy.
-
-
12/08/2025 at 7:23 PM #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_indexset_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 = highmax := math.max(high, max)
atr = nz(ta.atr(200), ta.cum(high – low) / (n+1)) * distMultif 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))
//———————————————————————————————————————}
12/09/2025 at 12:05 PM #254379123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178// -----------------------------------------------// 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) - TealbullR = 8bullG = 153bullB = 129// Bearish (Resistance) - RedbearR = 242bearG = 54bearB = 69// -----------------------------------------------// --- Variables Initialization ---// -----------------------------------------------ONCE maxPrice = 0ONCE athCount = 0ONCE x1 = 0ONCE currentATR = 0// Arrays to store ATH dataONCE $athsValue[0] = 0 // Stores the Price LevelONCE $athsBarIndex[0] = 0 // Stores the BarIndex of the ATHONCE $priceDist[0] = 0 // Cumulative distance above levelONCE $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 THENmaxPrice = HighELSEmaxPrice = MAX(maxPrice, High)ENDIF// ATR Calculation for filteringcurrentATR = AverageTrueRange[200](Close) * distMult// Detect new ATH CandidateIF High > maxPrice[1] THENx1 = BarIndexENDIF// -----------------------------------------------// 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] = 0athCount = athCount + 1ENDIF// -----------------------------------------------// 3. Update SR calculations for ALL stored ATHs// -----------------------------------------------IF athCount > 0 THENFOR i = 0 TO athCount - 1 DOcurrentLvl = $athsValue[i]// Calculate distancesdistPlus = MAX(Close - currentLvl, 0)absDist = ABS(Close - currentLvl)// Accumulate in arrays$priceDist[i] = $priceDist[i] + distPlus$totalPriceDist[i] = $totalPriceDist[i] + absDistNEXTENDIF// -----------------------------------------------// --- 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 THENlev=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 = recentLvlcountDisplayed = 0// Loop from the second to last stored ATH down to the first one// Check if athCount is sufficient to avoid loop errorsIF athCount > 1 THENFOR i = athCount - 2 DOWNTO 0 DO// Limit the number of lines displayedIF countDisplayed < showLast THENcurrentHistLvl = $athsValue[i]dist = prevLvl - currentHistLvl// Filter: Only show if distance from previous drawn level is > ATR * MultiplierIF dist >= currentATR THEN// Calculate SR PercentagepDist = $priceDist[i]tDist = $totalPriceDist[i]normDist = 0IF tDist > 0 THENnormDist = (1 - (pDist / tDist)) * 100ENDIF// Color Calculation (Gradient Simulation)// 0 = Full Green (Support), 100 = Full Red (Resistance)colorFactor = normDist / 100finalR = ROUND(bullR + (bearR - bullR) * colorFactor)finalG = ROUND(bullG + (bearG - bullG) * colorFactor)finalB = ROUND(bullB + (bearB - bullB) * colorFactor)displayPct = ABS(normDist - 50) * 2// Check Minimum % FilterIF displayPct >= minSr THEN// Draw LinethisX = $athsBarIndex[i]DRAWSEGMENT(thisX, currentHistLvl, BarIndex + 10, currentHistLvl) COLOURED(finalR, finalG, finalB)// Draw LabelIF showClassification THEN// Determine Label (Support or Resistance)lev=round(currentHistLvl,2)IF normDist < 50 THENDRAWTEXT("[S] #lev#", BarIndex + 25, currentHistLvl) COLOURED(finalR, finalG, finalB) ANCHOR(LEFT, INDEX, VALUE)ELSEDRAWTEXT("[R] #lev#", BarIndex + 25, currentHistLvl) COLOURED(finalR, finalG, finalB) ANCHOR(LEFT, INDEX, VALUE)ENDIFENDIF// Update tracking variablesprevLvl = currentHistLvlcountDisplayed = countDisplayed + 1ENDIFENDIFELSEBREAK // Stop loop if we reached showLast limitENDIFNEXTENDIFENDIF// -----------------------------------------------// --- Background Plots ---// -----------------------------------------------COLORBETWEEN(Close, maxPrice, 200, 200, 255, 230) // Light Blue very transparent// -----------------------------------------------RETURN maxPrice AS "ATH Trace" COLOURED(0,0,255,35)1 user thanked author for this post.
12/09/2025 at 2:04 PM #254390Tks 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
12/09/2025 at 3:10 PM #25439412/09/2025 at 3:47 PM #254395Tks 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
12/09/2025 at 5:23 PM #254397Todo 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.
-
AuthorPosts
Find exclusive trading pro-tools on 