ProRealCode - Trading & Coding with ProRealTime™
Hello everyone,
ProRealCode Studio — Customize ProRealTime with thousands of codes — and create your own.
ProRealCode Studio is a full development environment docked in the ProRealTime™ web platform. You log in with your own ProRealTime account as usual; Studio draws on top of that session.
Studio runs ProRealCode Script, an extended language compatible with the ProBuilder syntax. Bring your existing codes as they are, then add great new possibilities with the extended instructions.
For Chrome — also works in Edge, Brave, Opera and other Chromium-based browsers.
Backtests, optimizations and replays are simulations on historical data. They do not predict future results and are not investment advice.
Screenshots are in the attachments below.
Find out more: the presentation page · the user guide.
Questions, bug reports and feature ideas are welcome: reply in this topic, we read everything.
First things first: ProRealCode Script is compatible with the ProBuilder syntax. The indicators and strategies you already have run in Studio as they are, with no rewrite.
Studio also reads more than one syntax: the //@version scripts written for a well-known web charting platform are recognised on their own when you paste them into the editor, with no setting to change.
Then it goes further. Studio adds instructions and features that the platform’s own language does not have, and many of them have been requested on this forum for years. Every one is documented in the user guide, with its syntax and an example: What ProRealCode Script adds.
A non-exhaustive selection:
One thing to keep in mind: a code that uses these additions runs in Studio, not on the platform’s own engine. The editor shows a Studio Only badge on such a code and names the instructions concerned. Everything the two share is documented as always on prorealcode.com/documentation.
This is only the beginning. Anyone can ask for an improvement or a new instruction: reply in this topic, we will be glad to study it and deliver it as quickly as we can.
In the next posts of this topic we will publish examples, one at a time, each with a capture taken on the platform.
An EMA crossover that warns you by itself. When the fast EMA crosses the slow one, the code draws a Buy or Sell label on the candle and calls alert(): you get a message in Studio, a sound and a desktop notification, and the same alert leaves as a JSON message if you send your signals to a webhook.
What the code uses
How to use it: paste the code into a new Studio tab and press Ctrl + Enter. Alerts fire on live updates while a ProRealTime tab is open; switch desktop notifications on in the Alerts panel. To forward the JSON, set your webhook URL in the Alert preferences.
// ProRealCode Script example — alerts from the code
// An EMA crossover that warns you by itself: a message in Studio, a sound,
// a desktop notification, and a JSON message ready for a webhook.
// input() turns the two lengths into fields of the Variables form.
input(fastLen, 9, "Fast EMA", int)
input(slowLen, 21, "Slow EMA", int)
fastMa = ExponentialAverage[fastLen](close)
slowMa = ExponentialAverage[slowLen](close)
atr = AverageTrueRange[14](close)
// The ribbon between the two averages, green above, red below
IF fastMa >= slowMa THEN
COLORBETWEEN(fastMa, slowMa, 60, 190, 120, 60)
ELSE
COLORBETWEEN(fastMa, slowMa, 230, 90, 90, 60)
ENDIF
IF fastMa CROSSES OVER slowMa THEN
DRAWLABEL(barindex, low - 0.6 * atr, "Buy", arrowup, small, "EMA #fastLen# crossed over EMA #slowLen#") COLOURED(20, 22, 28) FILLCOLOR(120, 205, 150) BORDERCOLOR(30, 120, 70)
alert("EMA cross", "Bullish cross at #close#", onceperbar, 1, {side: "long", price: close})
ENDIF
IF fastMa CROSSES UNDER slowMa THEN
DRAWLABEL(barindex, high + 0.6 * atr, "Sell", arrowdown, small, "EMA #fastLen# crossed under EMA #slowLen#") COLOURED(235, 235, 235) FILLCOLOR(170, 60, 70) BORDERCOLOR(215, 95, 105)
alert("EMA cross", "Bearish cross at #close#", onceperbar, 1, {side: "short", price: close})
ENDIF
RETURN fastMa AS "Fast EMA" COLOURED(90, 170, 255) STYLE(line, 2), slowMa AS "Slow EMA" COLOURED(240, 180, 60) STYLE(line, 2)The captures: the Mini Nasdaq 100 future in 1 minute with the code open in Studio, at the moment a live Sell signal fires. The alert shows up in Studio with its sound, and as a desktop notification.
Write a calculation once, call it as often as you like. This code defines a Hull moving average as a function and calls it twice, for a fast line and a slow one, plus a second function that returns both edges of an ATR channel in a single call.
What the code uses
Good to know: a function is defined above the place where it is called, it cannot call itself, and it reads the code’s other variables without changing them.
How to use it: paste the code into a new Studio tab and press Ctrl + Enter.
// ProRealCode Script example — functions
// FUNCTION ... ENDFUNCTION: write a calculation once, call it as often as you like.
// Each call keeps its own history, and a function can return several values.
input(fastLen, 16, "Fast Hull length", int)
input(slowLen, 55, "Slow Hull length", int)
input(bandLen, 20, "Channel length", int)
input(bandMult, 2, "Channel width (ATR)", float)
// A Hull moving average, written once
FUNCTION hullMa(src, len)
halfMa = WeightedAverage[MAX(1, ROUND(len / 2))](src)
fullMa = WeightedAverage[len](src)
WeightedAverage[MAX(1, ROUND(SQRT(len)))](2 * halfMa - fullMa)
ENDFUNCTION
// A channel that returns two values at once
FUNCTION atrChannel(len, mult)
mid = ExponentialAverage[len](close)
width = mult * AverageTrueRange[len](close)
RETURN mid + width, mid - width
ENDFUNCTION
fastHull = hullMa(close, fastLen)
slowHull = hullMa(close, slowLen)
(upper, lower) = atrChannel(bandLen, bandMult)
COLORBETWEEN(upper, lower, 120, 140, 255, 25)
IF fastHull >= slowHull THEN
r = 60
g = 190
b = 120
ELSE
r = 230
g = 90
b = 90
ENDIF
RETURN fastHull AS "Hull fast" COLOURED(r, g, b) STYLE(line, 3), slowHull AS "Hull slow" COLOURED(200, 200, 210) STYLE(line, 1), upper AS "Channel top" COLOURED(120, 140, 255), lower AS "Channel bottom" COLOURED(120, 140, 255)The capture: the Mini Nasdaq 100 future in 1 minute with the code open in Studio. The fast Hull turns green above the slow one (grey) and red below it, inside the ATR channel (blue).
An RSI in its own panel that also paints the candles of the price chart in its colour: green when the RSI is low, grey around the middle, red when it is high.
What the code uses
How to use it: paste the code into a new Studio tab and press Ctrl + Enter.
// ProRealCode Script example — colour gradients and ONPRICE
// An RSI in its own panel that also paints the candles of the price chart.
// GRADIENTCOLOR turns a value into a colour; ONPRICE sends one drawing
// of this panel indicator onto the price chart.
DEFPARAM overlay = false
input(len, 14, "RSI length", int)
myRsi = RSI[len](close)
// In the panel: the RSI line, coloured by its own value
// and a fill that fades towards the 50 line
COLORBETWEEN(myRsi, 50, GRADIENTCOLOR(myRsi, 30, 70, "#3fbf7f66", "#8fa4c022", "#e0556366"))
// On the price chart: every candle takes the colour of the RSI
DRAWCANDLE(open, high, low, close) GRADIENTCOLOR(myRsi, 30, 70, "#3fbf7f", "#8fa4c0", "#e05563") ONPRICE
RETURN myRsi AS "RSI" GRADIENTCOLOR(myRsi, 30, 70, "#3fbf7f", "#8fa4c0", "#e05563") STYLE(line, 2), 70 AS "70" COLOURED(150, 150, 160), 50 AS "50" COLOURED(110, 110, 120), 30 AS "30" COLOURED(150, 150, 160)The capture: the Mini Nasdaq 100 future in 1 minute in the light theme, with the candles coloured by the RSI, the RSI and its fill in the panel below, and the code open in Studio.
The last 50 closes go into an array, and the array gives what a single variable never could: their median, the band that holds 80% of them, their dispersion, and where the current close ranks among them. When the close becomes the highest or the lowest of its window, a flag marks it.
What the code uses
Good to know: an array holds up to a million values and keeps them from one bar to the next. It has no history of its own, so a value you want to compare with the previous bar goes into an ordinary variable first, as rank does here with rank[1].
How to use it: paste the code into a new Studio tab and press Ctrl + Enter. The window length is a field of the Variables form.
// ProRealCode Script example — arrays
// The last closes go into an array, then the array gives their median,
// a percentile band, their dispersion and the rank of the current close.
input(len, 50, "Window (bars)", int)
// $w[0] is the oldest close of the window, $w[len - 1] the current one
ARRAYFROM($w, close, len)
mid = ARRAYMEDIAN($w)
low10 = ARRAYPERCENTILE($w, 10)
high90 = ARRAYPERCENTILE($w, 90)
dispersion = ARRAYSTDDEV($w)
// The band that holds 80% of the window's closes
COLORBETWEEN(low10, high90, 120, 140, 255, 30)
// Rank of the current close among the window: 0 = lowest, len - 1 = highest
ARRAYCOPY($ranked, $w)
ARRAYSORT($ranked, ascend)
rank = ARRAYINDEXOF($ranked, close)
IF rank = len - 1 AND rank[1] < len - 1 THEN
DRAWLABEL(barindex, high + dispersion * 0.3, "High of #len#", flag, tiny) COLOURED(20, 22, 28) FILLCOLOR(120, 205, 150)
ENDIF
IF rank = 0 AND rank[1] > 0 THEN
DRAWLABEL(barindex, low - dispersion * 0.3, "Low of #len#", flag, tiny) COLOURED(235, 235, 235) FILLCOLOR(170, 60, 70)
ENDIF
RETURN mid AS "Median" COLOURED(240, 180, 60) STYLE(line, 2), low10 AS "10th percentile" COLOURED(120, 140, 255), high90 AS "90th percentile" COLOURED(120, 140, 255)The capture: the Mini Nasdaq 100 future in 1 minute, with the median, the 10–90 percentile band and the High / Low of 50 flags, and the code open in Studio.
A small dashboard pinned to the chart and filled entirely from the code: the RSI, the ATR as a percentage of the price, and the change over the last 14 bars, each with a gauge, a sparkline of its last 60 bars and a coloured cell.
What the code uses
Good to know: the ranges of the ATR and change gauges are sized for the Nasdaq future in 1 minute; adjust them for another instrument or timeframe.
How to use it: paste the code into a new Studio tab and press Ctrl + Enter.
// ProRealCode Script example — a table on the chart
// DRAWTABLE pins a table to a corner of the chart, and the cells are filled
// from the code: text, gauges, bars, heat cells and sparklines.
DEFPARAM DRAWONLASTBARONLY = True
input(len, 14, "Length", int)
myRsi = RSI[len](close)
atrPct = AverageTrueRange[len](close) / close * 100
change = (close - close[len]) / close[len] * 100
rsiTxt = round(myRsi)
atrTxt = round(atrPct * 100) / 100
chgTxt = round(change * 100) / 100
board = DRAWTABLE(4, 3, topright) FILLCOLOR(16, 20, 28, 235) BORDERCOLOR(48, 58, 76)
// Title row across the three columns
TABLEMERGE(board, 0, 0, 1, 3)
TABLECELL(board, 0, 0, "Market board · #len# bars", bold, center, 12) COLOURED(214, 222, 235)
// One column per measure: a gauge, a sparkline of its last 60 bars, a heat cell
TABLEGAUGE(board, 1, 0, myRsi, 0, 100, "RSI #rsiTxt#") GRADIENTCOLOR(myRsi, 30, 70, "#3fbf7f", "#8fa4c0", "#e05563")
TABLEGAUGE(board, 1, 1, atrPct, 0, 0.1, "ATR #atrTxt#%") COLOURED(120, 170, 255)
TABLEGAUGE(board, 1, 2, change, 0 - 0.5, 0.5, "Change #chgTxt#%") COLOURED(190, 150, 255)
TABLESPARK(board, 2, 0, myRsi, 60) COLOURED(150, 190, 235)
TABLESPARK(board, 2, 1, atrPct, 60) COLOURED(120, 170, 255)
TABLESPARK(board, 2, 2, change, 60) COLOURED(190, 150, 255)
TABLEHEAT(board, 3, 0, myRsi, 70, 30, "#rsiTxt#")
TABLEHEAT(board, 3, 1, atrPct, 0.1, 0, "#atrTxt#")
TABLEHEAT(board, 3, 2, change, 0 - 0.5, 0.5, "#chgTxt#")
RETURNThe capture: the Mini Nasdaq 100 future in 1 minute in the light theme, with the table on the chart and the code open in Studio.
Swing highs and swing lows, marked on the bar where they happened and never moved afterwards, plus two lines that hold the last confirmed swing high and swing low as a resistance and a support.
What the code uses
Good to know: because a pivot is only confirmed right bars later, a strategy that reads it sees it on the bar of confirmation, never earlier. A backtest that uses it therefore does not read the future.
How to use it: paste the code into a new Studio tab and press Ctrl + Enter. The two lengths are fields of the Variables form; raise them for fewer, larger swings.
// ProRealCode Script example — pivots that never repaint
// PivotHigh / PivotLow find swing points, confirmed a few bars later and never moved.
// ValueWhen keeps the price of the last confirmed pivot as a support or a resistance.
input(leftBars, 5, "Bars on the left", int)
input(rightBars, 5, "Bars on the right", int)
ph = PivotHigh[leftBars, rightBars](high)
pl = PivotLow[leftBars, rightBars](low)
// The last confirmed swing high and swing low, carried forward bar after bar
resistance = ValueWhen(ISSET(ph), ph, 0)
support = ValueWhen(ISSET(pl), pl, 0)
// The pivots are marked on the bar where they happened, rightBars bars back
IF ISSET(ph) THEN
DRAWLABEL(barindex - rightBars, ph, "#ph#", arrowdown, small, "Swing high, confirmed #rightBars# bars later") COLOURED(20, 22, 28) FILLCOLOR(240, 190, 70) BORDERCOLOR(150, 105, 20)
ENDIF
IF ISSET(pl) THEN
DRAWLABEL(barindex - rightBars, pl, "#pl#", arrowup, small, "Swing low, confirmed #rightBars# bars later") COLOURED(20, 22, 28) FILLCOLOR(120, 205, 150) BORDERCOLOR(30, 120, 70)
ENDIF
RETURN resistance AS "Last swing high" COLOURED(240, 150, 70) STYLE(line, 2), support AS "Last swing low" COLOURED(90, 190, 140) STYLE(line, 2)The capture: the Mini Nasdaq 100 future in 1 minute in the light theme, with the swing labels, the last swing high (orange) and the last swing low (green), and the code open in Studio.
The concepts ICT traders draw by hand, computed by one code and kept up to date on every bar: market structure with its breaks and changes of character, liquidity sweeps, fair value gaps that stay on the chart until price fills them, the premium and discount halves of the dealing range, the liquidity still resting above and below it, and a dashboard that sums it all up.
What it draws
What the code uses
How to use it: paste the code into a new Studio tab and press Ctrl + Enter. Raise the swing length for a calmer structure on short timeframes. This is an illustration of the concepts, not a trading signal.
// ProRealCode Script example — an ICT toolkit
// Market structure (BOS and CHoCH), liquidity sweeps, fair value gaps that stay
// on the chart until price fills them, the premium and discount halves of the
// dealing range, and a dashboard. Built with functions, arrays, labels,
// gradients, a table and an alert.
input(swingLen, 5, "Swing length (bars on each side)", int)
input(maxGaps, 10, "Open fair value gaps shown", int)
input(minGapAtr, 0.2, "Smallest gap (in ATR)", float)
atr = AverageTrueRange[14](close)
// A level written once, used for every price shown in the dashboard
FUNCTION fmt(v)
ROUND(v * 100) / 100
ENDFUNCTION
// ── 1. Swings: confirmed pivots, never repainted ─────────────────────────────
ph = PivotHigh[swingLen, swingLen](high)
pl = PivotLow[swingLen, swingLen](low)
IF ISSET(ph) THEN
swingHigh = ph
swingHighBar = barindex - swingLen
highTaken = 0
ENDIF
IF ISSET(pl) THEN
swingLow = pl
swingLowBar = barindex - swingLen
lowTaken = 0
ENDIF
// ── 2. Liquidity sweeps and market structure ─────────────────────────────────
// A wick above the last swing high that closes back below it takes the
// buy-side liquidity; a close above it breaks the structure.
IF swingHigh > 0 AND highTaken = 0 AND high > swingHigh THEN
highTaken = 1
IF close < swingHigh THEN
DRAWLABEL(barindex, high + 0.4 * atr, "Sweep", arrowdown, tiny, "Buy-side liquidity taken above #swingHigh#") COLOURED(20, 22, 28) FILLCOLOR(240, 190, 70)
ELSE
DRAWSEGMENT(swingHighBar, swingHigh, barindex, swingHigh) COLOURED(60, 190, 120) STYLE(dashedline, 1)
IF trend = -1 THEN
DRAWLABEL(barindex, swingHigh + 0.3 * atr, "CHoCH", none, small, "Change of character: the bearish structure is broken") COLOURED(255, 255, 255) FILLCOLOR(40, 150, 95)
alert("ICT", "Bullish change of character at #close#", onceperbar, 1, {event: "choch", side: "long", price: close})
ELSE
DRAWLABEL(barindex, swingHigh + 0.3 * atr, "BOS", none, tiny, "Break of structure, trend continues up") COLOURED(60, 190, 120)
ENDIF
trend = 1
ENDIF
ENDIF
IF swingLow > 0 AND lowTaken = 0 AND low < swingLow THEN
lowTaken = 1
IF close > swingLow THEN
DRAWLABEL(barindex, low - 0.4 * atr, "Sweep", arrowup, tiny, "Sell-side liquidity taken below #swingLow#") COLOURED(20, 22, 28) FILLCOLOR(240, 190, 70)
ELSE
DRAWSEGMENT(swingLowBar, swingLow, barindex, swingLow) COLOURED(230, 90, 90) STYLE(dashedline, 1)
IF trend = 1 THEN
DRAWLABEL(barindex, swingLow - 0.3 * atr, "CHoCH", none, small, "Change of character: the bullish structure is broken") COLOURED(255, 255, 255) FILLCOLOR(175, 55, 65)
alert("ICT", "Bearish change of character at #close#", onceperbar, 1, {event: "choch", side: "short", price: close})
ELSE
DRAWLABEL(barindex, swingLow - 0.3 * atr, "BOS", none, tiny, "Break of structure, trend continues down") COLOURED(230, 90, 90)
ENDIF
trend = -1
ENDIF
ENDIF
// ── 3. Fair value gaps, kept in arrays until price fills them ────────────────
IF low > high[2] AND low - high[2] >= minGapAtr * atr THEN
ARRAYPUSH($gTop, low)
ARRAYPUSH($gBot, high[2])
ARRAYPUSH($gBar, barindex - 1)
ARRAYPUSH($gDir, 1)
ENDIF
IF high < low[2] AND low[2] - high >= minGapAtr * atr THEN
ARRAYPUSH($gTop, low[2])
ARRAYPUSH($gBot, high)
ARRAYPUSH($gBar, barindex - 1)
ARRAYPUSH($gDir, -1)
ENDIF
// Price eats into a gap: it shrinks, and disappears once filled
FOR i = 0 TO ARRAYSIZE($gDir) - 1 DO
IF $gDir[i] = 1 AND $gBar[i] < barindex - 1 THEN
IF low <= $gBot[i] THEN
$gDir[i] = 0
ELSIF low < $gTop[i] THEN
$gTop[i] = low
ENDIF
ELSIF $gDir[i] = -1 AND $gBar[i] < barindex - 1 THEN
IF high >= $gTop[i] THEN
$gDir[i] = 0
ELSIF high > $gBot[i] THEN
$gBot[i] = high
ENDIF
ENDIF
NEXT
// Keep the arrays short: the oldest entries leave from the front
WHILE ARRAYSIZE($gDir) > 200 DO
ARRAYSHIFT($gTop)
ARRAYSHIFT($gBot)
ARRAYSHIFT($gBar)
ARRAYSHIFT($gDir)
WEND
// ── 4. On the last bar: zones, liquidity and the dashboard ───────────────────
IF islastbarupdate AND swingHigh > 0 AND swingLow > 0 THEN
rangeStart = MIN(swingHighBar, swingLowBar)
rangeEnd = barindex + 12
eq = (swingHigh + swingLow) / 2
// Premium (upper half) and discount (lower half) of the dealing range
DRAWRECTANGLE(rangeStart, swingHigh, rangeEnd, eq) FILLCOLOR(230, 90, 90, 22)
DRAWRECTANGLE(rangeStart, eq, rangeEnd, swingLow) FILLCOLOR(60, 190, 120, 22)
DRAWSEGMENT(rangeStart, eq, rangeEnd, eq) COLOURED(150, 150, 165) STYLE(dottedline, 1)
DRAWLABEL(rangeEnd, eq, "EQ", none, tiny, right) COLOURED(150, 150, 165)
DRAWLABEL(rangeEnd, swingHigh, "Premium", none, tiny, right) COLOURED(230, 90, 90)
DRAWLABEL(rangeEnd, swingLow, "Discount", none, tiny, right) COLOURED(60, 190, 120)
// Liquidity still resting above the last swing high and below the last swing low
IF highTaken = 0 THEN
DRAWSEGMENT(swingHighBar, swingHigh, rangeEnd, swingHigh) COLOURED(240, 190, 70) STYLE(dottedline, 2)
DRAWLABEL(swingHighBar, swingHigh + 0.3 * atr, "BSL", none, tiny) COLOURED(240, 190, 70)
ENDIF
IF lowTaken = 0 THEN
DRAWSEGMENT(swingLowBar, swingLow, rangeEnd, swingLow) COLOURED(240, 190, 70) STYLE(dottedline, 2)
DRAWLABEL(swingLowBar, swingLow - 0.3 * atr, "SSL", none, tiny) COLOURED(240, 190, 70)
ENDIF
// The open fair value gaps, newest first
shown = 0
upGaps = 0
downGaps = 0
FOR i = ARRAYSIZE($gDir) - 1 DOWNTO 0 DO
IF $gDir[i] = 1 THEN
upGaps = upGaps + 1
ELSIF $gDir[i] = -1 THEN
downGaps = downGaps + 1
ENDIF
IF $gDir[i] <> 0 AND shown < maxGaps THEN
shown = shown + 1
IF $gDir[i] = 1 THEN
DRAWRECTANGLE($gBar[i], $gTop[i], rangeEnd, $gBot[i]) FILLCOLOR(60, 190, 120, 70) COLOURED(60, 190, 120)
ELSE
DRAWRECTANGLE($gBar[i], $gTop[i], rangeEnd, $gBot[i]) FILLCOLOR(230, 90, 90, 70) COLOURED(230, 90, 90)
ENDIF
ENDIF
NEXT
// Where the close sits in the range: 0% = swing low, 100% = swing high
pos = MAX(0, MIN(100, (close - swingLow) / (swingHigh - swingLow) * 100))
posTxt = ROUND(pos)
bsl = fmt(swingHigh)
ssl = fmt(swingLow)
board = DRAWTABLE(6, 2, topleft) FILLCOLOR(16, 20, 28, 235) BORDERCOLOR(48, 58, 76)
TABLEMERGE(board, 0, 0, 1, 2)
TABLECELL(board, 0, 0, "ICT dashboard", bold, center, 12) COLOURED(214, 222, 235)
TABLECELL(board, 1, 0, "Structure") COLOURED(170, 180, 195)
IF trend = 1 THEN
TABLECELL(board, 1, 1, "Bullish", bold) COLOURED(255, 255, 255)
TABLEBG(board, 1, 1, 40, 150, 95)
ELSIF trend = -1 THEN
TABLECELL(board, 1, 1, "Bearish", bold) COLOURED(255, 255, 255)
TABLEBG(board, 1, 1, 175, 55, 65)
ELSE
TABLECELL(board, 1, 1, "Undecided") COLOURED(170, 180, 195)
ENDIF
TABLECELL(board, 2, 0, "Range position") COLOURED(170, 180, 195)
TABLEBAR(board, 2, 1, pos, 0, 100, "#posTxt#%") GRADIENTCOLOR(pos, 0, 100, "#3fbf7f", "#8fa4c0", "#e05563")
TABLECELL(board, 3, 0, "Open gaps up / down") COLOURED(170, 180, 195)
TABLECELL(board, 3, 1, "#upGaps# / #downGaps#") COLOURED(214, 222, 235)
TABLECELL(board, 4, 0, "Buy-side liquidity") COLOURED(170, 180, 195)
TABLECELL(board, 4, 1, "#bsl#") COLOURED(240, 190, 70)
TABLECELL(board, 5, 0, "Sell-side liquidity") COLOURED(170, 180, 195)
TABLECELL(board, 5, 1, "#ssl#") COLOURED(240, 190, 70)
ENDIF
RETURNThe captures: the Mini Nasdaq 100 future in 1 minute and in 15 minutes, the same code on both.
ProRealTrend draws support and resistance lines on the chart. Six names let a code read those lines, whether ProRealTrend is shown or hidden, and work with them. This one tags every line with what it is, counts them in a dashboard, finds the nearest support and resistance, and raises an alert when the price comes near a major line.
The six names
The code also joins strings with + to build each tag (« Resistance · major · monthly »), and uses DRAWLABEL, DRAWTABLE and alert() with a JSON block.
Good to know: the lines are what ProRealTrend computes today. Read on a past bar, TrendLine(i) is where today’s line passes on that bar, not a line that was known at the time, so a backtest built on it would read the future. That is why this code reads them on the last bar only, with islastbarupdate. When ProRealTrend recomputes (a new bar, another instrument or timeframe), the code recalculates with the new set.
How to use it: paste the code into a new Studio tab and press Ctrl + Enter. Show ProRealTrend if you want to see the lines under the tags; the code reads them either way.
// ProRealCode Script example — reading ProRealTrend from the code
// Six names read the support and resistance lines ProRealTrend computes for
// this chart, shown or hidden: TrendLineCount, TrendLine(i), TrendLineType(i),
// TrendLineImportance(i), TrendLineOblique(i) and TrendLinePeriod(i).
// Read on a past bar, a line is where TODAY's line passes on that bar, so this
// code reads them on the last bar only.
input(minImportance, 1, "Lowest importance shown (1 minor, 2 intermediate, 3 major)", int)
input(alertPct, 0.1, "Alert when the close is this near a major line (%)", float)
IF islastbarupdate THEN
supports = 0
resistances = 0
majors = 0
obliques = 0
higherTf = 0
nearSup = undefined
nearRes = undefined
FOR i = 1 TO TrendLineCount DO
lvl = TrendLine(i)
imp = TrendLineImportance(i)
IF ISSET(lvl) AND imp >= minImportance THEN
// What the line is: support or resistance
IF TrendLineType(i) = 1 THEN
supports = supports + 1
txt = "Support"
r = 60
g = 190
b = 120
IF lvl <= close AND (NOT ISSET(nearSup) OR lvl > nearSup) THEN
nearSup = lvl
ENDIF
ELSE
resistances = resistances + 1
txt = "Resistance"
r = 230
g = 90
b = 90
IF lvl > close AND (NOT ISSET(nearRes) OR lvl < nearRes) THEN
nearRes = lvl
ENDIF
ENDIF
// How strong ProRealTrend rates it: 3 major, 2 intermediate, 1 minor
IF imp = 3 THEN
majors = majors + 1
txt = txt + " · major"
IF ABS(close - lvl) / lvl * 100 <= alertPct THEN
alert("ProRealTrend", "Close #close# is near a major line at #lvl#", onceperbar, 1, {level: lvl, support: TrendLineType(i) = 1})
ENDIF
ELSIF imp = 2 THEN
txt = txt + " · intermediate"
ELSE
txt = txt + " · minor"
ENDIF
// Horizontal or oblique
IF TrendLineOblique(i) = 1 THEN
obliques = obliques + 1
txt = txt + " · oblique"
ENDIF
// The timeframe it was computed on, in seconds per bar
p = TrendLinePeriod(i)
IF p >= 2592000 THEN
txt = txt + " · monthly"
ELSIF p >= 604800 THEN
txt = txt + " · weekly"
ELSIF p >= 86400 THEN
txt = txt + " · daily"
ENDIF
IF p > GetTimeframe THEN
higherTf = higherTf + 1
ENDIF
// A tag at the right end of the line, stronger lines more opaque
DRAWLABEL(barindex + 2, lvl, txt, arrowleft, small, left) COLOURED(255, 255, 255) FILLCOLOR(r, g, b, 80 + imp * 55)
ENDIF
NEXT
// The dashboard
board = DRAWTABLE(8, 2, topleft) FILLCOLOR(16, 20, 28, 235) BORDERCOLOR(48, 58, 76)
TABLEMERGE(board, 0, 0, 1, 2)
TABLECELL(board, 0, 0, "ProRealTrend, read by the code", bold, center, 12) COLOURED(214, 222, 235)
TABLECELL(board, 1, 0, "Lines on the chart") COLOURED(170, 180, 195)
TABLECELL(board, 1, 1, "#TrendLineCount#") COLOURED(214, 222, 235)
TABLECELL(board, 2, 0, "Supports / resistances") COLOURED(170, 180, 195)
TABLECELL(board, 2, 1, "#supports# / #resistances#") COLOURED(214, 222, 235)
TABLECELL(board, 3, 0, "Major lines") COLOURED(170, 180, 195)
TABLECELL(board, 3, 1, "#majors#") COLOURED(214, 222, 235)
TABLECELL(board, 4, 0, "Oblique lines") COLOURED(170, 180, 195)
TABLECELL(board, 4, 1, "#obliques#") COLOURED(214, 222, 235)
TABLECELL(board, 5, 0, "From a higher timeframe") COLOURED(170, 180, 195)
TABLECELL(board, 5, 1, "#higherTf#") COLOURED(214, 222, 235)
TABLECELL(board, 6, 0, "Nearest support") COLOURED(170, 180, 195)
IF ISSET(nearSup) THEN
supLvl = ROUND(nearSup * 100) / 100
supPct = ROUND((close - nearSup) / close * 10000) / 100
TABLECELL(board, 6, 1, "#supLvl# (-#supPct#%)") COLOURED(60, 190, 120)
ELSE
TABLECELL(board, 6, 1, "none below") COLOURED(170, 180, 195)
ENDIF
TABLECELL(board, 7, 0, "Nearest resistance") COLOURED(170, 180, 195)
IF ISSET(nearRes) THEN
resLvl = ROUND(nearRes * 100) / 100
resPct = ROUND((nearRes - close) / close * 10000) / 100
TABLECELL(board, 7, 1, "#resLvl# (+#resPct#%)") COLOURED(230, 90, 90)
ELSE
TABLECELL(board, 7, 1, "none above") COLOURED(170, 180, 195)
ENDIF
ENDIF
RETURNThe captures: the Mini Nasdaq 100 future in 15 minutes, first with ProRealTrend shown, then hidden. The tags and the dashboard do not depend on the display: the code reads the lines in both cases.
Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.
A complete code editor, chart templates, bar replay and alerts from your codes, right inside the platform.
Add to ChromeAlso works in Edge, Brave, Opera and other Chromium-based browsers.
Discover ProRealCode StudioProRealCode Studio — extend ProRealTime Web from Chrome
This topic contains 9 replies,
has 1 voice, and was last updated by
Nicolas
1 hour, 52 minutes ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 12/01/2026 |
| Status: | Active |
| Attachments: | 14 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.