# AlertaScript > Official AlertaChart scripting documentation. Documented Pine-compatible spellings run without warnings. The documentation uses the alerta. presentation prefix. Source code supplied to the editor is not automatically rewritten. Review examples and run them explicitly. ## Guides - [AlertaScript](https://www.alertachart.com/alertascript): Turn chart data into indicators, strategies and alerts. ### How it works AlertaScript brings your analysis rules onto the AlertaChart chart. Read price and volume series, calculate indicators, draw levels and test trading ideas in a single scripting environment. ### Put it into practice Start with a small indicator and inspect its output on historical and live bars. The reference documents exact signatures, accepted spellings and data requirements; guides connect those building blocks into usable workflows. ### Continue reading - [Getting started](https://www.alertachart.com/alertascript/getting-started): Your path from an empty editor to a useful script. ### How it works Build one observable result first: a moving average, an oscillator or a named alert condition. Each tutorial introduces a separate workflow so you can understand the output before combining features. ### Put it into practice Open Alerta Script from the chart, create a draft and run the quick-start example. Then choose the indicator, strategy or alert tutorial. Save the script before experimenting with additional rules. ### Continue reading - [Quick start](https://www.alertachart.com/alertascript/getting-started/quick-start): Plot a configurable EMA in five lines. ### How it works The indicator declaration sets the title and chart placement. input.int exposes a length setting; close supplies the price series; alerta.ta.ema calculates the moving average. plot turns the calculated series into a visible line. ### Put it into practice Run the example, change Length from 20 to 50 and compare the line with price. Early bars may lack enough history for a calculation. Keep the script small while checking that the chart symbol and timeframe match your intended analysis. ### Working example ``` indicator("My first EMA", overlay=true) length = input.int(20, "Length", minval=1) average = alerta.ta.ema(close, length) plot(average, "EMA", color=color.blue, linewidth=2) plot(close, "Close", color=color.new(color.gray, 80)) ``` - [Editor tour](https://www.alertachart.com/alertascript/getting-started/editor-tour): Write, run, save and inspect your script. ### How it works The editor brings code, templates and execution feedback together. The Documentation button opens the documentation website in a separate tab. Contextual help on a function provides its reference link without replacing the code you are editing. ### Put it into practice Read the exact line and message when execution fails. If an existing draft is being edited, opening a documentation example preserves it and offers a separate tab. Examples are not run or saved automatically; inspect the code before doing either. - [Your first indicator](https://www.alertachart.com/alertascript/getting-started/first-indicator): Create an RSI with editable inputs and reference levels. ### How it works An indicator calculates values without simulating orders. overlay=false places the RSI in its own pane; input.int exposes the lookback; hline adds stable comparison levels at 70 and 30. ### Put it into practice Run the example on two timeframes and inspect the same historical segment. Inputs change the calculation, while colors and line styles change its presentation. Keep plot titles descriptive because they also help identify values and alert placeholders. ### Working example ``` indicator("My RSI", overlay=false) length = input.int(14, "Length", minval=1) rsi = alerta.ta.rsi(close, length) plot(rsi, "RSI", color=color.blue) hline(70, "Upper") hline(30, "Lower") ``` - [Your first strategy](https://www.alertachart.com/alertascript/getting-started/first-strategy): Turn an EMA crossover into a testable trading rule. ### How it works A strategy declaration enables simulated order logic. The example opens a long position when the fast EMA crosses above the slow EMA and closes the matching entry when the cross reverses. Entry IDs connect related order actions. ### Put it into practice Inspect trades and performance in the Strategy Tester. A plotted signal is not necessarily the fill price: order timing and the available bar data matter. Check position size, fees and the test interval before interpreting results; a strategy script does not by itself send live exchange orders. ### Working example EMA(10) crossing above EMA(30) enters Long; crossing below closes Long. This compares two averages, not price against an average. The code has no explicit barstate.isconfirmed guard. Evaluation and simulated fills depend on strategy execution settings; the script neither creates a notification subscription nor sends live orders. ``` strategy("EMA cross", overlay=true) fast = ta.ema(close, 10) slow = ta.ema(close, 30) if ta.crossover(fast, slow) strategy.entry("Long", strategy.long) if ta.crossunder(fast, slow) strategy.close("Long") plot(fast, "Fast") plot(slow, "Slow") ``` ### Continue reading - [Your first alert](https://www.alertachart.com/alertascript/getting-started/first-alert): Expose a named condition in the alert workflow. ### How it works alertcondition registers a title, a boolean series and a message. The example names an upward EMA cross so the condition can be identified in the alert interface. The ticker placeholder is resolved when the event is produced. ### Put it into practice Run the script, create the corresponding alert and verify its condition and notification settings. An intrabar cross can disappear before the candle closes. Decide whether you want live-bar behavior or a confirmed-close signal; script execution alone is not a promise of unattended server monitoring. ### Working example Here close crosses above EMA(20): the preceding close was at or below its EMA and the current price is above it. This is price versus one EMA, not two EMA lines. There is no barstate.isconfirmed guard, so the live-bar condition may change. Running the script only registers the condition; create an alert and choose its frequency and notification channels separately. ``` indicator("EMA cross alert", overlay=true) average = ta.ema(close, 20) signal = ta.crossover(close, average) plot(average, "EMA") alertcondition(signal, "Close above EMA", "{{ticker}} crossed above EMA") ``` ### Continue reading - [Language guide](https://www.alertachart.com/alertascript/language): Understand the building blocks behind chart scripts. ### How it works AlertaScript combines familiar Pine-compatible expressions with chart series, collections and drawing objects. Learn how values evolve across bars before moving into reusable functions, arrays or multi-timeframe requests. ### Put it into practice Read syntax and series first. Then follow the sections for the data structures your script actually uses. A numeric series, an array and a drawing ID are different kinds of values, even when all three are stored in variables. ### Continue reading - [Syntax and types](https://www.alertachart.com/alertascript/language/syntax-and-types): Declare values, pass arguments and keep types explicit. ### How it works Use = for a declaration and := when reassigning an existing variable in Pine-style code. int, float, bool, string and color describe different values. Named arguments make optional settings easier to read. ### Put it into practice Give ambiguous values an explicit type, especially when initializing with na. Match each argument to the function signature rather than relying on automatic conversion. Use typed inputs such as input.int or input.bool so settings express the intended value type. ### Working example ``` indicator("Typed inputs", overlay=true) int length = input.int(20, "Length", minval=1) float source = close bool rising = close > open plot(ta.ema(source, length), "EMA", color=rising ? color.green : color.red) ``` - [Series and history](https://www.alertachart.com/alertascript/language/series-and-history): Read the current bar and earlier values safely. ### How it works close is the current price series; close[1] reads the preceding bar. The bracket is a history offset, not an array position. The first loaded bar has no previous value, so history-dependent expressions can produce na. Inside a function, x[1] of a parameter or a local variable is its value at the function's previous call, so a function called only on some bars looks back to its previous call, not to the previous bar. ### Put it into practice Check na before dividing, comparing or drawing from unavailable history. A longer lookback needs sufficient loaded bars. Avoid replacing missing prices with zero just to force a visible result: that changes the meaning of averages, returns and signals. ### Working example ``` indicator("Bar change", overlay=false) previous = close[1] change = na(previous) ? na : close - previous plot(change, "Change", style=plot.style_histogram) ``` - [Control flow](https://www.alertachart.com/alertascript/language/control-flow): Express conditions and bounded repetition. ### How it works if selects a branch, a ternary expression selects a value, and loops repeat a block. Conditions are evaluated in the current bar context. Compute reusable time-series indicators consistently, then use conditions to decide what to display or trade. ### Put it into practice Keep loops bounded and stop when the intended result is found. For small choices, a ternary expression is often clearer than a loop. Be especially careful with loops that grow a collection on every bar; their cost increases with chart history. ### Working example ``` indicator("Bar direction", overlay=false) direction = close > open ? 1 : close < open ? -1 : 0 plot(direction, "Direction", style=plot.style_histogram) ``` - [Functions](https://www.alertachart.com/alertascript/language/functions): Extract a calculation without hiding its inputs. ### How it works A user function names a repeatable calculation and returns its final expression. Pass required series and parameters explicitly so callers can see what influences the result. Typed parameters make custom helpers easier to inspect. Arguments can be named at the call site, as in f(close, length = 50); they are evaluated in the order written. Methods with the same name can be declared for several types: the type of the receiver picks the method. A function can be declared more than once with a different number or type of parameters; each call runs the declaration its arguments match. A function cannot call itself, and it cannot change a variable declared outside it with :=; both are errors that say what to write instead. ### Put it into practice The range example divides the candle range by its price basis and handles a zero basis. Test helpers with missing values and boundary inputs before using them in a strategy. Distinguish your own function names from documented built-ins and aliases. ### Working example ``` indicator("Relative range", overlay=false) relativeRange(float hi, float lo, float basis) => basis == 0 ? na : (hi - lo) / basis * 100 plot(relativeRange(high, low, close), "Range %") ``` - [User-defined types and methods](https://www.alertachart.com/alertascript/language/user-defined-types-and-methods): Group related values and attach meaningful operations. ### How it works A type declaration describes fields; its constructor creates an instance. A method uses a typed first parameter as its receiver. The example groups a high and low price, then exposes their width as a method. ### Put it into practice Use types for coherent records such as a price zone or trade state. chart.point is a built-in type, not a price-series variable. Keep user-defined field and method names separate from global built-ins when reading errors or searching the reference. ### Working example ``` indicator("Price range", overlay=false) type PriceRange float hi float lo method width(PriceRange this) => this.hi - this.lo range = PriceRange.new(high, low) plot(range.width(), "Range") ``` - [Arrays](https://www.alertachart.com/alertascript/language/arrays): Manage an ordered collection with explicit bounds. ### How it works Arrays store multiple values inside one object. array.get and array.set use zero-based indices; close[1] instead accesses bar history. A var array can persist between bars, so additions accumulate unless you remove old values. ### Put it into practice The example keeps only the most recent 20 samples by shifting the oldest after each push. Check array.size before indexing or removing an element. Choose a maximum length deliberately; an ever-growing array is rarely necessary for a rolling calculation. An index past the end stops the script with an error. In a //@version=6 script a negative index counts from the end, so array.get(a, -1) is the last element. array.slice returns a view: writing an element of the slice changes the original array. ### Working example ``` indicator("Array average", overlay=true) var samples = array.new(0) array.push(samples, close) if array.size(samples) > 20 array.shift(samples) plot(array.avg(samples), "Average") ``` ### Continue reading - [Maps](https://www.alertachart.com/alertascript/language/maps): Look up values by named keys. ### How it works A map stores key-value pairs and is useful when position is less meaningful than identity. map.put creates or replaces a value under a key; map.get retrieves it. Key and value types are specified when the map is constructed. ### Put it into practice Choose stable keys such as level names and check map.contains when absence is possible. Reusing a key replaces its value rather than appending a second item. Use an array when ordering and numeric positions are the primary requirement. ### Working example ``` indicator("Named levels", overlay=true) levels = map.new() map.put(levels, "high", high) map.put(levels, "low", low) plot(map.get(levels, "high"), "High") ``` - [Matrices](https://www.alertachart.com/alertascript/language/matrices): Represent and access rectangular numeric data. ### How it works Matrices organize values by row and column. matrix.new sets the dimensions and initial value; matrix.set updates a cell; matrix.get reads it. Both coordinates are zero-based. ### Put it into practice Check dimensions before indexing and ensure compatible sizes before combining matrices. Keep the example small while verifying row and column orientation. A matrix represents a structured collection, not automatically a window of historical bars. ### Working example ``` indicator("Matrix example", overlay=false) values = matrix.new(2, 2, 0.0) matrix.set(values, 0, 0, close) matrix.set(values, 1, 1, open) plot(matrix.get(values, 0, 0) - matrix.get(values, 1, 1), "Body") ``` - [Strings](https://www.alertachart.com/alertascript/language/strings): Format clear labels and messages. ### How it works Strings carry titles, symbols and human-readable text. Concatenate strings with + and format numeric values with str.tostring. format.mintick follows the symbol price precision and avoids arbitrary decimal counts. str.tonumber reads only plain decimals such as 1234.5 or -12; text such as 1,234 or 1e3 gives na. An na string joined with + counts as empty text. Without a format, str.tostring writes a number with at most ten decimals and no exponent, so 0.1 + 0.2 gives 0.3, and na is written as NaN. str.format reads Pine's placeholders, such as {0}, {0,number,#.##} and {0,number,percent}. ### Put it into practice Use a stable plot title and concise alert text. Creating a new label on every update can accumulate objects; retain and update an existing label for a lasting dashboard. String formatting changes presentation, not the underlying numeric calculation. ### Working example ``` indicator("Price label", overlay=true) if barstate.islast label.new(bar_index, high, syminfo.ticker + " " + str.tostring(close, format.mintick)) ``` - [Colors](https://www.alertachart.com/alertascript/language/colors): Separate a visual rule from its calculation. ### How it works A color can be selected by a condition and passed to plots, candles or backgrounds. color.new adds transparency: 0 is opaque and 100 is fully transparent. The example colors bullish and bearish bars independently of any trading order. The transparency replaces the color's own: color.new(c, 0) is opaque even when c was translucent. It can also change from bar to bar. ### Put it into practice Use translucent backgrounds so candles remain readable. Check both light and dark themes, and use titles or shapes as well as color to convey meaning. Changing a plot color should not alter the signal calculation. ### Working example ``` indicator("Candle colors", overlay=true) tint = close >= open ? color.teal : color.red barcolor(tint) bgcolor(color.new(tint, 94)) ``` - [Time and sessions](https://www.alertachart.com/alertascript/language/time-and-sessions): Interpret bar time in the correct market context. ### How it works time exposes bar timestamps; time() can filter bars by timeframe, session and timezone. A session expression such as 0930-1600:23456 defines weekdays and hours in the supplied timezone. Outside that session the result is na. ### Put it into practice Prefer named zones such as America/New_York when daylight saving changes matter. Exchange sessions do not always start at midnight, and extended-hours bars depend on the data feed. Separate a chart display timezone from the session timezone used by your rule. ### Working example ``` indicator("Session", overlay=true) inSession = not na(time(timeframe.period, "0930-1600:23456", "America/New_York")) bgcolor(inSession ? color.new(color.blue, 92) : na) ``` - [Execution model](https://www.alertachart.com/alertascript/language/execution-model): Know what can change before the bar closes. ### How it works Scripts calculate against chart bars and update as current data changes. Historical bars have completed OHLCV values; a live bar is still forming. var preserves initialized state across bars, while history references read earlier series values. ### Put it into practice Use barstate.isconfirmed when a rule explicitly requires a completed candle. Test both historical results and live updates. After a symbol, timeframe or input change, a script may recalculate over the available dataset; do not treat in-memory state as permanent storage. ### Working example ``` indicator("Confirmed close", overlay=true) value = barstate.isconfirmed ? close : na plot(value, "Confirmed close", style=plot.style_circles) ``` - [Guides](https://www.alertachart.com/alertascript/guides): Connect language features into practical workflows. ### How it works These guides combine calculations with chart output, simulated trades, external contexts and alerts. Start from the result you want to inspect and keep data availability separate from the rule that processes it. ### Put it into practice Use the drawing guide for overlays, the strategy guide for order simulation and the multi-timeframe guide for request contexts. For an existing Pine script, read the migration guide before changing working names or syntax. ### Continue reading - [Drawings and visuals](https://www.alertachart.com/alertascript/guides/drawing-and-visuals): Choose between series plots and positioned objects. ### How it works plot follows a series across bars; line, label, box and table create objects with their own lifetimes and coordinates. A line can use bar indices or timestamps depending on xloc. These coordinate systems are not interchangeable. ### Put it into practice The example deletes its previous last-bar line before creating a replacement. For persistent objects, keep an ID and use set methods when appropriate. Limit object creation and verify extension, scale and pane placement instead of creating an object on every update. ### Working example ``` indicator("Last-bar range", overlay=true) var line rangeLine = na if barstate.islast line.delete(rangeLine) rangeLine := line.new(bar_index, low, bar_index, high, color=color.blue, width=2) ``` - [Strategies and backtesting](https://www.alertachart.com/alertascript/guides/strategies-and-backtesting): Interpret simulated orders and exits correctly. ### How it works strategy.entry opens simulated entries; strategy.close closes an entry ID; strategy.exit attaches exit rules. In strategy.exit, profit and loss are distances in ticks, while limit and stop are absolute prices. They are not interchangeable percentages. Within a bar, orders fill in the order the price reaches them: market orders at the open, then resting orders along the path open, nearer extreme, farther extreme, close. Orders are kept by id: two entries of other ids on one bar both fill (within pyramiding), a resting limit or stop waits beside later orders, and an OCA group answers when one of its orders fills. ### Put it into practice Verify tick size, quantity, fees and fill assumptions before comparing strategies. Separate the signal bar from the simulated fill, and inspect individual trades as well as aggregate performance. Historical results depend on the supplied data and do not guarantee future outcomes. A new alert created on a strategy fires on every order fill by default. ### Working example ``` strategy("EMA with exit", overlay=true) average = ta.ema(close, 20) if ta.crossover(close, average) strategy.entry("Long", strategy.long) strategy.exit("Exit", "Long", profit=100, loss=50) plot(average, "EMA") ``` - [Multiple symbols and timeframes](https://www.alertachart.com/alertascript/guides/multi-symbol-and-timeframe): Evaluate an expression in another data context. ### How it works request.security evaluates its expression for the requested symbol and timeframe, then aligns the result to the chart. A higher-timeframe EMA is calculated from higher-timeframe bars; requesting close and averaging it afterward is a different calculation. The symbol and timeframe can come from inputs, variables or a loop, and a request can sit inside an if block or a function. The expression may also return a string, a color, an array or a user-defined type. ### Put it into practice Use lookahead_off for a baseline without future-bar alignment. An unconfirmed higher-timeframe candle can still change. Check gaps, market sessions and symbol availability; a syntactically valid request does not establish that every exchange or asset has the same historical coverage. ### Working example ``` indicator("Hourly EMA", overlay=true) hourly = request.security(syminfo.tickerid, "60", ta.ema(close, 20), lookahead=barmerge.lookahead_off) plot(hourly, "Hourly EMA", color=color.blue) ``` ### Continue reading - [Order flow data](https://www.alertachart.com/alertascript/guides/order-flow-data): Use available trade-level information deliberately. ### How it works request.footprint returns a footprint object when the chart has the required order-flow data. The object exposes bar delta, volume rows and profile information. A missing footprint is na, not a zero-volume bar. ### Put it into practice Guard access with na checks, as in the delta example. request.security also reads order-flow series by ticker: BINANCE:BTCUSDT.P_OI, .P_FUNDING, .P_CVD, BINANCE:BTCUSDT_CVD, .P_NETLONG, .P_NETSHORT, .P_LIQ_LONG, .P_LIQ_SHORT — open interest and net positions in coins, funding as a decimal rate per 8 h, cumulative delta in coins (spot without .P), liquidations as USD notional. Name a venue (BINANCE, BYBIT, OKX, COINBASE, HYPERLIQUID) or sum them all with AGG:BTC.P_…; coverage differs by venue, and a series a venue lacks is na. These tickers come with the Pro and Elite plans; on other plans they return na with a warning. ### Working example ``` indicator("Bar delta", overlay=false) footprint fp = request.footprint(10) delta = na(fp) ? na : fp.delta() plot(delta, "Bar delta", style=plot.style_histogram) ``` ### Continue reading - [Alerts](https://www.alertachart.com/alertascript/guides/alerts): Separate the signal, its timing and its message. ### How it works alertcondition exposes a named condition; alert emits an event from the executing code path. alert.freq_once_per_bar_close delays dispatch until the candle closes, while other frequency modes permit different live-bar behavior. ### Put it into practice Use readable titles and supported placeholders such as {{ticker}}. Check the configured alert in the interface and test a reachable condition. Runtime events and notification delivery are distinct; verify monitoring and delivery settings rather than assuming a script runs continuously after its chart is closed. ### Working example This example uses the same price-above-EMA(20) crossover, with alert.freq_once_per_bar_close. The condition must be true at the closing update; an earlier intrabar cross that reverses is insufficient. Create an alert for the script’s alert() events and configure notifications separately. ``` indicator("Bar-close alert", overlay=true) average = ta.ema(close, 20) if ta.crossover(close, average) alert("{{ticker}} crossed above EMA", alert.freq_once_per_bar_close) plot(average, "EMA") ``` - [Pine compatibility and migration](https://www.alertachart.com/alertascript/guides/pine-migration): Move a Pine-style script to AlertaScript: what runs as written, what returns na, and three tested examples. ### How it works AlertaScript supports a broad Pine-compatible surface, including namespaced calls, collections, types and strategies. Supported names such as ta.ema and alerta.ta.ema resolve to the same calculation. Existing compatible spelling can run without a naming warning. The documentation writes AlertaScript functions with the alerta. prefix so you can tell them apart, but nothing has to be renamed: code written with ta.*, math.*, str.* or strategy.* can be pasted as it is. The editor does not rewrite what you paste; it runs exactly the code you see. ### Put it into practice Start by running the original script and inspect actual diagnostics. Search by the original name or its AlertaScript spelling before replacing anything. Data-feed availability, live-bar behavior and simulation assumptions still require checking; an accepted function name alone does not prove every external dataset exists. ### Run the original script first Open Alerta Script from the Indicators menu of the chart, paste the script without changes and press Run. Problems are reported with their line and message. A Run that ends without an error also saves the script under My scripts; warnings do not block it. - An error stops the run. Read its line, then search this documentation by the original function name or by its alerta. spelling before you change code. - A warning lets the script run and explains a value it could not supply, for example a request that returns na. - An empty chart is not always an error: bars without enough history, na results, an oscillator in its own pane or a request for data the chart does not have all leave a plot empty. ### One calculation, two spellings Both lines come from the same 20-period EMA and lie on top of each other. Keep whichever spelling your code already uses. ``` indicator("EMA spellings", overlay=true) original = ta.ema(close, 20) prefixed = alerta.ta.ema(close, 20) plot(original, "TradingView-compatible") plot(prefixed, "AlertaScript", color=color.blue) ``` ### Migration checklist Go through these parts of every script you move. Most need no change; the point is to know which values depend on data rather than on syntax. Part of the script | What to check Declaration | indicator(...) or strategy(...), the title and overlay. overlay=false puts the output in its own pane. Inputs | Defaults and the minimum and maximum of input.int, input.float, input.timeframe and the others. They become the settings behind the gear of the script on the chart. Calculations | Each ta.*, math.* or array.* function you call has a reference page. Search by the name you know. Other symbols and timeframes | Every request.security call: the symbol must exist on AlertaChart and have history for the period you look at. Fundamental data | request.financial, request.earnings, request.dividends and request.splits return na (next section). Alerts | alertcondition titles and messages, and whether a condition has to wait for the candle to close. Strategy settings | Initial capital, order size, commission and pyramiding in strategy(...). The Strategy tester settings can change them later without editing the code. Drawings | line, label, box and table objects. Execution and drawing resources are bounded, so delete objects you no longer need instead of creating new ones on every bar. ### What returns na or is not supported These limits come from the data AlertaChart has, not from the language. A script that relies on them still runs, but the values involved stay empty, so judge a migration by its output and not only by the absence of errors. Call | In AlertaScript request.financial, request.earnings, request.dividends, request.splits | Return na because there is no fundamentals feed. The editor shows a warning unless the call passes ignore_invalid_symbol = true. request.seed, request.quandl | Not supported. They return na with a warning. request.security on ticker.renko, ticker.kagi, ticker.linebreak or ticker.pointfigure | Returns na with a warning: these bars are not built. ticker.heikinashi works; its bars are built from the symbol's own bars. syminfo.current_contract | Not supported. It does not give a contract code. Footprint and open-interest data (request.footprint, tickers such as BINANCE:BTCUSDT.P_OI) | Pro and Elite plans, on supported markets and timeframes. On other plans they return na with a warning (see the order flow guide below). Historical depth | Depends on the chart and its data source, so a long lookback can start later than on another platform. ### Example: EMA crossover strategy A complete strategy with three inputs. It opens a long position when the 9-period EMA crosses above the 21-period EMA, closes it on the opposite cross and keeps a protective stop 2 % below the average entry price. It is a rule to study, not a recommendation. Before you run it: - strategy(...) sets what the Strategy tester starts from: 10,000 initial capital, 10 % of equity per order and 0.1 % commission. - stop= in strategy.exit is an absolute price, so the example turns the percentage input into a price. profit= and loss= would be distances in ticks. - In the simulation, an order placed on the signal bar fills at the open of the next bar, so the marked signal and the fill price are different prices. - Read the trades in the Strategy tester under the chart. A strategy script does not send orders to an exchange. ``` //@version=5 strategy("EMA crossover strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1) fastLength = input.int(9, "Fast EMA length", minval=1) slowLength = input.int(21, "Slow EMA length", minval=2) stopPercent = input.float(2.0, "Stop loss (%)", minval=0.1, step=0.1) fast = ta.ema(close, fastLength) slow = ta.ema(close, slowLength) crossUp = ta.crossover(fast, slow) crossDown = ta.crossunder(fast, slow) if crossUp strategy.entry("Long", strategy.long) if crossDown strategy.close("Long", comment="EMA cross down") // A protective stop: an absolute price, recalculated from the average entry price. if strategy.position_size > 0 strategy.exit("Stop", "Long", stop=strategy.position_avg_price * (1 - stopPercent / 100)) plot(fast, "Fast EMA", color=color.teal) plot(slow, "Slow EMA", color=color.orange) plotshape(crossUp, title="Cross up", style=shape.triangleup, location=location.belowbar, color=color.teal, size=size.tiny) ``` ### Example: RSI divergence with alert conditions An indicator in its own pane. It compares RSI pivots with price: a lower price low on a higher RSI low is marked as bullish, a higher price high on a lower RSI high as bearish. Two named alert conditions make each case selectable when you create an alert. Before you run it: - A pivot needs pivotBars bars on its right. With the default of 5, a divergence is confirmed five bars after the pivot; offset draws the mark back on the pivot bar, which is where history shows it. - Running the script only defines the conditions. Alerts on a script come with the Pro and Elite plans: open Create Alert, choose Script as the source and this script, pick the condition by its title under Script alerts and check the notification settings. {{ticker}} is replaced by the symbol when the alert fires. - A divergence describes momentum; it does not say when or whether price turns. ``` //@version=5 indicator("RSI divergence finder", overlay=false) rsiLength = input.int(14, "RSI length", minval=2) pivotBars = input.int(5, "Bars on each side of a pivot", minval=1) rsi = ta.rsi(close, rsiLength) // A pivot is only known pivotBars bars after it formed. rsiLow = ta.pivotlow(rsi, pivotBars, pivotBars) rsiHigh = ta.pivothigh(rsi, pivotBars, pivotBars) newLow = not na(rsiLow) newHigh = not na(rsiHigh) // RSI and price at the previous pivot of the same kind. lastRsiLow = ta.valuewhen(newLow, rsi[pivotBars], 1) lastPriceLow = ta.valuewhen(newLow, low[pivotBars], 1) lastRsiHigh = ta.valuewhen(newHigh, rsi[pivotBars], 1) lastPriceHigh = ta.valuewhen(newHigh, high[pivotBars], 1) // Price makes a lower low while RSI makes a higher low (bullish), or the reverse at highs (bearish). bullish = newLow and low[pivotBars] < lastPriceLow and rsi[pivotBars] > lastRsiLow bearish = newHigh and high[pivotBars] > lastPriceHigh and rsi[pivotBars] < lastRsiHigh plot(rsi, "RSI", color=color.purple) hline(70, "Upper level") hline(30, "Lower level") plot(bullish ? rsi[pivotBars] : na, "Bullish divergence", color=color.green, style=plot.style_circles, linewidth=4, offset=-pivotBars) plot(bearish ? rsi[pivotBars] : na, "Bearish divergence", color=color.red, style=plot.style_circles, linewidth=4, offset=-pivotBars) alertcondition(bullish, "Bullish RSI divergence", "{{ticker}}: bullish RSI divergence confirmed") alertcondition(bearish, "Bearish RSI divergence", "{{ticker}}: bearish RSI divergence confirmed") ``` ### Example: higher-timeframe trend filter request.security evaluates the whole expression on the requested timeframe, here a 50-period EMA of 4-hour bars, and aligns the result with the chart. One call returns both values as a tuple. Before you run it: - Requesting close and averaging it on the chart would be a different calculation from an EMA computed on 4-hour bars. - lookahead=barmerge.lookahead_off is the baseline without future bars. While the current 4-hour candle is open, its values can still change. - input.timeframe lets you pick another higher timeframe from the settings without editing the code. ``` //@version=5 indicator("Higher-timeframe trend filter", overlay=true) higherTf = input.timeframe("240", "Higher timeframe") emaLength = input.int(50, "EMA length on the higher timeframe", minval=1) // One request returns both values, each calculated on the higher timeframe's own bars. [htfEma, htfClose] = request.security(syminfo.tickerid, higherTf, [ta.ema(close, emaLength), close], lookahead=barmerge.lookahead_off) uptrend = htfClose > htfEma plot(htfEma, "Higher-timeframe EMA", color=uptrend ? color.teal : color.red, linewidth=2) bgcolor(uptrend ? color.new(color.teal, 92) : color.new(color.red, 92), title="Trend background") ``` ### Differences to expect Identical code can still show different numbers on two platforms. These are the usual reasons: - Live and closed bars: scripts recalculate while the current candle forms. Use barstate.isconfirmed when a rule must wait for the close. - Alerts: alert.freq_once_per_bar_close waits for the close. Running a script is not, by itself, unattended monitoring on a server. - Strategy fills: within a bar, market orders fill at the open and resting orders along the path open, nearer extreme, farther extreme, close. Match quantity, commission and the test range before comparing reports. - Data: compare the same symbol, exchange and timeframe. The same pair on two exchanges is two different series. - Resources: execution and drawing are bounded. The limits page does not publish fixed numbers, so keep loops and object counts bounded instead of relying on one. ### Continue reading - [Quick reference](https://www.alertachart.com/alertascript/reference): Find signatures, constants, variables and examples. ### How it works The reference separates callable functions from variables, types and constant families. Each function page describes arguments, return values, accepted spellings and an example. Search accepts both AlertaScript-prefixed and compatible original names. ### Put it into practice Use parameter names and types to resolve call errors. A variable is read directly; a function is called with parentheses; a constant selects a documented mode. Reference descriptions may remain in English while navigation and guides follow your chosen language. ### Continue reading - [Frequently asked questions](https://www.alertachart.com/alertascript/faq): Answers to common script authoring questions. ### How it works A blank output is not always an execution failure: early history, na results, pane placement or unavailable requested data can explain it. A strategy simulates orders, while an indicator only calculates and draws unless you add an alert workflow. ### Put it into practice Use troubleshooting for a reproducible error and limitations for data and runtime boundaries. Before reporting a mismatch, compare the same symbol, exchange, timeframe and settings. Include the smallest script that still demonstrates the behavior. ### Continue reading - [Limits and availability](https://www.alertachart.com/alertascript/faq/limitations): Know the boundaries that affect a script result. ### How it works Execution and drawing resources are bounded, and historical depth depends on the chart and data source. Footprint and open-interest data are available only for supported contexts and with the Pro and Elite plans. request.financial, request.earnings, request.dividends and request.splits return na because there is no fundamentals feed, with a warning unless the call passes ignore_invalid_symbol = true; request.seed and request.quandl are not supported and return na too. In request.security, Renko, Kagi, Line Break and Point & Figure tickers return na with a warning; Heikin-Ashi tickers are built from the symbol's own bars. ### Put it into practice Check each reference entry for its actual behavior. syminfo.current_contract is not supported. Avoid inventing numeric limits that are not documented; reduce unbounded loops and object growth, handle unavailable values and verify the dataset before blaming the calculation. - [Troubleshooting](https://www.alertachart.com/alertascript/faq/troubleshooting): Reduce an error to a small, inspectable case. ### How it works Start with the reported line and exact message. Check spelling, argument order, types and missing history. If the script runs but draws nothing, inspect na results, overlay placement, transparency and the requested symbol or timeframe. ### Put it into practice Keep a copy, remove unrelated logic and reproduce with the same settings. Use the editor Feedback flow to send the failing code and diagnostics when you choose to submit them. Never include API keys, passwords or other secrets in a support example. ### Working example ``` indicator("Safe change", overlay=false) previous = close[1] change = na(previous) or previous == 0 ? na : (close / previous - 1) * 100 plot(change, "Change %") ``` - [Write with AI](https://www.alertachart.com/alertascript/ai-writing): Ask for a script that can be checked, not just generated. ### How it works Give the assistant your market, timeframe, inputs, exact entry or alert rule and expected output. Point it to the AlertaScript reference and ask it to use documented functions and supported datasets. A precise rule is easier to verify than a request for a profitable indicator. ### Put it into practice Ask for one complete script plus a short explanation of bar-close behavior, na handling and any request.security calls. Run it, inspect the output and test boundary cases before adding complexity. Keep original compatible names when supported; do not mechanically rename every call. ### Continue reading ## API reference ### alerta.ta.barssince https://www.alertachart.com/alertascript/reference/builtins/ta.barssince Signature: ta.barssince(condition) Counts the number of bars since the condition was true. TradingView-compatible spelling: ta.barssince; runs without warnings. - condition: series bool; required: true; default: not specified. Condition to evaluate. Returns: series int ``` indicator("Bars Since Example") // Search latest cross condition const isCross = ta.crossover(close, ta.sma(close, 20)) const barsPassed = ta.barssince(isCross) plot(barsPassed, { title: "Bars Since Cross", color: "#F59E0B" }) ``` Aliases: ta.barssince ### alerta.ta.cum https://www.alertachart.com/alertascript/reference/builtins/ta.cum Signature: ta.cum(source) Calculates the cumulative sum of source. TradingView-compatible spelling: ta.cum; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. Returns: series float ``` indicator("Cumulative Volume", overlay=false) // Track running total of volume across all bars const totalVol = ta.cum(volume) plot(totalVol, { title: "Total Volume", color: "#3B82F6", style: "area" }) ``` Aliases: ta.cum ### alerta.ta.sma https://www.alertachart.com/alertascript/reference/builtins/sma Signature: sma(source, length) Calculates the simple moving average over an N-bar period. TradingView-compatible spelling: ta.sma; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(sma(close, 20)) ``` Aliases: ta.sma ### alerta.ta.ema https://www.alertachart.com/alertascript/reference/builtins/ema Signature: ema(source, length) Calculates the exponential moving average, assigning more weight to recent prices. TradingView-compatible spelling: ta.ema; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(ema(close, 20)) ``` Aliases: ta.ema ### alerta.ta.wma https://www.alertachart.com/alertascript/reference/builtins/wma Signature: wma(source, length) Calculates the weighted moving average. TradingView-compatible spelling: ta.wma; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(wma(close, 15)) ``` Aliases: ta.wma ### alerta.ta.vwma https://www.alertachart.com/alertascript/reference/builtins/vwma Signature: vwma(source, length) Returns the volume-weighted moving average of source for length bars. TradingView-compatible spelling: ta.vwma; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(vwma(close, 20)) ``` Aliases: ta.vwma ### alerta.ta.rma https://www.alertachart.com/alertascript/reference/builtins/rma Signature: rma(source, length) Wilder's smoothing average (Relative Moving Average), the smoothing RSI and ATR are defined with. It follows Pine's recurrence: the first value is the simple average of the first length values, then alpha * source + (1 - alpha) * previous with alpha = 1 / length. TradingView-compatible spelling: ta.rma; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` const rmaLine = rma(close, 14) ``` Aliases: ta.rma ### alerta.ta.macd https://www.alertachart.com/alertascript/reference/builtins/macd Signature: macd(source, fast, slow, signal) Returns MACD line, Signal line and Histogram. TradingView-compatible spelling: ta.macd; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - fast: int; required: true; default: not specified. Fast EMA length. - slow: int; required: true; default: not specified. Slow EMA length. - signal: int; required: not specified; default: 9. Signal line length. Returns: [macdLine, signalLine, histogram] ``` indicator("MACD Pro", overlay=false) [macdLine, signalLine, hist] = macd(close, 12, 26, 9) plot(macdLine, { title: "MACD Line", color: color.blue, pane: "oscillator" }) plot(signalLine, { title: "Signal Line", color: color.orange, pane: "oscillator" }) plot(hist, { title: "Histogram", style: "histogram", pane: "oscillator" }) ``` Aliases: ta.macd ### alerta.ta.rsi https://www.alertachart.com/alertascript/reference/builtins/rsi Signature: rsi(source, length) Calculates the RSI, an oscillator measuring the speed and change of price movements. TradingView-compatible spelling: ta.rsi; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` indicator("RSI Pro", overlay=false) r = rsi(close, 14) plot(r, { title: "RSI", color: color.purple, pane: "oscillator" }) h1 = hline(70, { title: "Overbought", color: color.red, style: "dashed", pane: "oscillator" }) h2 = hline(30, { title: "Oversold", color: color.green, style: "dashed", pane: "oscillator" }) fill(h1, h2, { color: "rgba(168, 85, 247, 0.05)", pane: "oscillator" }) ``` Aliases: ta.rsi ### alerta.ta.roc https://www.alertachart.com/alertascript/reference/builtins/roc Signature: roc(source, length) Calculates the Rate of Change (percent) over an N-bar period. TradingView-compatible spelling: ta.roc; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(roc(close, 9), { pane: "oscillator" }) ``` Aliases: ta.roc ### alerta.ta.mom https://www.alertachart.com/alertascript/reference/builtins/mom Signature: mom(source, length) Calculates the momentum (difference) over an N-bar period. TradingView-compatible spelling: ta.mom; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(mom(close, 10), { pane: "oscillator" }) ``` Aliases: ta.mom ### alerta.ta.kst https://www.alertachart.com/alertascript/reference/builtins/kst Signature: kst(source, roc1, roc2, roc3, roc4, sma1, sma2, sma3, sma4) Weighted momentum oscillator built from four smoothed ROC components. TradingView-compatible spelling: ta.kst; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - roc1: int; required: false; default: not specified. ROC period 1 (default 10). - roc2: int; required: false; default: not specified. ROC period 2 (default 15). - roc3: int; required: false; default: not specified. ROC period 3 (default 20). - roc4: int; required: false; default: not specified. ROC period 4 (default 30). - sma1: int; required: false; default: not specified. Smoothing for ROC1 (default 10). - sma2: int; required: false; default: not specified. Smoothing for ROC2 (default 10). - sma3: int; required: false; default: not specified. Smoothing for ROC3 (default 10). - sma4: int; required: false; default: not specified. Smoothing for ROC4 (default 15). Returns: series float ``` plot(kst(close, 10, 15, 20, 30, 10, 10, 10, 15), { pane: "oscillator" }) ``` Aliases: ta.kst ### alerta.ta.specialK https://www.alertachart.com/alertascript/reference/builtins/ta.specialk Signature: ta.specialK(source, length1, length2) Martin J. Pring's Special K: twelve simple averages of rates of change, from a 10-bar to a 530-bar ROC, weighted 1-2-3-4 within the short, medium and long groups and summed, with a signal line that is a simple average of a simple average of it. Needs about 725 bars of history before its first value. TradingView-compatible spelling: ta.specialK; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length1: int; required: false; default: 100. Length of the first simple average of the signal line. - length2: int; required: false; default: 100. Length of the second simple average of the signal line. Returns: [specialK, signal] ``` [sk, signal] = ta.specialK(close, 100, 100) plot(sk, { title: "Special K", pane: "oscillator" }) plot(signal, { title: "Signal", pane: "oscillator" }) ``` Special K = Σ w·SMA(ROC(n), m) over (n, m, w) = (10,10,1) (15,10,2) (20,10,3) (30,15,4) (40,50,1) (65,65,2) (75,75,3) (100,100,4) (195,130,1) (265,130,2) (390,130,3) (530,195,4), ROC in percent; signal = SMA(SMA(Special K, length1), length2). Source: Martin J. Pring, "Technical Analysis Explained", 5th ed. Reached through a `TradingView/ta` import alias too (`TVta.specialK`). Aliases: ta.specialK ### alerta.ta.tr https://www.alertachart.com/alertascript/reference/builtins/tr Signature: ta.tr(handle_na = false) or tr(high, low, close) Calculates the True Range for each bar. Pine v6 form is `ta.tr(handle_na)` operating on chart H/L/C; a legacy 3-arg form accepting custom series is also supported. TradingView-compatible spelling: ta.tr; runs without warnings. - handle_na: series bool; required: false; default: not specified. If true, returns high - low when the previous close is na (avoids na in the first bars). Defaults to false. (Pine v6 form: ta.tr(handle_na)) - low: series; required: false; default: not specified. Low series — legacy 3-arg form only. - close: series; required: false; default: not specified. Close series — legacy 3-arg form only. Returns: series float ``` plot(ta.tr(true), { pane: "oscillator" }) plot(tr(high, low, close), { pane: "oscillator" }) ``` Aliases: ta.tr ### alerta.ta.cmo https://www.alertachart.com/alertascript/reference/builtins/cmo Signature: cmo(source, length) Calculates the Chande Momentum Oscillator over an N-bar period. TradingView-compatible spelling: ta.cmo; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(cmo(close, 14), { pane: "oscillator" }) ``` Aliases: ta.cmo ### alerta.ta.stochrsi https://www.alertachart.com/alertascript/reference/builtins/stochrsi Signature: stochrsi(source, length, rsiLength, k, d) Calculates the Stochastic RSI oscillator. TradingView-compatible spelling: ta.stochrsi; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: false; default: not specified. Stoch RSI length (default 14). - rsiLength: int; required: false; default: not specified. RSI length (default 14). - k: int; required: false; default: not specified. K smoothing (default 3). - d: int; required: false; default: not specified. D smoothing (default 3). Returns: [k, d] ``` [k, d] = stochrsi(close, 14, 14, 3, 3) plot(k, { title: "StochRSI K", color: color.blue, pane: "oscillator" }) plot(d, { title: "StochRSI D", color: color.orange, pane: "oscillator" }) ``` Aliases: ta.stochrsi ### alerta.ta.tsi https://www.alertachart.com/alertascript/reference/builtins/tsi Signature: ta.tsi(source, short_length, long_length) or tsi(source, longLength, shortLength) Calculates the True Strength Index. Pine form `ta.tsi(source, short_length, long_length)`: EMA(EMA(change, long), short) / EMA(EMA(|change|, long), short), a ratio in [-1, 1]. The legacy bare form `tsi(source, longLength, shortLength)` (also `alerta.tsi`) takes the long length first and returns the same index times 100. TradingView-compatible spelling: ta.tsi; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - longLength: int; required: false; default: not specified. ta.tsi: short_length, the second smoothing (default 13). Legacy tsi(): the long smoothing length (default 25). - shortLength: int; required: false; default: not specified. ta.tsi: long_length, the first smoothing (default 25). Legacy tsi(): the short smoothing length (default 13). Returns: series float ``` plot(ta.tsi(close, 13, 25), { pane: "oscillator" }) plot(tsi(close, 25, 13), { pane: "oscillator" }) ``` Aliases: ta.tsi ### alerta.ta.pvo https://www.alertachart.com/alertascript/reference/builtins/pvo Signature: pvo(source, fastLength, slowLength, signalLength) Calculates the Percentage Volume Oscillator (volume MACD). TradingView-compatible spelling: ta.pvo; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - fastLength: int; required: false; default: not specified. Fast EMA length (default 12). - slowLength: int; required: false; default: not specified. Slow EMA length (default 26). - signalLength: int; required: false; default: not specified. Signal EMA length (default 9). Returns: [pvoLine, signal, hist] ``` [pvoLine, signal, hist] = pvo(volume, 12, 26, 9) plot(pvoLine, { title: "PVO", color: color.blue, pane: "oscillator" }) plot(signal, { title: "Signal", color: color.orange, pane: "oscillator" }) plot(hist, { title: "Histogram", style: "histogram", pane: "oscillator" }) ``` Aliases: ta.pvo ### alerta.ta.rvi https://www.alertachart.com/alertascript/reference/builtins/rvi Signature: rvi(open, high, low, close, length) Calculates the Relative Vigor Index and signal line. TradingView-compatible spelling: ta.rvi; runs without warnings. - open: series; required: true; default: not specified. Open series. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - close: series; required: true; default: not specified. Close series. - length: int; required: false; default: not specified. Length (default 10). Returns: [rviLine, signal] ``` [rviLine, signal] = rvi(open, high, low, close, 10) plot(rviLine, { title: "RVI", color: color.blue, pane: "oscillator" }) plot(signal, { title: "Signal", color: color.orange, pane: "oscillator" }) ``` Aliases: ta.rvi ### alerta.ta.fisher https://www.alertachart.com/alertascript/reference/builtins/fisher Signature: fisher(source, length) Applies the Fisher Transform to a source series. TradingView-compatible spelling: ta.fisher; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: false; default: not specified. Length (default 10). Returns: series float ``` plot(fisher(close, 10), { pane: "oscillator" }) ``` Aliases: ta.fisher ### alerta.ta.cfo https://www.alertachart.com/alertascript/reference/builtins/cfo Signature: cfo(source, length) Calculates the Chande Forecast Oscillator. TradingView-compatible spelling: ta.cfo; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: false; default: not specified. Length (default 9). Returns: series float ``` plot(cfo(close, 9), { pane: "oscillator" }) ``` Aliases: ta.cfo ### alerta.ta.stc https://www.alertachart.com/alertascript/reference/builtins/stc Signature: stc(source, fastLength, slowLength, cycleLength) Calculates the Schaff Trend Cycle oscillator. TradingView-compatible spelling: ta.stc; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - fastLength: int; required: false; default: not specified. Fast EMA length (default 23). - slowLength: int; required: false; default: not specified. Slow EMA length (default 50). - cycleLength: int; required: false; default: not specified. Cycle length (default 10). Returns: series float ``` plot(stc(close, 23, 50, 10), { pane: "oscillator" }) ``` Aliases: ta.stc ### alerta.ta.adxr https://www.alertachart.com/alertascript/reference/builtins/adxr Signature: adxr(high, low, close, length) Calculates the ADXR by averaging current ADX with ADX from length bars ago. TradingView-compatible spelling: ta.adxr; runs without warnings. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - close: series; required: true; default: not specified. Close series. - length: int; required: false; default: not specified. Length (default 14). Returns: series float ``` plot(adxr(high, low, close, 14), { pane: "oscillator" }) ``` Aliases: ta.adxr ### alerta.ta.atrp https://www.alertachart.com/alertascript/reference/builtins/atrp Signature: atrp(high, low, close, length) Calculates ATR as a percentage of price. TradingView-compatible spelling: ta.atrp; runs without warnings. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - close: series; required: true; default: not specified. Close series. - length: int; required: false; default: not specified. Length (default 14). Returns: series float ``` plot(atrp(high, low, close, 14), { pane: "oscillator" }) ``` Aliases: ta.atrp ### alerta.ta.chaikin https://www.alertachart.com/alertascript/reference/builtins/chaikin Signature: chaikin(high, low, close, volume, fastLength, slowLength) Calculates the Chaikin Oscillator from ADL. TradingView-compatible spelling: ta.chaikin; runs without warnings. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - close: series; required: true; default: not specified. Close series. - volume: series; required: true; default: not specified. Volume series. - fastLength: int; required: false; default: not specified. Fast EMA length (default 3). - slowLength: int; required: false; default: not specified. Slow EMA length (default 10). Returns: series float ``` plot(chaikin(high, low, close, volume, 3, 10), { pane: "oscillator" }) ``` Aliases: ta.chaikin ### alerta.ta.cvi https://www.alertachart.com/alertascript/reference/builtins/cvi Signature: cvi(high, low, emaLength, rocLength) Measures volatility as percent change of EMA(high-low) over a lookback. TradingView-compatible spelling: ta.cvi; runs without warnings. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - emaLength: int; required: false; default: not specified. EMA smoothing length (default 10). - rocLength: int; required: false; default: not specified. Rate-of-change length (default 10). Returns: series float ``` plot(cvi(high, low, 10, 10), { pane: "oscillator" }) ``` Aliases: ta.cvi ### alerta.ta.adosc https://www.alertachart.com/alertascript/reference/builtins/adosc Signature: adosc(high, low, close, volume, fastLength, slowLength) Calculates the Accumulation/Distribution Oscillator (Chaikin). TradingView-compatible spelling: ta.adosc; runs without warnings. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - close: series; required: true; default: not specified. Close series. - volume: series; required: true; default: not specified. Volume series. - fastLength: int; required: false; default: not specified. Fast EMA length (default 3). - slowLength: int; required: false; default: not specified. Slow EMA length (default 10). Returns: series float ``` plot(adosc(high, low, close, volume, 3, 10), { pane: "oscillator" }) ``` Aliases: ta.adosc ### alerta.ta.vi https://www.alertachart.com/alertascript/reference/builtins/vi Signature: vi(high, low, close, length) Calculates Vortex Indicator positive/negative lines. TradingView-compatible spelling: ta.vi; runs without warnings. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - close: series; required: true; default: not specified. Close series. - length: int; required: false; default: not specified. Length (default 14). Returns: [vip, vin] ``` [vip, vin] = vi(high, low, close, 14) plot(vip, { title: "VI+", color: color.green, pane: "oscillator" }) plot(vin, { title: "VI-", color: color.red, pane: "oscillator" }) ``` Aliases: ta.vi, ta.vortex ### alerta.ta.trix https://www.alertachart.com/alertascript/reference/builtins/trix Signature: trix(source, length) Calculates the percent rate of change of a triple-smoothed EMA. TradingView-compatible spelling: ta.trix; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: false; default: not specified. Number of bars (length, default 18). Returns: series float ``` plot(trix(close, 18), { pane: "oscillator" }) ``` Aliases: ta.trix ### alerta.ta.willr https://www.alertachart.com/alertascript/reference/builtins/williamsr Signature: williamsr(high, low, close, length) Measures overbought/oversold levels using the high/low range. TradingView-compatible spelling: ta.willr; runs without warnings. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - close: series; required: true; default: not specified. Close series. - length: int; required: false; default: not specified. Number of bars (length, default 14). Returns: series float ``` plot(williamsr(high, low, close, 14), { pane: "oscillator" }) ``` Aliases: ta.willr, ta.williamsr ### alerta.ta.ultosc https://www.alertachart.com/alertascript/reference/builtins/ultosc Signature: ultosc(high, low, close, length1, length2, length3) Calculates the Ultimate Oscillator using three timeframes. TradingView-compatible spelling: ta.ultosc; runs without warnings. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - close: series; required: true; default: not specified. Close series. - length1: int; required: false; default: not specified. Short length (default 7). - length2: int; required: false; default: not specified. Medium length (default 14). - length3: int; required: false; default: not specified. Long length (default 28). Returns: series float ``` plot(ultosc(high, low, close, 7, 14, 28), { pane: "oscillator" }) ``` Aliases: ta.ultosc ### alerta.ta.natr https://www.alertachart.com/alertascript/reference/builtins/natr Signature: natr(high, low, close, length) Calculates ATR normalized by price (percent). TradingView-compatible spelling: ta.natr; runs without warnings. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - close: series; required: true; default: not specified. Close series. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(natr(high, low, close, 14), { pane: "oscillator" }) ``` Aliases: ta.natr ### alerta.ta.adx https://www.alertachart.com/alertascript/reference/builtins/adx Signature: adx(high, low, close, length) Measures trend strength using the Average Directional Index. TradingView-compatible spelling: ta.adx; runs without warnings. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - close: series; required: true; default: not specified. Close series. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(adx(high, low, close, 14)) ``` Aliases: ta.adx ### alerta.ta.dmi https://www.alertachart.com/alertascript/reference/builtins/dmi Signature: dmi(diLength, adxSmoothing) or dmi(high, low, close, length) Returns DI+ / DI- and ADX. Pine's form is ta.dmi(diLength, adxSmoothing), which smooths DI and ADX by DIFFERENT lengths and reads the chart's own high/low/close; the 4-argument form is kept for older scripts. TradingView-compatible spelling: ta.dmi; runs without warnings. - diLength: int; required: true; default: not specified. DI smoothing length. This is Pine's own form — ta.dmi(diLength, adxSmoothing) reads the chart's own H/L/C. - adxSmoothing: int; required: not specified; default: not specified. ADX smoothing length. Defaults to diLength. - close: series; required: not specified; default: not specified. Legacy 4-argument form only: close series. - length: int; required: not specified; default: not specified. Legacy 4-argument form only: length. Returns: { plus, minus, adx } ``` indicator("DMI", overlay=false) [diPlus, diMinus, adxValue] = ta.dmi(14, 14) plot(diPlus, { title: "+DI", pane: "oscillator" }) plot(diMinus, { title: "-DI", pane: "oscillator" }) plot(adxValue, { title: "ADX", pane: "oscillator" }) ``` Aliases: ta.dmi ### alerta.ta.aroon https://www.alertachart.com/alertascript/reference/builtins/aroon Signature: aroon(high, low, length) Returns Aroon Up and Aroon Down values. TradingView-compatible spelling: ta.aroon; runs without warnings. - high: series; required: true; default: not specified. High series. - low: series; required: true; default: not specified. Low series. - length: int; required: true; default: not specified. Number of bars (length). Returns: { up, down } ``` indicator("Aroon", overlay=false) [up, down] = ta.aroon(high, low, 14) plot(up, "Aroon up") plot(down, "Aroon down") ``` Aliases: ta.aroon ### alerta.ta.hma https://www.alertachart.com/alertascript/reference/builtins/hma Signature: hma(source, length) Calculates the Hull Moving Average. TradingView-compatible spelling: ta.hma; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(hma(close, 55)) ``` Aliases: ta.hma ### alerta.ta.alma https://www.alertachart.com/alertascript/reference/builtins/alma Signature: alma(source, length, offset, sigma, floor) Calculates the Arnaud Legoux Moving Average. TradingView-compatible spelling: ta.alma; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). - offset: float; required: false; default: not specified. Offset (default 0.85). - sigma: float; required: false; default: not specified. Sigma (default 6). - floor: bool; required: false; default: not specified. Pine v6: floor the offset position offset * (length - 1) before the weights are computed (default false). Returns: series float ``` plot(alma(close, 9, 0.85, 6)) ``` Aliases: ta.alma ### alerta.ta.dema https://www.alertachart.com/alertascript/reference/builtins/dema Signature: dema(source, length) Calculates the Double Exponential Moving Average. TradingView-compatible spelling: ta.dema; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(dema(close, 21)) ``` Aliases: ta.dema ### alerta.ta.tema https://www.alertachart.com/alertascript/reference/builtins/tema Signature: tema(source, length) Calculates the Triple Exponential Moving Average. TradingView-compatible spelling: ta.tema; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(tema(close, 21)) ``` Aliases: ta.tema ### alerta.ta.trima https://www.alertachart.com/alertascript/reference/builtins/trima Signature: trima(source, length) Calculates the Triangular Moving Average. TradingView-compatible spelling: ta.trima; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(trima(close, 10)) ``` Aliases: ta.trima ### alerta.ta.kama https://www.alertachart.com/alertascript/reference/builtins/kama Signature: kama(source, length, fast, slow) Calculates the Kaufman Adaptive Moving Average. TradingView-compatible spelling: ta.kama; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). - fast: int; required: false; default: not specified. Fast period (default 2). - slow: int; required: false; default: not specified. Slow period (default 30). Returns: series float ``` plot(kama(close, 10, 2, 30)) ``` Aliases: ta.kama ### alerta.ta.linreg https://www.alertachart.com/alertascript/reference/builtins/linreg Signature: linreg(source, length, offset) Calculates the Linear Regression value over an N-bar window. TradingView-compatible spelling: ta.linreg; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). - offset: int; required: false; default: not specified. Regression offset (default 0). Returns: series float ``` plot(linreg(close, 14, 0)) ``` Aliases: ta.linreg ### alerta.ta.t3 https://www.alertachart.com/alertascript/reference/builtins/t3 Signature: t3(source, length, vfactor) Calculates the Tillson T3 moving average. TradingView-compatible spelling: ta.t3; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). - vfactor: float; required: false; default: not specified. Volume factor (default 0.7). Returns: series float ``` plot(t3(close, 5, 0.7)) ``` Aliases: ta.t3 ### alerta.ta.zlema https://www.alertachart.com/alertascript/reference/builtins/zlema Signature: zlema(source, length) Calculates the Zero Lag Exponential Moving Average. TradingView-compatible spelling: ta.zlema; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(zlema(close, 10)) ``` Aliases: ta.zlema ### alerta.ta.smma https://www.alertachart.com/alertascript/reference/builtins/smma Signature: smma(source, length) Calculates the Smoothed Moving Average. TradingView-compatible spelling: ta.smma; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(smma(close, 10)) ``` Aliases: ta.smma ### alerta.ta.atr https://www.alertachart.com/alertascript/reference/builtins/atr Signature: atr(length) Calculates the Average True Range, a measure of market volatility. TradingView-compatible spelling: ta.atr; runs without warnings. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` plot(atr(14), { pane: "oscillator" }) ``` Aliases: ta.atr ### alerta.ta.bb https://www.alertachart.com/alertascript/reference/builtins/bbands Signature: bbands(source, length, mult) Bollinger Bands: a simple moving average of source (the middle band) and the bands mult standard deviations above and below it. Returns the tuple [middle, upper, lower], as Pine's ta.bb does; ta.bbands and bbands are the same function. TradingView-compatible spelling: ta.bb; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars. - mult: float; required: true; default: not specified. Standard deviation multiplier. Returns: [middle, upper, lower] ``` [basis, upper, lower] = ta.bb(close, 20, 2.0) plot(basis, "Basis") plot(upper, "Upper") plot(lower, "Lower") ``` Aliases: ta.bbands, ta.bb ### alerta.ta.stdev https://www.alertachart.com/alertascript/reference/builtins/stdev Signature: stdev(source, length, biased = true) Calculates standard deviation of source over length bars. Pine v6 third argument `biased` selects the biased (Bessel-corrected off) or unbiased estimator; defaults to true. TradingView-compatible spelling: ta.stdev; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). - biased: bool; required: false; default: not specified. Pine v6 estimator switch. When true (default) uses the biased / population formula (divides by N); when false uses the unbiased / sample formula (divides by N-1). Returns: series float ``` plot(stdev(close, 20), { pane: "oscillator" }) plot(stdev(close, 20, true), { pane: "oscillator" }) ``` Aliases: ta.stdev ### alerta.ta.highest https://www.alertachart.com/alertascript/reference/builtins/highest Signature: highest(source, length) Returns the highest value of source for length bars back. TradingView-compatible spelling: ta.highest; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` const hh = highest(high, 20) ``` Aliases: ta.highest ### alerta.ta.highestbars https://www.alertachart.com/alertascript/reference/builtins/highestbars Signature: highestbars(source, length) Returns the offset to the highest value of source over the last length bars, as Pine does: 0 on the current bar, negative before it (-3 = three bars ago). With a single argument — highestbars(length) — the source is high. TradingView-compatible spelling: ta.highestbars; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series int ``` const hh_off = highestbars(high, 20) ``` Returns offset, not absolute bar_index. For absolute index use highestindex(). Aliases: ta.highestbars ### alerta.ta.lowest https://www.alertachart.com/alertascript/reference/builtins/lowest Signature: lowest(source, length) Returns the lowest value of source for length bars back. TradingView-compatible spelling: ta.lowest; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series float ``` const ll = lowest(low, 20) ``` Aliases: ta.lowest ### alerta.ta.lowestbars https://www.alertachart.com/alertascript/reference/builtins/lowestbars Signature: lowestbars(source, length) Returns the offset to the lowest value of source over the last length bars, as Pine does: 0 on the current bar, negative before it (-3 = three bars ago). With a single argument — lowestbars(length) — the source is low. TradingView-compatible spelling: ta.lowestbars; runs without warnings. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series int ``` const ll_off = lowestbars(low, 20) ``` Returns offset, not absolute bar_index. For absolute index use lowestindex(). Aliases: ta.lowestbars ### alerta.highestindex https://www.alertachart.com/alertascript/reference/builtins/highestindex Signature: highestindex(source, length) Returns the absolute index of the highest value of source for length bars. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series int ``` const h_idx = highestindex(high, 20) ``` AlertaScript returns absolute bar_index, whereas Pine ta.highestbars returns offset. ### alerta.lowestindex https://www.alertachart.com/alertascript/reference/builtins/lowestindex Signature: lowestindex(source, length) Returns the absolute index of the lowest value of source for length bars. - source: series; required: true; default: not specified. Series of values to process. - length: int; required: true; default: not specified. Number of bars (length). Returns: series int ``` const l_idx = lowestindex(low, 20) ``` AlertaScript returns absolute bar_index, whereas Pine ta.lowestbars returns offset. ### alerta.ta.crossover https://www.alertachart.com/alertascript/reference/builtins/crossover Signature: crossover(a, b) Returns true if `a` crossed above `b`. TradingView-compatible spelling: ta.crossover; runs without warnings. - a: series; required: true; default: not specified. First series. - b: series; required: true; default: not specified. Second series. Returns: series bool ``` const buy = crossover(sma(close, 10), sma(close, 20)) ``` Aliases: ta.crossover ### alerta.ta.crossunder https://www.alertachart.com/alertascript/reference/builtins/crossunder Signature: crossunder(a, b) Returns true if `a` crossed below `b`. TradingView-compatible spelling: ta.crossunder; runs without warnings. - a: series; required: true; default: not specified. First series. - b: series; required: true; default: not specified. Second series. Returns: series bool ``` const sell = crossunder(sma(close, 10), sma(close, 20)) ``` Aliases: ta.crossunder ### alerta.ta.cross https://www.alertachart.com/alertascript/reference/builtins/ta.cross Signature: ta.cross(a, b) Returns true when `a` crosses `b` in either direction. TradingView-compatible spelling: ta.cross; runs without warnings. - a: series; required: true; default: not specified. First series. - b: series; required: true; default: not specified. Second series. Returns: series bool ``` lineA = sma(close, 10) lineB = sma(close, 20) crossed = ta.cross(lineA, lineB) plot(crossed ? 1 : 0, { title: "Cross Any", pane: "oscillator" }) ``` Aliases: ta.cross ### alerta.ta.rising https://www.alertachart.com/alertascript/reference/builtins/ta.rising Signature: ta.rising(source, length) Returns true when source is greater than all previous values in the lookback window. TradingView-compatible spelling: ta.rising; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback window. Returns: series bool ``` isRising = ta.rising(close, 5) plot(isRising ? 1 : 0, { title: "Rising", pane: "oscillator" }) ``` Aliases: ta.rising ### alerta.ta.falling https://www.alertachart.com/alertascript/reference/builtins/ta.falling Signature: ta.falling(source, length) Returns true when source is lower than all previous values in the lookback window. TradingView-compatible spelling: ta.falling; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback window. Returns: series bool ``` isFalling = ta.falling(close, 5) plot(isFalling ? 1 : 0, { title: "Falling", pane: "oscillator" }) ``` Aliases: ta.falling ### alerta.ta.range https://www.alertachart.com/alertascript/reference/builtins/ta.range Signature: ta.range(source, length) Returns max(source, length) - min(source, length). TradingView-compatible spelling: ta.range; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback window. Returns: series float ``` r = ta.range(close, 20) plot(r, { title: "Range" }) ``` Aliases: ta.range ### alerta.ta.swma https://www.alertachart.com/alertascript/reference/builtins/ta.swma Signature: ta.swma(source) 4-period symmetric weighted moving average with weights [1, 2, 2, 1] / 6. TradingView-compatible spelling: ta.swma; runs without warnings. - source: series; required: true; default: not specified. Source series. Returns: series float ``` sw = ta.swma(close) plot(sw, { title: "SWMA", color: "#60A5FA" }) ``` Aliases: ta.swma ### alerta.ta.dev https://www.alertachart.com/alertascript/reference/builtins/ta.dev Signature: ta.dev(source, length) Returns average absolute deviation from the moving mean over length bars. TradingView-compatible spelling: ta.dev; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback window. Returns: series float ``` mad = ta.dev(close, 20) plot(mad, { title: "MAD", pane: "oscillator" }) ``` Aliases: ta.dev ### alerta.ta.variance https://www.alertachart.com/alertascript/reference/builtins/ta.variance Signature: ta.variance(source, length, biased) Returns rolling variance. `biased=true` computes population variance, `false` uses sample variance. TradingView-compatible spelling: ta.variance; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback window. - biased: bool; required: false; default: true. Population variance when true; sample variance when false. Returns: series float ``` vPop = ta.variance(close, 20, true) vSample = ta.variance(close, 20, false) plot(vPop, { title: "Variance Pop", pane: "oscillator" }) plot(vSample, { title: "Variance Sample", pane: "oscillator" }) ``` Aliases: ta.variance ### alerta.ta.percentrank https://www.alertachart.com/alertascript/reference/builtins/ta.percentrank Signature: ta.percentrank(source, length) Returns the percentile rank (0..100) of the current value inside the rolling window. TradingView-compatible spelling: ta.percentrank; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback window. Returns: series float ``` pr = ta.percentrank(close, 50) plot(pr, { title: "PercentRank", pane: "oscillator" }) ``` Aliases: ta.percentrank ### alerta.ta.percentile_nearest_rank https://www.alertachart.com/alertascript/reference/builtins/ta.percentile_nearest_rank Signature: ta.percentile_nearest_rank(source, length, percentage) Returns rolling percentile using nearest-rank method. TradingView-compatible spelling: ta.percentile_nearest_rank; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback window. - percentage: float; required: true; default: not specified. Percentile level between 0 and 100. Returns: series float ``` p75 = ta.percentile_nearest_rank(close, 20, 75) plot(p75, { title: "P75 NR", pane: "oscillator" }) ``` Aliases: ta.percentile_nearest_rank ### alerta.ta.percentile_linear_interpolation https://www.alertachart.com/alertascript/reference/builtins/ta.percentile_linear_interpolation Signature: ta.percentile_linear_interpolation(source, length, percentage) Returns rolling percentile using linear interpolation between nearest ranks. TradingView-compatible spelling: ta.percentile_linear_interpolation; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback window. - percentage: float; required: true; default: not specified. Percentile level between 0 and 100. Returns: series float ``` p75 = ta.percentile_linear_interpolation(close, 20, 75) plot(p75, { title: "P75 LI", pane: "oscillator" }) ``` Aliases: ta.percentile_linear_interpolation ### alerta.ta.kc https://www.alertachart.com/alertascript/reference/builtins/ta.kc Signature: ta.kc(source, length, mult, useTrueRange) Returns Keltner Channel basis, upper and lower bands. TradingView-compatible spelling: ta.kc; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback length. - mult: float; required: false; default: 1.5. Band multiplier. - useTrueRange: bool; required: false; default: true. Uses true range when true, high-low range when false. Returns: [basis, upper, lower] ``` [basis, upper, lower] = ta.kc(close, 20, 1.5, true) plot(basis, { title: "KC Basis" }) plot(upper, { title: "KC Upper" }) plot(lower, { title: "KC Lower" }) ``` Aliases: ta.kc ### alerta.ta.kcw https://www.alertachart.com/alertascript/reference/builtins/ta.kcw Signature: ta.kcw(source, length, mult, useTrueRange) Returns channel width as `(upper - lower) / basis`. TradingView-compatible spelling: ta.kcw; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback length. - mult: float; required: false; default: 1.5. Band multiplier. - useTrueRange: bool; required: false; default: true. Uses true range when true. Returns: series float ``` w = ta.kcw(close, 20, 1.5, true) plot(w, { title: "KC Width", pane: "oscillator" }) ``` Aliases: ta.kcw ### alerta.ta.bbw https://www.alertachart.com/alertascript/reference/builtins/ta.bbw Signature: ta.bbw(source, length, mult) Returns Bollinger width as `(upper - lower) / basis`. TradingView-compatible spelling: ta.bbw; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback length. - mult: float; required: false; default: 2.0. Band multiplier. Returns: series float ``` w = ta.bbw(close, 20, 2.0) plot(w, { title: "BBW", pane: "oscillator" }) ``` Aliases: ta.bbw ### alerta.ta.cog https://www.alertachart.com/alertascript/reference/builtins/ta.cog Signature: ta.cog(source, length) Computes Center of Gravity oscillator over the lookback window. TradingView-compatible spelling: ta.cog; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback length. Returns: series float ``` c = ta.cog(close, 10) plot(c, { title: "COG", pane: "oscillator" }) ``` Aliases: ta.cog ### alerta.ta.correlation https://www.alertachart.com/alertascript/reference/builtins/ta.correlation Signature: ta.correlation(sourceA, sourceB, length) Rolling Pearson correlation between two series. TradingView-compatible spelling: ta.correlation; runs without warnings. - sourceA: series; required: true; default: not specified. First source series. - sourceB: series; required: true; default: not specified. Second source series. - length: int; required: true; default: not specified. Lookback length. Returns: series float ``` corr = ta.correlation(close, volume, 20) plot(corr, { title: "Correlation", pane: "oscillator" }) ``` Aliases: ta.correlation ### alerta.ta.max https://www.alertachart.com/alertascript/reference/builtins/ta.max Signature: ta.max → series float Pine v6 built-in VARIABLE (no parentheses): the running all-time high — the maximum of `high` from the first bar up to the current bar. TradingView-compatible spelling: ta.max; runs without warnings. Returns: series float ``` //@version=6 indicator("ATH", overlay=true) plot(ta.max, title="All-time high", color=color.green) ``` Aliases: ta.max, alerta.ta.max Alternate form: ta.max(source) Returns running all-time maximum of source. Returns: series float - source: series. Source series. ``` mx = ta.max(close) plot(mx, { title: "All-time Max" }) ``` ### alerta.ta.min https://www.alertachart.com/alertascript/reference/builtins/ta.min Signature: ta.min → series float Pine v6 built-in VARIABLE (no parentheses): the running all-time low — the minimum of `low` from the first bar up to the current bar. TradingView-compatible spelling: ta.min; runs without warnings. Returns: series float ``` //@version=6 indicator("ATL", overlay=true) plot(ta.min, title="All-time low", color=color.red) ``` Aliases: ta.min, alerta.ta.min Alternate form: ta.min(source) Returns running all-time minimum of source. Returns: series float - source: series. Source series. ``` mn = ta.min(close) plot(mn, { title: "All-time Min" }) ``` ### alerta.ta.median https://www.alertachart.com/alertascript/reference/builtins/ta.median Signature: ta.median(source, length) Returns rolling median of source values over length bars. TradingView-compatible spelling: ta.median; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback length. Returns: series float ``` m = ta.median(close, 21) plot(m, { title: "Median" }) ``` Aliases: ta.median ### alerta.ta.mode https://www.alertachart.com/alertascript/reference/builtins/ta.mode Signature: ta.mode(source, length) Returns most frequent value in the rolling window. TradingView-compatible spelling: ta.mode; runs without warnings. - source: series; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Lookback length. Returns: series float ``` m = ta.mode(close, 21) plot(m, { title: "Mode" }) ``` Aliases: ta.mode ### alerta.alert https://www.alertachart.com/alertascript/reference/builtins/alert Signature: alert(message, freq) Triggers an alert event when executed. freq controls dispatch cadence: once_per_bar (default), once_per_bar_close (held until the bar closes), all (every tick). Message supports {{placeholders}}: ticker, exchange, interval, time, OHLCV, plot_N, plot("Title"), syminfo.*, strategy.order.id/action/contracts/price/comment/alert_message, strategy.market_position(_size), strategy.prev_market_position(_size). TradingView-compatible spelling: alert; runs without warnings. - message: string; required: true; default: not specified. Alert message text — {{placeholder}} tokens are substituted at fire time. - freq: string; required: false; default: alert.freq_once_per_bar. alert.freq_once_per_bar | alert.freq_once_per_bar_close | alert.freq_all. Returns: void ``` if crossover(close, sma(close, 20)) alert("Bullish crossover", alert.freq_once_per_bar_close) ``` ### alerta.alertcondition https://www.alertachart.com/alertascript/reference/builtins/alertcondition Signature: alertcondition(condition, title, message) Registers a named, selectable alert condition (listed by title in the alert UI) and fires it when the condition is true on the current bar. Message supports the same {{placeholder}} set as alert(). TradingView-compatible spelling: alertcondition; runs without warnings. - condition: series bool; required: true; default: not specified. Condition that enables alert. - title: string; required: false; default: not specified. Display title for alert. - message: string; required: false; default: not specified. Alert message text. Returns: void ``` indicator("Bearish price crossover", overlay=true) ma = ta.sma(close, 20) signal = ta.crossunder(close, ma) plot(ma, "SMA 20") plotshape(signal, title="Price crossed below SMA", style=shape.triangledown, location=location.abovebar) alertcondition(signal, "Bearish", "Price crossed below SMA 20") ``` ### alerta.input.source https://www.alertachart.com/alertascript/reference/builtins/input.source Signature: input.source(defval, title) Creates a source selector input: the series chosen in the script's settings is the series the script reads. TradingView-compatible spelling: input.source; runs without warnings. - defval: series; required: true; default: not specified. Default source (e.g. close). - title: string; required: false; default: not specified. Input title. Returns: series float ``` src = input.source(close, "Source") plot(ema(src, 20)) ``` ### alerta.input.timeframe https://www.alertachart.com/alertascript/reference/builtins/input.timeframe Signature: input.timeframe(defval, title) Creates a timeframe input suitable for request.security. TradingView-compatible spelling: input.timeframe; runs without warnings. - defval: string; required: true; default: not specified. Default timeframe (e.g. "60", "D"). - title: string; required: false; default: not specified. Input title. Returns: string ``` tf = input.timeframe("60", "HTF") plot(close, { title: "Selected TF Input" }) ``` ### alerta.input.symbol https://www.alertachart.com/alertascript/reference/builtins/input.symbol Signature: input.symbol(defval, title) Creates a symbol input suitable for request.security. TradingView-compatible spelling: input.symbol; runs without warnings. - defval: string; required: true; default: not specified. Default symbol (e.g. BINANCE:BTCUSDT). - title: string; required: false; default: not specified. Input title. Returns: string ``` sym = input.symbol("SELF", "Symbol") plot(close, { title: "Selected Symbol Input" }) ``` ### alerta.input.time https://www.alertachart.com/alertascript/reference/builtins/input.time Signature: input.time(defval, title) Creates a timestamp input (epoch milliseconds). TradingView-compatible spelling: input.time; runs without warnings. - defval: int; required: true; default: not specified. Default timestamp. - title: string; required: false; default: not specified. Input title. Returns: int ``` t0 = input.time(1704067200000, "Start") cond = time >= t0 ``` ### alerta.input.session https://www.alertachart.com/alertascript/reference/builtins/input.session Signature: input.session(defval, title) Creates a session string input (HHMM-HHMM[:days]). TradingView-compatible spelling: input.session; runs without warnings. - defval: string; required: true; default: not specified. Default session string. - title: string; required: false; default: not specified. Input title. Returns: string ``` sess = input.session("0900-1700", "Session") ``` ### alerta.input.int https://www.alertachart.com/alertascript/reference/builtins/input.int Signature: input.int(defval, title, options) Creates an integer input in the script's settings. Pine's named arguments are accepted: minval, maxval and step set the range the settings allow, options (a list of allowed values) offers only those values, and tooltip, inline and group arrange the input in the settings. The older `{ min, max, step }` object as the third argument is accepted too. TradingView-compatible spelling: input.int; runs without warnings. - defval: int; required: true; default: not specified. Default integer value. - title: string; required: false; default: not specified. Input title. - options: object; required: false; default: not specified. Optional constraints { min, max, step }. Returns: int ``` len = input.int(14, "Length", minval = 1, maxval = 200) plot(len, { pane: "oscillator" }) ``` ### alerta.input.float https://www.alertachart.com/alertascript/reference/builtins/input.float Signature: input.float(defval, title, options) Creates a decimal-number input in the script's settings. Pine's named arguments are accepted: minval, maxval and step set the range the settings allow, options (a list of allowed values) offers only those values, and tooltip, inline and group arrange the input in the settings. The older `{ min, max, step }` object as the third argument is accepted too. TradingView-compatible spelling: input.float; runs without warnings. - defval: float; required: true; default: not specified. Default float value. - title: string; required: false; default: not specified. Input title. - options: object; required: false; default: not specified. Optional constraints { min, max, step }. Returns: float ``` mult = input.float(2.5, "Multiplier", minval = 0.1, step = 0.1) plot(mult, { pane: "oscillator" }) ``` ### alerta.input.bool https://www.alertachart.com/alertascript/reference/builtins/input.bool Signature: input.bool(defval, title) Creates a boolean (checkbox) input parameter. TradingView-compatible spelling: input.bool; runs without warnings. - defval: bool; required: true; default: not specified. Default boolean value. - title: string; required: false; default: not specified. Input title. Returns: bool ``` show = input.bool(true, "Show Line") plot(show ? close : na) ``` ### alerta.input.string https://www.alertachart.com/alertascript/reference/builtins/input.string Signature: input.string(defval, title) Creates a string input parameter. TradingView-compatible spelling: input.string; runs without warnings. - defval: string; required: true; default: not specified. Default string value. - title: string; required: false; default: not specified. Input title. Returns: string ``` tag = input.string("BTC", "Tag") if barstate.islast label.new(bar_index, high, tag) ``` ### alerta.input.color https://www.alertachart.com/alertascript/reference/builtins/input.color Signature: input.color(defval, title) Creates a color picker input parameter. TradingView-compatible spelling: input.color; runs without warnings. - defval: color; required: true; default: not specified. Default color. - title: string; required: false; default: not specified. Input title. Returns: color ``` lineColor = input.color(color.green, "Line Color") plot(close, { color: lineColor }) ``` ### alerta.input.price https://www.alertachart.com/alertascript/reference/builtins/input.price Signature: input.price(defval, title, options) Creates a price-like numeric input parameter. TradingView-compatible spelling: input.price; runs without warnings. - defval: float; required: true; default: not specified. Default price value. - title: string; required: false; default: not specified. Input title. - options: object; required: false; default: not specified. Optional constraints { min, max, step }. Returns: float ``` lvl = input.price(100.0, "Level") plot(lvl) ``` ### alerta.input.text_area https://www.alertachart.com/alertascript/reference/builtins/input.text_area Signature: input.text_area(defval, title) Creates a multiline text input parameter. TradingView-compatible spelling: input.text_area; runs without warnings. - defval: string; required: true; default: not specified. Default multiline text. - title: string; required: false; default: not specified. Input title. Returns: string ``` notes = input.text_area("line1\nline2", "Notes") if barstate.islast label.new(bar_index, high, notes) ``` ### alerta.input.enum https://www.alertachart.com/alertascript/reference/builtins/input.enum Signature: input.enum(defval, title, options?) Creates a dropdown input from a user-declared enum. Returns the selected enum MEMBER (not its title string), so it compares directly against EnumName.member. Member titles are what the user sees in the settings dialog. TradingView-compatible spelling: input.enum; runs without warnings. - defval: enum member; required: true; default: not specified. Default selected enum member (e.g. Side.Long). - title: string; required: false; default: not specified. Input title. - options: array; required: false; default: not specified. Restrict the dropdown to a subset of members. Omitted = every member of the enum. Returns: enum member ``` enum Side Long = "Buy side" Short = "Sell side" side = input.enum(Side.Long, "Direction") plot(side == Side.Long ? 1 : -1, { pane: "oscillator" }) ``` ### alerta.time https://www.alertachart.com/alertascript/reference/builtins/time Signature: time() or time(timeframe, session?, timezone?, bars_back?, timeframe_bars_back?) Returns bar open timestamps (epoch milliseconds). Also usable as a bare built-in variable (no parens). The Pine v6 overload `time(timeframe, session?, timezone?, bars_back?, timeframe_bars_back?)` is accepted; when a session is supplied the value is the bar time inside the session window (in the given timezone) and `na` outside. TradingView-compatible spelling: time; runs without warnings. - timeframe: simple string; required: false; default: not specified. Optional resolution to evaluate the time at (Pine v6 overload). - session: simple string; required: false; default: not specified. Session spec, e.g. "0930-1100" or "2200-0200:23456". When present, the function returns na outside the session window. - timezone: simple string; required: false; default: not specified. IANA name ("America/New_York"), "UTC", or "GMT±N". Defaults to UTC. - bars_back: series int; required: false; default: not specified. Read the chart bar N back (a negative N reads the bar N ahead; past the last loaded bar the chart's timeframe steps on). Applied before the session mask; used to detect session edges. - timeframe_bars_back: series int; required: false; default: not specified. Read the `timeframe` bar N back from the one holding the chart bar (negative: ahead). Not combined with a session. Returns: series int ``` plot(time, { pane: "oscillator" }) plot(time(timeframe.period), { pane: "oscillator" }) plot(time("D", timeframe_bars_back = 1), { title: "previous day open", pane: "oscillator" }) ``` ### alerta.time_close https://www.alertachart.com/alertascript/reference/builtins/time_close Signature: time_close() or time_close(timeframe, session?, timezone?, bars_back?, timeframe_bars_back?) Returns the bar's close time (epoch milliseconds): open + timeframe, calendar months for monthly bars, and the session close for a stock's daily bar. Also usable as a bare built-in variable. Takes the same optional arguments as `time`: with a timeframe, `time_close("D")` is the close of the higher-timeframe bar the current bar belongs to; with a session, the value is the close time inside the session window and `na` outside. TradingView-compatible spelling: time_close; runs without warnings. - timeframe: simple string; required: false; default: not specified. Optional resolution to evaluate the close time at. - session: simple string; required: false; default: not specified. Session spec, e.g. "0930-1600". When present, returns na outside the session window. - timezone: simple string; required: false; default: not specified. IANA name, "UTC", or "GMT±N". Defaults to UTC. - bars_back: series int; required: false; default: not specified. The close of the chart bar N back (a negative N reads the bar N ahead; past the last loaded bar the chart's timeframe steps on). - timeframe_bars_back: series int; required: false; default: not specified. The close of the `timeframe` bar N back from the one holding the chart bar (negative: ahead). Not combined with a session. Returns: series int ``` plot(time_close(), { pane: "oscillator" }) plot(nz(time_close("D"), time), { title: "session close", pane: "oscillator" }) ``` ### alerta.timestamp https://www.alertachart.com/alertascript/reference/builtins/timestamp Signature: timestamp(year, month, day, hour, minute, second) | timestamp(timezone, year, month, day, …) | timestamp(dateString) Builds a timestamp (milliseconds since the Unix epoch). Three forms: from date/time components, read on the chart symbol's exchange clock (`syminfo.timezone` — UTC on crypto charts, New York time on a US stock); with an IANA timezone as the first argument, which reads those components in that zone instead; or from a single DATE STRING — `timestamp("2024-01-01")`, `timestamp("2024-01-01 09:30")`, `timestamp("2026-08-01T11:00:00-0500")`. A date string without its own offset is read as UTC. TradingView-compatible spelling: timestamp; runs without warnings. - year: int or string; required: true; default: not specified. Year — or, in the other two forms, an IANA timezone followed by the date components, or a whole date string on its own. - month: int; required: false; default: not specified. Month 1..12. Omitted in the date-string form. - day: int; required: false; default: not specified. Day of month. Omitted in the date-string form. - hour: int; required: false; default: not specified. Hour. - minute: int; required: false; default: not specified. Minute. - second: int; required: false; default: not specified. Second. Returns: int ``` t = timestamp(2026, 4, 10, 12, 0, 0) fromText = timestamp("2026-04-10 12:00") plot(t == fromText ? 1 : 0, { title: "same instant", pane: "oscillator" }) ``` ### alerta.hour https://www.alertachart.com/alertascript/reference/builtins/hour Signature: hour(source?, timezone?) Returns hour component from timestamp series. With a timezone arg, the hour is computed in that timezone (Pine v6). Without one, the chart symbol's exchange clock applies (`syminfo.timezone`): UTC on crypto charts, New York time on a US stock — daylight saving included. TradingView-compatible spelling: hour; runs without warnings. - source: series int; required: false; default: not specified. Timestamp source. Defaults to time. - timezone: simple string; required: false; default: not specified. IANA timezone, "UTC", or "GMT±N". Returns: series int ``` plot(hour(), { pane: "oscillator" }) ``` ### alerta.minute https://www.alertachart.com/alertascript/reference/builtins/minute Signature: minute(source?, timezone?) Returns minute component from timestamp series. With a timezone arg, the minute is computed in that timezone (Pine v6). Without one, the chart symbol's exchange clock applies (`syminfo.timezone`): UTC on crypto charts, New York time on a US stock — daylight saving included. TradingView-compatible spelling: minute; runs without warnings. - source: series int; required: false; default: not specified. Timestamp source. Defaults to time. - timezone: simple string; required: false; default: not specified. IANA timezone, "UTC", or "GMT±N". Returns: series int ``` plot(minute(), { pane: "oscillator" }) ``` ### alerta.second https://www.alertachart.com/alertascript/reference/builtins/second Signature: second(source?, timezone?) Returns second component from timestamp series. With a timezone arg, the second is computed in that timezone (Pine v6). Without one, the chart symbol's exchange clock applies (`syminfo.timezone`): UTC on crypto charts, New York time on a US stock — daylight saving included. TradingView-compatible spelling: second; runs without warnings. - source: series int; required: false; default: not specified. Timestamp source. Defaults to time. - timezone: simple string; required: false; default: not specified. IANA timezone, "UTC", or "GMT±N". Returns: series int ``` plot(second(), { pane: "oscillator" }) ``` ### alerta.dayofmonth https://www.alertachart.com/alertascript/reference/builtins/dayofmonth Signature: dayofmonth(source?, timezone?) Returns day-of-month from timestamp series. With a timezone arg, computed in that timezone (Pine v6). Without one, the chart symbol's exchange clock applies (`syminfo.timezone`): UTC on crypto charts, New York time on a US stock — daylight saving included. TradingView-compatible spelling: dayofmonth; runs without warnings. - source: series int; required: false; default: not specified. Timestamp source. Defaults to time. - timezone: simple string; required: false; default: not specified. IANA timezone, "UTC", or "GMT±N". Returns: series int ``` plot(dayofmonth(), { pane: "oscillator" }) ``` ### alerta.dayofweek https://www.alertachart.com/alertascript/reference/builtins/dayofweek Signature: dayofweek(source?, timezone?) Returns the day of week from a timestamp (1=Sunday..7=Saturday). With a timezone arg, the day-of-week is computed in that timezone (Pine v6). Without one, the chart symbol's exchange clock applies (`syminfo.timezone`): UTC on crypto charts, New York time on a US stock — daylight saving included. TradingView-compatible spelling: dayofweek; runs without warnings. - source: series int; required: false; default: not specified. Timestamp source. Defaults to time. - timezone: simple string; required: false; default: not specified. IANA timezone, "UTC", or "GMT±N". Defaults to chart exchange / UTC. Returns: series int ``` plot(dayofweek(), { pane: "oscillator" }) ``` ### alerta.weekofyear https://www.alertachart.com/alertascript/reference/builtins/weekofyear Signature: weekofyear(source?, timezone?) Returns the ISO week number (weeks start on Monday) of a timestamp. With a timezone arg, the date is read in that timezone (Pine v6). Without one, the chart symbol's exchange clock applies (`syminfo.timezone`): UTC on crypto charts, New York time on a US stock — daylight saving included. TradingView-compatible spelling: weekofyear; runs without warnings. - source: series int; required: false; default: not specified. Timestamp source. Defaults to time. - timezone: simple string; required: false; default: not specified. IANA timezone, "UTC", or "GMT±N". Defaults to chart exchange / UTC. Returns: series int ``` plot(weekofyear(), { pane: "oscillator" }) ``` ### alerta.month https://www.alertachart.com/alertascript/reference/builtins/month Signature: month(source?, timezone?) Returns month (1..12) from timestamp series. With a timezone arg, computed in that timezone (Pine v6). Without one, the chart symbol's exchange clock applies (`syminfo.timezone`): UTC on crypto charts, New York time on a US stock — daylight saving included. TradingView-compatible spelling: month; runs without warnings. - source: series int; required: false; default: not specified. Timestamp source. Defaults to time. - timezone: simple string; required: false; default: not specified. IANA timezone, "UTC", or "GMT±N". Returns: series int ``` plot(month(), { pane: "oscillator" }) ``` ### alerta.year https://www.alertachart.com/alertascript/reference/builtins/year Signature: year(source?, timezone?) Returns year from timestamp series. With a timezone arg, computed in that timezone (Pine v6). Without one, the chart symbol's exchange clock applies (`syminfo.timezone`): UTC on crypto charts, New York time on a US stock — daylight saving included. TradingView-compatible spelling: year; runs without warnings. - source: series int; required: false; default: not specified. Timestamp source. Defaults to time. - timezone: simple string; required: false; default: not specified. IANA timezone, "UTC", or "GMT±N". Returns: series int ``` plot(year(), { pane: "oscillator" }) ``` ### alerta.timeframe.in_seconds https://www.alertachart.com/alertascript/reference/builtins/timeframe.in_seconds Signature: timeframe.in_seconds(timeframe) Returns timeframe duration in seconds. TradingView-compatible spelling: timeframe.in_seconds; runs without warnings. - timeframe: string; required: false; default: not specified. Timeframe string. Defaults to chart timeframe. Returns: int ``` secs = timeframe.in_seconds("60") plot(secs, { pane: "oscillator" }) ``` ### alerta.timeframe.from_seconds https://www.alertachart.com/alertascript/reference/builtins/timeframe.from_seconds Signature: timeframe.from_seconds(seconds) Converts seconds value to canonical timeframe string. TradingView-compatible spelling: timeframe.from_seconds; runs without warnings. - seconds: int; required: true; default: not specified. Duration in seconds. Returns: string ``` tf = timeframe.from_seconds(3600) if barstate.islast label.new(bar_index, high, tf) ``` ### alerta.barstate.isfirst https://www.alertachart.com/alertascript/reference/builtins/barstate.isfirst Signature: barstate.isfirst True only on first bar of current dataset. TradingView-compatible spelling: barstate.isfirst; runs without warnings. Returns: series bool ``` plotshape(barstate.isfirst, { style: "circle" }) ``` ### alerta.barstate.islast https://www.alertachart.com/alertascript/reference/builtins/barstate.islast Signature: barstate.islast True only on last bar of current dataset. TradingView-compatible spelling: barstate.islast; runs without warnings. Returns: series bool ``` plotshape(barstate.islast, { style: "circle" }) ``` ### alerta.barstate.ishistory https://www.alertachart.com/alertascript/reference/builtins/barstate.ishistory Signature: barstate.ishistory True for historical bars in current execution model. TradingView-compatible spelling: barstate.ishistory; runs without warnings. Returns: series bool ``` plotshape(barstate.ishistory, { style: "circle" }) ``` ### alerta.barstate.isrealtime https://www.alertachart.com/alertascript/reference/builtins/barstate.isrealtime Signature: barstate.isrealtime True on the latest bar during live delta execution (`update_last` and `append_last`). TradingView-compatible spelling: barstate.isrealtime; runs without warnings. Returns: series bool ``` plotshape(barstate.isrealtime, { style: "circle" }) ``` Only realtime updates can produce the marker; historical bars are false. ### alerta.barstate.isnew https://www.alertachart.com/alertascript/reference/builtins/barstate.isnew Signature: barstate.isnew True only when a new candle is appended (`append_last`) on the latest bar. TradingView-compatible spelling: barstate.isnew; runs without warnings. Returns: series bool ``` plotshape(barstate.isnew, { style: "triangleup", color: "#22C55E" }) ``` ### alerta.barstate.isconfirmed https://www.alertachart.com/alertascript/reference/builtins/barstate.isconfirmed Signature: barstate.isconfirmed True when bar is confirmed/closed in current execution model. TradingView-compatible spelling: barstate.isconfirmed; runs without warnings. Returns: series bool ``` plotshape(barstate.isconfirmed, { style: "circle" }) ``` ### alerta.syminfo.tickerid https://www.alertachart.com/alertascript/reference/builtins/syminfo.tickerid Signature: syminfo.tickerid Exchange-qualified symbol id (e.g. BINANCE:BTCUSDT). Inside request.security it is the requested symbol's; syminfo.main_tickerid stays the chart's. Pine v1–v3 scripts write it as `tickerid`. TradingView-compatible spelling: syminfo.tickerid; runs without warnings. Returns: string ``` id = syminfo.tickerid ``` ### alerta.syminfo.ticker https://www.alertachart.com/alertascript/reference/builtins/syminfo.ticker Signature: syminfo.ticker Ticker part of current symbol (e.g. BTCUSDT). Pine v1–v3 scripts write it as `ticker`. TradingView-compatible spelling: syminfo.ticker; runs without warnings. Returns: string ``` tk = syminfo.ticker ``` ### alerta.syminfo.prefix https://www.alertachart.com/alertascript/reference/builtins/syminfo.prefix Signature: syminfo.prefix Exchange prefix of current symbol (e.g. BINANCE). TradingView-compatible spelling: syminfo.prefix; runs without warnings. Returns: string ``` ex = syminfo.prefix ``` ### alerta.syminfo.mintick https://www.alertachart.com/alertascript/reference/builtins/syminfo.mintick Signature: syminfo.mintick Minimum price increment for the current symbol — the precision the chart's own price axis uses (a magnitude estimate from the last price when the script runs outside the chart). format.mintick and math.round_to_mintick use it. TradingView-compatible spelling: syminfo.mintick; runs without warnings. Returns: float ``` mt = syminfo.mintick ``` ### alerta.timeframe.period https://www.alertachart.com/alertascript/reference/builtins/timeframe.period Signature: timeframe.period Canonical chart timeframe identifier (e.g. 60, D, W, M). Inside request.security it is the requested timeframe; timeframe.main_period stays the chart's. Pine v1–v3 scripts write it as `period`. TradingView-compatible spelling: timeframe.period; runs without warnings. Returns: string ``` p = timeframe.period ``` ### alerta.timeframe.isintraday https://www.alertachart.com/alertascript/reference/builtins/timeframe.isintraday Signature: timeframe.isintraday True when timeframe is minute/hour based. Pine v1–v3 scripts write it (and isdaily, isweekly, ismonthly, isdwm) without the timeframe. prefix. TradingView-compatible spelling: timeframe.isintraday; runs without warnings. Returns: bool ``` x = timeframe.isintraday ``` ### alerta.timeframe.isdaily https://www.alertachart.com/alertascript/reference/builtins/timeframe.isdaily Signature: timeframe.isdaily True when timeframe period is D. TradingView-compatible spelling: timeframe.isdaily; runs without warnings. Returns: bool ``` x = timeframe.isdaily ``` ### alerta.timeframe.isweekly https://www.alertachart.com/alertascript/reference/builtins/timeframe.isweekly Signature: timeframe.isweekly True when timeframe period is W. TradingView-compatible spelling: timeframe.isweekly; runs without warnings. Returns: bool ``` x = timeframe.isweekly ``` ### alerta.timeframe.ismonthly https://www.alertachart.com/alertascript/reference/builtins/timeframe.ismonthly Signature: timeframe.ismonthly True when timeframe period is M. TradingView-compatible spelling: timeframe.ismonthly; runs without warnings. Returns: bool ``` x = timeframe.ismonthly ``` ### alerta.ta.change https://www.alertachart.com/alertascript/reference/builtins/change Signature: change(source, length) Difference between current value and previous value (length bars ago). TradingView-compatible spelling: ta.change; runs without warnings. - source: series; required: true; default: not specified. Series of values. - length: int; required: not specified; default: 1. Number of bars back. Returns: series float ``` const priceChange = change(close) ``` Aliases: ta.change ### alerta.sum https://www.alertachart.com/alertascript/reference/builtins/sum Signature: sum(source, length) Math namespace alias for sum. TradingView-compatible spelling: math.sum; runs without warnings. - source: series float; required: true; default: not specified. Source series. - length: int; required: true; default: not specified. Window length. Returns: series float ``` v = sum(close, 14) plot(v, { pane: "oscillator" }) ``` Aliases: math.sum Alternate form: sum(source, length) Sum of source for length bars. Returns: series float - source: series. Series of values to process. - length: int. Number of bars. ``` const volSum = sum(volume, 20) ``` ### alerta.ta.valuewhen https://www.alertachart.com/alertascript/reference/builtins/valuewhen Signature: valuewhen(condition, source, occurrence) Returns the value of `source` when `condition` was last true. TradingView-compatible spelling: ta.valuewhen; runs without warnings. - condition: series bool; required: true; default: not specified. Condition to evaluate. - source: series; required: true; default: not specified. Source series. - occurrence: int; required: not specified; default: 0. 0 for most recent, 1 for previous, etc. Returns: series any ``` ph = pivothigh(high, 5, 5) lastHigh = valuewhen(ph !== null, high, 0) plot(lastHigh) ``` Until the condition has been true `occurrence + 1` times the result is `na`. Used as a price level for a box or line, keep `na` rather than replacing it with 0: a level of 0 stretches the drawing down to zero. Aliases: ta.valuewhen ### alerta.ta.pivothigh https://www.alertachart.com/alertascript/reference/builtins/pivothigh Signature: pivothigh(source, leftLen, rightLen) Returns price if it's a pivot high, else null. Confirmed rightLen bars ago. TradingView-compatible spelling: ta.pivothigh; runs without warnings. - source: series; required: true; default: not specified. Input series. - leftLen: int; required: true; default: not specified. Bars to the left. - rightLen: int; required: true; default: not specified. Bars to the right. Returns: series float ``` const ph = pivothigh(high, 10, 10) if (ph) { plotShape(ph, { style: "label_down" }) } ``` Aliases: ta.pivothigh ### alerta.ta.pivotlow https://www.alertachart.com/alertascript/reference/builtins/pivotlow Signature: pivotlow(source, leftLen, rightLen) Returns price if it's a pivot low, else null. Confirmed rightLen bars ago. TradingView-compatible spelling: ta.pivotlow; runs without warnings. - source: series; required: true; default: not specified. Input series. - leftLen: int; required: true; default: not specified. Bars to the left. - rightLen: int; required: true; default: not specified. Bars to the right. Returns: series float ``` const pl = pivotlow(low, 10, 10) ``` Aliases: ta.pivotlow ### alerta.ta.sar https://www.alertachart.com/alertascript/reference/builtins/sar Signature: sar(start, inc, max) Parabolic Stop and Reverse indicator. TradingView-compatible spelling: ta.sar; runs without warnings. - start: float; required: true; default: not specified. Start value. - inc: float; required: true; default: not specified. Increment. - max: float; required: true; default: not specified. Maximum value. Returns: series float ``` plot(sar(0.02, 0.02, 0.2), { style: "cross" }) ``` Aliases: ta.sar ### alerta.ta.supertrend https://www.alertachart.com/alertascript/reference/builtins/supertrend Signature: supertrend(factor, atrLength, high, low, close) Returns SuperTrend line and trend direction (+1/-1). TradingView-compatible spelling: ta.supertrend; runs without warnings. - factor: float; required: false; default: not specified. ATR multiplier (default 3). - atrLength: int; required: false; default: not specified. ATR length (default 10). - high: series; required: false; default: not specified. High series (default chart high). - low: series; required: false; default: not specified. Low series (default chart low). - close: series; required: false; default: not specified. Close series (default chart close). Returns: { supertrend, direction } ``` const [st, dir] = supertrend(3, 10) plot(st) plotshape(crossover(dir, 0), { style: "triangleup", color: color.green }) ``` Aliases: ta.supertrend ### alerta.ta.vwap https://www.alertachart.com/alertascript/reference/builtins/vwap Signature: ta.vwap(source, anchor?, stdev_mult?) → series float | [vwap, upper, lower] Pine v6: volume-weighted average price, restarted whenever `anchor` is true — by default at the first bar of every trading day on the exchange clock (so on a daily chart it is the source itself). Two overloads: • `ta.vwap(source, anchor)` → series float • `ta.vwap(source, anchor, stdev_mult)` → tuple [vwap, upper, lower] with ±N·stdev bands. The bare `ta.vwap` variable is the session VWAP of hlc3. TradingView-compatible spelling: ta.vwap; runs without warnings. - source: series float; required: true; default: not specified. Price source (e.g. close, hlc3). - anchor: series bool; required: not specified; default: not specified. Reset condition. Default is `timeframe.change("1D")`. - stdev_mult: simple float; required: not specified; default: not specified. When present, the function returns ±N·stdev bands as a tuple. Returns: series float | tuple ``` // Daily-anchored VWAP with ±1σ bands. [v, u, l] = ta.vwap(close, timeframe.change("D"), 1.0) plot(v) plot(u) plot(l) ``` Aliases: ta.vwap ### alerta.ta.stoch https://www.alertachart.com/alertascript/reference/builtins/stoch Signature: stoch(close, high, low, length, k_smooth, d_smooth) Calculates the Stochastic Oscillator. Pine's `ta.stoch(source, high, low, length)` returns ONE series — the raw %K, 100 × (source − lowest low) / (highest high − lowest low) — which scripts smooth themselves, e.g. `k = ta.sma(ta.stoch(close, high, low, 14), 3)`. AlertaScript's own `[k, d] = stoch(close, high, low, 14)` returns the smoothed pair (k_smooth / d_smooth, default 3). TradingView-compatible spelling: ta.stoch; runs without warnings. - close: series float; required: true; default: not specified. Close price series. - high: series float; required: true; default: not specified. High price series. - low: series float; required: true; default: not specified. Low price series. - length: int; required: true; default: not specified. Length. - k_smooth: int; required: not specified; default: 3. Smooth K. - d_smooth: int; required: not specified; default: 3. Smooth D. Returns: [k, d] ``` [k, d] = stoch(close, high, low, 14) plot(k, { title: "K", color: color.blue, pane: "oscillator" }) plot(d, { title: "D", color: color.orange, pane: "oscillator" }) ``` Aliases: ta.stoch ### alerta.ta.cci https://www.alertachart.com/alertascript/reference/builtins/cci Signature: cci(source, length) Calculates the CCI indicator. TradingView-compatible spelling: ta.cci; runs without warnings. - source: series float; required: true; default: not specified. Source price series. - length: int; required: true; default: not specified. Length. Returns: series float ``` plot(cci(close, 20), { pane: "oscillator" }) ``` Aliases: ta.cci ### alerta.ta.obv https://www.alertachart.com/alertascript/reference/builtins/obv Signature: obv(close, volume) Calculates OBV. TradingView-compatible spelling: ta.obv; runs without warnings. - close: series float; required: true; default: not specified. Close price series. - volume: series float; required: true; default: not specified. Volume series. Returns: series float ``` plot(obv(close, volume), { pane: "oscillator" }) ``` Aliases: ta.obv ### alerta.ta.mfi https://www.alertachart.com/alertascript/reference/builtins/mfi Signature: mfi(high, low, close, volume, length) Calculates MFI indicator. Accepts mfi(high, low, close, volume, length) or ta.mfi(source, length). TradingView-compatible spelling: ta.mfi; runs without warnings. - high: series float; required: true; default: not specified. High price. - low: series float; required: true; default: not specified. Low price. - close: series float; required: true; default: not specified. Close price. - volume: series float; required: true; default: not specified. Volume. - length: int; required: true; default: not specified. Length. Returns: series float ``` plot(mfi(high, low, close, volume, 14), { pane: "oscillator" }) ``` Aliases: ta.mfi ### alerta.ta.kdj https://www.alertachart.com/alertascript/reference/builtins/kdj Signature: kdj(close, high, low, length, m1, m2) Calculates the KDJ indicator. TradingView-compatible spelling: ta.kdj; runs without warnings. - close: series float; required: true; default: not specified. Close. - high: series float; required: true; default: not specified. High. - low: series float; required: true; default: not specified. Low. - length: int; required: true; default: not specified. n length. - m1: int; required: true; default: not specified. m1 smooth. - m2: int; required: true; default: not specified. m2 smooth. Returns: [k, d, j] ``` [k, d, j] = kdj(close, high, low, 9, 3, 3) plot(k, { title: "K", color: color.blue, pane: "oscillator" }) plot(d, { title: "D", color: color.orange, pane: "oscillator" }) plot(j, { title: "J", color: color.purple, pane: "oscillator" }) ``` Aliases: ta.kdj ### alerta.ta.dc https://www.alertachart.com/alertascript/reference/builtins/ta.dc Signature: ta.dc(length) Calculates the Donchian Channel — the highest high and lowest low over a given period. Returns an object with upper, lower, and basis (midline) series. TradingView-compatible spelling: ta.dc; runs without warnings. - length: int; required: true; default: not specified. Lookback period in bars. Returns: { upper: series float, lower: series float, basis: series float } ``` indicator("Donchian Channel", overlay=true) const dc = ta.dc(20) plot(dc.upper, { title: "DC Upper", color: "#3B82F6" }) plot(dc.basis, { title: "DC Midline", color: "#9CA3AF" }) plot(dc.lower, { title: "DC Lower", color: "#EF4444" }) fill(plot(dc.upper, { display: "none" }), plot(dc.lower, { display: "none" }), { color: "rgba(59,130,246,0.05)" }) ``` Aliases: ta.dc ### alerta.ta.wvad https://www.alertachart.com/alertascript/reference/builtins/ta.wvad Signature: ta.wvad() Calculates Williams Vane Accumulation/Distribution — a volume-weighted directional pressure indicator using (close - open) / (high - low) * volume. TradingView-compatible spelling: ta.wvad; runs without warnings. Returns: series float ``` indicator("WVAD", overlay=false) const wvad = ta.wvad() const wvadSmooth = sma(wvad, 14) plot(wvadSmooth, { title: "WVAD (14)", color: wvadSmooth > 0 ? "#10B981" : "#EF4444", style: "histogram" }) hline(0) ``` Aliases: ta.wvad ### alerta.ta.pivot_point_levels https://www.alertachart.com/alertascript/reference/builtins/ta.pivot_point_levels Signature: ta.pivot_point_levels(type, anchor, developing?) → array Pine v6: computes pivot levels (P, R1-R5, S1-S5) using one of six methods, anchored to a user-defined period. TradingView-compatible spelling: ta.pivot_point_levels; runs without warnings. - type: series string; required: true; default: not specified. "Traditional" | "Fibonacci" | "Woodie" | "Classic" | "DM" | "Camarilla". - anchor: series bool; required: true; default: not specified. Resets the accumulator when true (e.g. `timeframe.change("W")`). - developing: series bool; required: not specified; default: not specified. When true, the pivot is recomputed live within the current anchor period. Default false. NOTE: developing=true is illegal with type="Woodie". Returns: array ``` //@version=6 indicator("Weekly Pivots", overlay=true) weekChange = timeframe.change("W") levels = ta.pivot_point_levels("Traditional", weekChange) if weekChange for lvl in levels line.new(time, lvl, time + timeframe.in_seconds("W") * 1000, lvl, xloc=xloc.bar_time) ``` Aliases: alerta.ta.pivot_point_levels ### alerta.ta.rci https://www.alertachart.com/alertascript/reference/builtins/ta.rci Signature: ta.rci(source, length) → series float Pine v6: Spearman rank correlation between `source` and the time index over `length` bars. Scaled to [-100, 100]. 100 = monotonically rising, -100 = monotonically falling. TradingView-compatible spelling: ta.rci; runs without warnings. - source: series float; required: true; default: not specified. Price source. - length: simple int; required: true; default: not specified. Window length. Returns: series float ``` plot(ta.rci(close, 14)) ``` Aliases: alerta.ta.rci ### alerta.ta.wpr https://www.alertachart.com/alertascript/reference/builtins/ta.wpr Signature: ta.wpr(length) → series float Pine v6 official name for Williams %R. Oscillator showing current close relative to the high/low range over `length` bars. TradingView-compatible spelling: ta.wpr; runs without warnings. - length: series int; required: true; default: not specified. Window length. Returns: series float ``` plot(ta.wpr(14), color = color.orange) ``` Aliases: alerta.ta.wpr, ta.willr, williamsr ### alerta.timeframe.change https://www.alertachart.com/alertascript/reference/builtins/timeframe.change Signature: timeframe.change(timeframe) → series bool Pine v6: returns true on the first bar of every new period of the specified timeframe. Use it to anchor higher-timeframe-driven pivots, VWAP and aggregations. TradingView-compatible spelling: timeframe.change; runs without warnings. - timeframe: series string; required: true; default: not specified. Target timeframe (e.g. "D", "W", "1M"). Returns: series bool ``` isNewDay = timeframe.change("D") bgcolor(isNewDay ? color.new(color.green, 80) : na) ``` Aliases: alerta.timeframe.change ### alerta.ta.pvt https://www.alertachart.com/alertascript/reference/builtins/ta.pvt Signature: ta.pvt → series float Pine built-in VARIABLE (no parentheses): cumulative sum of the close %-change weighted by volume — cum(change(close)/close[1] * volume). Rises when price gains on volume, falls when price drops on volume. TradingView-compatible spelling: ta.pvt; runs without warnings. Returns: series float ``` //@version=6 indicator("PVT", overlay=false) plot(ta.pvt, title="PVT", color=color.teal) ``` Aliases: alerta.ta.pvt, pvt ### alerta.ta.accdist https://www.alertachart.com/alertascript/reference/builtins/ta.accdist Signature: ta.accdist → series float Pine built-in VARIABLE (no parentheses): cumulative Accumulation/Distribution line — cum(((close-low)-(high-close))/(high-low) * volume). Measures buying vs. selling pressure via the close position inside the bar range. TradingView-compatible spelling: ta.accdist; runs without warnings. Returns: series float ``` //@version=6 indicator("AccDist", overlay=false) plot(ta.accdist, title="A/D", color=color.blue) ``` Aliases: alerta.ta.accdist, accdist ### alerta.ta.iii https://www.alertachart.com/alertascript/reference/builtins/ta.iii Signature: ta.iii → series float Pine built-in VARIABLE (no parentheses): (2*close - high - low) / ((high - low) * volume). Gauges where the close sits in the bar range, normalized by volume. TradingView-compatible spelling: ta.iii; runs without warnings. Returns: series float ``` //@version=6 indicator("III", overlay=false) plot(ta.iii, title="III", color=color.purple) ``` Aliases: alerta.ta.iii, iii ### alerta.ta.nvi https://www.alertachart.com/alertascript/reference/builtins/ta.nvi Signature: ta.nvi → series float Pine built-in VARIABLE (no parentheses): starts at 1.0 and compounds the close %-change ONLY on bars where volume fell versus the prior bar. Tracks what "smart money" does on quiet days. TradingView-compatible spelling: ta.nvi; runs without warnings. Returns: series float ``` //@version=6 indicator("NVI", overlay=false) plot(ta.nvi, title="NVI", color=color.red) ``` Aliases: alerta.ta.nvi, nvi ### alerta.ta.pvi https://www.alertachart.com/alertascript/reference/builtins/ta.pvi Signature: ta.pvi → series float Pine built-in VARIABLE (no parentheses): starts at 1.0 and compounds the close %-change ONLY on bars where volume rose versus the prior bar. Mirror of ta.nvi for high-activity days. TradingView-compatible spelling: ta.pvi; runs without warnings. Returns: series float ``` //@version=6 indicator("PVI", overlay=false) plot(ta.pvi, title="PVI", color=color.green) ``` Aliases: alerta.ta.pvi, pvi ### alerta.ta.wad https://www.alertachart.com/alertascript/reference/builtins/ta.wad Signature: ta.wad → series float Pine built-in VARIABLE (no parentheses): cumulative sum of close - min(low, close[1]) on up-closes and close - max(high, close[1]) on down-closes (0 when unchanged). Larry Williams’ accumulation/distribution measure. TradingView-compatible spelling: ta.wad; runs without warnings. Returns: series float ``` //@version=6 indicator("WAD", overlay=false) plot(ta.wad, title="WAD", color=color.orange) ``` Aliases: alerta.ta.wad, wad ### alerta.strategy.entry https://www.alertachart.com/alertascript/reference/builtins/strategy.entry Signature: strategy.entry(id, direction, qty, limit, stop, oca_name, oca_type, comment, alert_message) Enters a market position (long or short) for strategy backtesting. Must run inside a strategy script header. TradingView-compatible spelling: strategy.entry; runs without warnings. - id: string; required: true; default: not specified. Unique identifier for the order. - direction: string; required: true; default: not specified. "long" or "short" (or strategy.long / strategy.short). - qty: float; required: not specified; default: not specified. Quantity (contracts or percentage depending on settings). - limit: float; required: not specified; default: not specified. Optional limit price. - stop: float; required: not specified; default: not specified. Optional stop price. - oca_name: string; required: not specified; default: not specified. One-Cancels-All group name; orders sharing a group cancel each other when one fills. - oca_type: string; required: not specified; default: not specified. OCA behaviour: strategy.oca.cancel | strategy.oca.reduce | strategy.oca.none. - comment: string; required: not specified; default: not specified. Free-text annotation attached to the order (visible in trade list / alerts). - alert_message: string; required: not specified; default: not specified. Custom alert payload — used when the order fires its alert. Returns: void ``` strategy("Entry Example", overlay=true) if bar_index == 1 strategy.entry("Buy", "long") ``` Use inside strategy scripts only. Replace default indicator header with a strategy header. Orders are kept by id. A second call with the same id replaces the waiting order (on the same bar or while a limit or stop entry still rests); a call with another id waits beside it — two entries on one bar both fill, within the pyramiding limit, and a buy stop above and a sell stop below both rest until the price reaches one of them. An OCA group answers when one of its orders FILLS: with strategy.oca.cancel the group's other orders are withdrawn, with strategy.oca.reduce they shrink by the filled quantity (and are withdrawn at zero). An order the strategy refuses — over the pyramiding limit or a risk rule — fills nothing and cancels nothing. Aliases: buy, sell, enter ### alerta.strategy.exit https://www.alertachart.com/alertascript/reference/builtins/strategy.exit Signature: strategy.exit(id, from_entry, qty, qty_percent, profit, limit, loss, stop, trail_price, trail_points, trail_offset, oca_name, comment, comment_profit, comment_loss, comment_trailing, alert_message) Exits a specific entry by ID with take-profit / stop-loss / trailing legs. `profit`/`loss` are TICK offsets from the entry price; `limit`/`stop` are absolute prices. `from_entry` scopes the exit (and its qty/qty_percent) to trades opened by that entry id. Per-leg comments label the trade by whichever leg fired. TradingView-compatible spelling: strategy.exit; runs without warnings. - id: string; required: true; default: not specified. Order ID for the exit. - from_entry: string; required: not specified; default: not specified. The entry ID to exit from. qty/qty_percent apply to that entry's trades only. - qty: float; required: not specified; default: not specified. Quantity to exit. - qty_percent: float; required: not specified; default: not specified. Percentage of the (scoped) position to exit (0-100). - profit: float; required: not specified; default: not specified. Take-profit distance in TICKS from the entry price. - limit: float; required: not specified; default: not specified. Explicit take-profit PRICE (overrides profit). - loss: float; required: not specified; default: not specified. Stop-loss distance in TICKS from the entry price. - stop: float; required: not specified; default: not specified. Explicit stop-loss PRICE (overrides loss). - trail_price: float; required: not specified; default: not specified. Trailing stop activation price. - trail_points: float; required: not specified; default: not specified. Trailing stop activation: profit from the entry, in ticks. The trailing stop starts once price gets this far in the trade's favour. - trail_offset: float; required: not specified; default: not specified. Trailing distance in ticks: once active, the stop follows the best price since activation this far behind. Needs trail_price or trail_points. - oca_name: string; required: not specified; default: not specified. OCA group name for bracket OCO behavior. - comment: string; required: not specified; default: not specified. Default exit comment. - comment_profit: string; required: not specified; default: not specified. Comment used when the take-profit leg fires. - comment_loss: string; required: not specified; default: not specified. Comment used when the stop-loss leg fires. - comment_trailing: string; required: not specified; default: not specified. Comment used when the trailing stop fires. - alert_message: string; required: not specified; default: not specified. Text for the {{strategy.order.alert_message}} placeholder. Returns: void ``` strategy("Exit Example", overlay=true) if bar_index == 1 strategy.entry("Buy", strategy.long) strategy.exit("ExitBuy", "Buy", limit = close * 1.01, stop = close * 0.99, comment_profit = "TP", comment_loss = "SL") ``` Use inside strategy scripts only. Replace default indicator header with a strategy header. An exit placed together with its entry already protects the entry's first bar. When one bar reaches both the target and the stop, the one the price reaches first along open → nearer extreme → farther extreme → close fills: a bar whose low is nearer the open than its high hits a long's stop first. A trailing stop starts once the price has moved trail_points ticks (or reached trail_price) in the trade's favour and then stays active, following the best price trail_offset ticks behind. Aliases: tp, sl, takeprofit, stoploss ### alerta.strategy.close https://www.alertachart.com/alertascript/reference/builtins/strategy.close Signature: strategy.close(id, comment, qty, qty_percent, alert_message, immediately) Closes what the entry with this id opened, at market price, at the next bar's open (`immediately=true`: at the signal bar's close). With the default close_entries_rule (FIFO) that quantity is taken from the oldest open trades first, so the list of trades can show an earlier entry closed by this order; with close_entries_rule = "ANY" the entry's own trades are closed. When the entry has no open trade the call does nothing — it is not kept for a later position. Must run inside a strategy script header. TradingView-compatible spelling: strategy.close; runs without warnings. - id: string; required: true; default: not specified. The entry ID to close. - comment: string; required: not specified; default: not specified. Comment on the chart. - qty: float; required: not specified; default: not specified. Quantity to close. - qty_percent: float; required: not specified; default: not specified. Percentage of the position to close (0-100). - alert_message: string; required: not specified; default: not specified. Text for the {{strategy.order.alert_message}} placeholder. - immediately: bool; required: not specified; default: false. true = fill at this bar's close instead of the next bar's open. Returns: void ``` strategy("Close Example", overlay=true) if bar_index == 1 strategy.entry("Buy", "long") if bar_index == 2 strategy.close("Buy") ``` Use inside strategy scripts only. Replace default indicator header with a strategy header. Aliases: close_position ### alerta.request.security https://www.alertachart.com/alertascript/reference/builtins/request.security Signature: request.security(symbol, timeframe, expression, gaps, lookahead) Requests data from another symbol or timeframe and aligns it to the chart's bars. The expression is calculated on the requested bars: a higher-timeframe EMA is the EMA of the higher-timeframe bars, not an average of the chart's values. The symbol and the timeframe do not have to be literals — an input, a variable, a function result or a condition may supply them, so one script can request several symbols or timeframes, also from a loop. A symbol AlertaChart has no data for returns na with a warning naming it; the rest of the script keeps running, and the chart's own bars are never substituted for it. TradingView-compatible spelling: request.security; runs without warnings. - symbol: string; required: true; default: not specified. Ticker (e.g. "BINANCE:BTCUSDT", "NASDAQ:AAPL", an order-flow ticker such as "BINANCE:BTCUSDT.P_FUNDING"); syminfo.tickerid or "SELF" for the chart's own symbol. - timeframe: string; required: true; default: not specified. Timeframe string (e.g. "D", "60", "240"). - expression: any; required: true; default: not specified. Expression to evaluate in that timeframe (e.g. close, sma(close, 20)). A tuple such as [close, time_close, time] returns one series per member. - gaps: bool; required: false; default: not specified. Whether to return gaps (barmerge.gaps_on/off). Default false. - lookahead: bool; required: false; default: not specified. Whether to allow lookahead (barmerge.lookahead_on/off). lookahead_on reads the higher timeframe's finished bar, so the series can repaint on history — it runs, with a warning saying so (not for the non-repainting form, an expression offset by one). - currency: string; required: false; default: not specified. Read the requested symbol's prices in this currency (currency.EUR, "BTC", syminfo.currency …): open, high, low and close — and everything the expression builds from them — at the daily rate of the day before each bar; volume and literals stay as they are. Until the rate's data is loaded the request is na with a warning naming it. Returns: series any ``` indicator("Funding rate", overlay = false) // Order flow (Pro): Binance's BTC perpetual funding rate; any ticker works here ("ES1!", "NASDAQ:AAPL", …) sym = input.symbol("BINANCE:BTCUSDT.P_FUNDING", "Ticker") [rate, dailyRate] = request.security(sym, timeframe.period, [close, close * 3]) plot(rate * 100, "Funding % per 8 h") plot(dailyRate * 100, "Funding % per day") ``` Tickers are answered from AlertaChart's own feeds: crypto venues (BINANCE, BYBIT, OKX, COINBASE, HYPERLIQUID, …), US stocks (NASDAQ:AAPL), Hong Kong, Shanghai, Shenzhen and London listings (HKEX:700, SSE:600519, SZSE:300903, LSE:HSBA), forex (OANDA:EURUSD), indices (TVC:DXY, TVC:VIX, SP:SPX), CME/CBOT/COMEX/NYMEX continuous futures (CME_MINI:ES1!), US macro series (FRED:CPIAUCSL, TVC:US10Y), crypto market cap (CRYPTOCAP:TOTAL, BTC.D) and spread formulas (NASDAQ:AAPL/NASDAQ:MSFT). Symbols resolve with or without an exchange prefix when unique. Borsa Istanbul symbols are not available yet and return na with a warning. Stock, forex, futures and index tickers (and spreads with such a leg) come with the plans that open those charts (Trader and above); on other plans they return na, with a warning naming the plan. Crypto pairs, crypto market cap and US macro series are on every plan; order-flow tickers are Pro and Elite (below). Spot gold and silver (OANDA:XAUUSD, TVC:GOLD, XAGUSD …) read the chart's own XAU/USD and XAG/USD on the plans that open those charts (Trader and above). On other plans the same tickers read Binance's XAUUSDT / XAGUSDT perpetual, and a warning names the plan the spot price comes with. US macro series by their FRED id or TradingView name: Treasury yields (FRED:DGS10 or TVC:US10Y, US02Y, US05Y, GS20, US30Y, the 3-month bill FRED:DTB3), SOFR, the fed funds rate (FRED:DFF), the overnight reverse repo (FRED:RRPONTSYD), the 10Y–2Y and 10Y–3M spreads (FRED:T10Y2Y, FRED:T10Y3M) and the high-yield and corporate bond spreads (FRED:BAMLH0A0HYM2, FRED:BAMLC0A0CM) are daily: a request at an intraday timeframe reads the daily values. Release-based series such as CPI (FRED:CPIAUCSL), GDP or unemployment are monthly. Order-flow data of crypto perpetuals is read the same way (Pro and Elite plans): EX:PAIR.P_OI open interest, EX:PAIR.P_FUNDING the funding rate (decimal per 8 hours, 0.0001 = 0.01 %), EX:PAIR.P_CVD cumulative volume delta in coins (EX:PAIR_CVD on spot; the bar's volume is its delta), EX:PAIR.P_LIQ_LONG / EX:PAIR.P_LIQ_SHORT the notional liquidated in the bar (USD) and EX:PAIR.P_NETLONG / EX:PAIR.P_NETSHORT net positions (coins), where EX is BINANCE, BYBIT, OKX, COINBASE or HYPERLIQUID — or AGG for every venue together (AGG:BTC.P_FUNDING, AGG:ETH.P_OI). Without the plan these tickers return na with a warning saying so. A venue's open interest is sampled every 5 minutes: on a 1- to 4-minute chart each value lands on the last chart bar of its 5-minute period, never ahead of the price. Alignment follows Pine on historical bars: a request at the chart's own timeframe is the bar itself, and a higher-timeframe value (lookahead off) arrives on the chart bar that closes together with it — the last bar of its period. barmerge.lookahead_on reads the higher timeframe's finished bar and warns that the series can repaint; its non-repainting form, an expression offset by one (`close[1]` with lookahead_on), runs without that warning. On the live (realtime) bar the request reads the higher timeframe's bar in progress, as Pine does — a daily close on an hourly chart is today's close so far, and barstate.isconfirmed inside the expression is false there. Such a value can change until its period closes (repaint); the non-repainting form `request.security(sym, tf, x[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]` reads closed periods only. Timeframe tokens follow Pine (1, 5, 60, 240, D, W, M; 1m, 1H, 1D; lowercase m = minutes, uppercase M = months). A symbol or timeframe that changes from bar to bar — picked by a condition, read from an array of inputs, or walked by `for … in` — makes one request per value, each read where the call runs. A request inside an if block, a loop or a function is evaluated on the bars that reach it. The expression may return a number, bool, string or color, a tuple such as [close, time_close, time] (destructured on assignment), an array, a matrix or a map (each chart bar gets it as it stood at the end of its requested bar) or an instance of a user-defined type. Before the first requested bar the value is na. A tuple is read only by taking it apart (`[a, b] = request.security(…)`); used as one value it is an error. The variables the expression names are computed on the requested bars too, with the statements that write them — `var` sums, loops (their break and continue included), arrays and maps the script fills with push / put, and objects whose fields it writes. Inside the expression, syminfo.*, timeframe.period and barstate.islast describe the requested symbol and bars; syminfo.main_tickerid and timeframe.main_period stay the chart's. The expression — or a function it calls — may itself call request.security / request.economic (nested requests): the inner request runs in the outer one's context, its "" symbol and timeframe being the outer request's. On a live chart another symbol's forming bar follows that symbol's own updates, so a spread or a comparison keeps moving with both markets. Aliases: security, mtf, htf ### alerta.request.financial https://www.alertachart.com/alertascript/reference/builtins/request.financial Signature: request.financial(symbol, financial_id, period, gaps?, ignore_invalid_symbol?, currency?) Requests a fundamental metric (revenue, EPS, capex, …) for a symbol, period by period. There is no historical fundamentals feed behind this: the call is accepted and returns `na`, with a warning, exactly as TradingView does for a symbol it has no data on. Guard the result with `na(...)`. On a stock chart the company's current profile is available as `syminfo.*` — `syminfo.sector`, `syminfo.industry`, `syminfo.country`, `syminfo.shares_outstanding_total`. TradingView-compatible spelling: request.financial; runs without warnings. - symbol: string; required: true; default: not specified. Symbol to query, e.g. syminfo.tickerid. - financial_id: string; required: true; default: not specified. Metric id, e.g. "TOTAL_REVENUE", "CAPITAL_EXPENDITURES". - period: string; required: true; default: not specified. Reporting period: "FQ", "FH", "FY", "TTM". - gaps: const; required: not specified; default: not specified. barmerge.gaps_on / barmerge.gaps_off. - ignore_invalid_symbol: bool; required: not specified; default: not specified. Return na instead of raising for an unavailable symbol. - currency: string; required: not specified; default: not specified. Convert the result into this currency. Returns: series float — na without a fundamentals feed ``` rev = request.financial(syminfo.tickerid, "TOTAL_REVENUE", "FQ", ignore_invalid_symbol = true) plot(na(rev) ? 0 : rev, { title: "Revenue", pane: "oscillator" }) ``` No fundamentals feed: always na plus a warning. The call no longer stops the script. ### alerta.request.earnings https://www.alertachart.com/alertascript/reference/builtins/request.earnings Signature: request.earnings(symbol, field, gaps?, lookahead?, ignore_invalid_symbol?, currency?) Requests reported earnings for a symbol. The second argument selects which figure: `earnings.actual`, `earnings.estimate` or `earnings.standardized`. As with request.financial there is no fundamentals feed, so the call returns `na` with a warning instead of failing. TradingView-compatible spelling: request.earnings; runs without warnings. - symbol: string; required: true; default: not specified. Symbol to query. - field: const; required: true; default: not specified. earnings.actual | earnings.estimate | earnings.standardized. - gaps: const; required: not specified; default: not specified. barmerge.gaps_on / barmerge.gaps_off. - lookahead: const; required: not specified; default: not specified. barmerge.lookahead_on / barmerge.lookahead_off. - ignore_invalid_symbol: bool; required: not specified; default: not specified. Return na instead of raising for an unavailable symbol. - currency: string; required: not specified; default: not specified. Convert the result into this currency. Returns: series float — na without a fundamentals feed ``` eps = request.earnings(syminfo.tickerid, earnings.actual, ignore_invalid_symbol = true) plot(na(eps) ? 0 : eps, { title: "EPS", pane: "oscillator" }) ``` `earnings.actual` / `.estimate` / `.standardized` are the field constants. No fundamentals feed: always na plus a warning. ### alerta.request.dividends https://www.alertachart.com/alertascript/reference/builtins/request.dividends Signature: request.dividends(symbol, field?, gaps?, lookahead?, ignore_invalid_symbol?, currency?) Requests dividend payments for a symbol (`dividends.gross` / `dividends.net`). Returns `na` with a warning — AlertaScript has no fundamentals feed. TradingView-compatible spelling: request.dividends; runs without warnings. - symbol: string; required: true; default: not specified. Symbol to query. - field: const; required: not specified; default: not specified. dividends.gross | dividends.net. - gaps: const; required: not specified; default: not specified. barmerge.gaps_on / barmerge.gaps_off. - lookahead: const; required: not specified; default: not specified. barmerge.lookahead_on / barmerge.lookahead_off. - ignore_invalid_symbol: bool; required: not specified; default: not specified. Return na instead of raising. - currency: string; required: not specified; default: not specified. Convert the result into this currency. Returns: series float — na without a fundamentals feed ``` d = request.dividends(syminfo.tickerid, dividends.gross, ignore_invalid_symbol = true) plot(na(d) ? 0 : d, { title: "Dividend", pane: "oscillator" }) ``` ### alerta.request.splits https://www.alertachart.com/alertascript/reference/builtins/request.splits Signature: request.splits(symbol, field, gaps?, lookahead?, ignore_invalid_symbol?) Requests split events for a symbol (`splits.numerator` / `splits.denominator`). Returns `na` with a warning — AlertaScript has no fundamentals feed. TradingView-compatible spelling: request.splits; runs without warnings. - symbol: string; required: true; default: not specified. Symbol to query. - field: const; required: true; default: not specified. splits.numerator | splits.denominator. - gaps: const; required: not specified; default: not specified. barmerge.gaps_on / barmerge.gaps_off. - lookahead: const; required: not specified; default: not specified. barmerge.lookahead_on / barmerge.lookahead_off. - ignore_invalid_symbol: bool; required: not specified; default: not specified. Return na instead of raising. Returns: series float — na without a fundamentals feed ``` s = request.splits(syminfo.tickerid, splits.numerator, ignore_invalid_symbol = true) plot(na(s) ? 0 : s, { title: "Split numerator", pane: "oscillator" }) ``` ### alerta.request.footprint https://www.alertachart.com/alertascript/reference/builtins/request.footprint Signature: request.footprint(ticks_per_row, va_percent, imbalance_percent) → footprint The volume footprint of every bar: its buy and sell volume by price row, Point of Control, value area and diagonal imbalances, read through `footprint.*()` and `volume_row.*()`. AlertaChart builds it from the symbol's own order flow — the taker buy / sell volume AlertaChart records for every minute (Binance spot and perpetuals; Bybit, OKX and Coinbase for BTC, ETH, XRP and SOL), spread over each minute's traded range, and the exact trade prices of the exchange's live trade stream for the bars since the chart opened. Inside `request.security` with another symbol — written out, from an input or a variable — that symbol's order flow. na (with one warning) on symbols without order flow: stocks, CME futures, forex. TradingView-compatible spelling: request.footprint; runs without warnings. - ticks_per_row: simple int; required: true; default: not specified. Row height in ticks (syminfo.mintick). A bar with more than 5000 rows is na. - va_percent: simple float; required: not specified; default: 70. Share of the bar's volume the value area holds. - imbalance_percent: simple float; required: not specified; default: 300. How many percent of the diagonal row's opposite volume a row's buy (or sell) volume must reach to be an imbalance: 300 = three times. Returns: series footprint — na where the bar has no order flow ``` indicator("Footprint delta") footprint fp = request.footprint(20, 70, 300) float buyVol = na(fp) ? na : fp.buy_volume() float sellVol = na(fp) ? na : fp.sell_volume() plot(buyVol - sellVol, "Footprint delta", style = plot.style_columns) ``` Bar totals are exact: buy_volume, sell_volume and delta are the sums of the bar's minutes (for 4h and daily charts, 5-minute buckets). Closed bars' rows are rebuilt from minutes, not from single trades: with 1m buckets, measured against Binance trades, the POC is within one row 90 % of the time at ≤ 10 rows a bar, 72 % at 10–20 rows and 45 % at 20–40 rows. Wider rows (a larger ticks_per_row) are closer to the exact footprint. History reaches back at most about 21 days on charts up to 1h and 100 days on 4h and daily charts — less where the record is shorter (Bybit, OKX and Coinbase: about 50 days). Tick and range charts and seconds timeframes have no footprint. Minutes the live trade stream missed — a dropped connection or skipped trades — are filled from the recorded minutes once they are fetched again after the gap; until then the bar is na. A minute missing from the record as well leaves its bar na. In a request of another timeframe the stream's levels count only as whole bars inside a longer bar. A lower-timeframe request (`request.security_lower_tf`) of the chart's own symbol reads the live stream's minute bars, which the chart keeps while such a script runs, and the recorded minutes before them. ### alerta.request.security_lower_tf https://www.alertachart.com/alertascript/reference/builtins/request.security_lower_tf Signature: request.security_lower_tf(symbol, timeframe, expression) → array (or a tuple of arrays) Requests EVERY lower-timeframe value that falls inside each chart bar. Unlike `request.security`, which projects one value per bar, this returns an ARRAY per bar — read it with `array.size` / `array.get` / `for … in`. The requested timeframe must not be higher than the chart timeframe (the chart's own gives one element per bar). When no intrabar series is available the arrays come back empty (size 0) and a warning is raised, so guard with `if arr.size() > 0`. TradingView-compatible spelling: request.security_lower_tf; runs without warnings. - symbol: string; required: true; default: not specified. Symbol to query. An empty string ("") means the chart's own symbol, same as `syminfo.tickerid`. - timeframe: string; required: true; default: not specified. Lower timeframe token. - expression: any; required: true; default: not specified. Expression to evaluate. - ignore_invalid_timeframe: bool; required: not specified; default: not specified. Pine v6: return na instead of raising when the requested timeframe is higher than the chart's. - currency: string; required: not specified; default: not specified. Pine v6: convert the result into this currency. - ignore_invalid_symbol: bool; required: not specified; default: not specified. Pine v6: return na instead of raising for an unavailable symbol. - calc_bars_count: int; required: not specified; default: not specified. Pine v6: use only the last N bars of the requested context. Returns: array — one array per bar; a tuple expression returns one array per member ``` vols = request.security_lower_tf("", "1S", volume) n = array.size(vols) plot(n > 0 ? array.sum(vols) : na, { title: "Intrabar volume" }) ``` Returns an ARRAY per bar, not a projected series — `plot(request.security_lower_tf(...))` is a type error in Pine and here. A tuple expression returns a tuple of arrays: `[h, l, v] = request.security_lower_tf("", "1", [high, low, volume])`. No lookahead: a bar receives only the lower-timeframe bars that fall inside it. A timeframe higher than the chart's is an error; the chart's own timeframe returns one element per bar. No intrabar data available → empty arrays plus a warning, never a stopped script. Aliases: security_lower_tf ### alerta.strategy.order https://www.alertachart.com/alertascript/reference/builtins/strategy.order Signature: strategy.order(id, direction, qty, limit, stop, comment) Places a market, limit, or stop order regardless of the current position. Does not automatically reverse positions like strategy.entry. TradingView-compatible spelling: strategy.order; runs without warnings. - id: string; required: true; default: not specified. Unique identifier for the order. - direction: string; required: true; default: not specified. "long" or "short". - qty: float; required: not specified; default: not specified. Quantity (contracts or percentage). - limit: float; required: not specified; default: not specified. Limit price for the order. - stop: float; required: not specified; default: not specified. Stop price for the order. - comment: string; required: not specified; default: not specified. Order comment. Returns: void ``` strategy("Order Example", overlay=true) if bar_index == 1 strategy.order("AddMore", "long", 10) ``` ### alerta.strategy.equity https://www.alertachart.com/alertascript/reference/builtins/strategy.equity Signature: strategy.equity Returns the current equity (initial capital + realized profit + open profit) for the strategy at the current bar. TradingView-compatible spelling: strategy.equity; runs without warnings. Returns: series float ``` strategy("Equity Plot", overlay=false) plot(strategy.equity, { title: "Current Equity" }) ``` ### alerta.strategy.netprofit_percent https://www.alertachart.com/alertascript/reference/builtins/strategy.netprofit_percent Signature: strategy.netprofit_percent Realized net profit expressed as a percentage of the initial capital. Companion percent variants also available: strategy.openprofit_percent, strategy.grossprofit_percent, strategy.grossloss_percent, strategy.max_drawdown_percent, strategy.max_runup_percent. TradingView-compatible spelling: strategy.netprofit_percent; runs without warnings. Returns: series float ``` strategy("NP%", overlay=false) plot(strategy.netprofit_percent, title="Net Profit %") ``` Aliases: strategy.openprofit_percent, strategy.grossprofit_percent, strategy.grossloss_percent, strategy.max_drawdown_percent, strategy.max_runup_percent ### alerta.strategy.avg_trade https://www.alertachart.com/alertascript/reference/builtins/strategy.avg_trade Signature: strategy.avg_trade Average profit/loss per closed trade. Companions: strategy.avg_trade_percent (per-trade % of entry notional), strategy.avg_winning_trade(_percent), strategy.avg_losing_trade(_percent). TradingView-compatible spelling: strategy.avg_trade; runs without warnings. Returns: series float ``` strategy("AvgTrade", overlay=false) plot(strategy.avg_trade, title="Avg Trade") plot(strategy.avg_winning_trade, title="Avg Win") ``` Aliases: strategy.avg_trade_percent, strategy.avg_winning_trade, strategy.avg_winning_trade_percent, strategy.avg_losing_trade, strategy.avg_losing_trade_percent ### alerta.strategy.margin_liquidation_price https://www.alertachart.com/alertascript/reference/builtins/strategy.margin_liquidation_price Signature: strategy.margin_liquidation_price Price at which a margin call would liquidate the position. AlertaScript does not simulate leverage/margin, so this returns na — matching Pine's value when margin requirements are 100%. TradingView-compatible spelling: strategy.margin_liquidation_price; runs without warnings. Returns: series float (na) ``` strategy("Margin liquidation price", overlay=true, margin_long=25) if bar_index == 3 strategy.entry("Long", strategy.long, qty=100) plot(strategy.margin_liquidation_price, "Liquidation price") ``` ### alerta.strategy.position_size https://www.alertachart.com/alertascript/reference/builtins/strategy.position_size Signature: strategy.position_size Returns the size of the current open position. Positive for long positions, negative for short positions, and 0 if neutral. TradingView-compatible spelling: strategy.position_size; runs without warnings. Returns: series float ``` strategy("Pos Size Plot", overlay=false) plot(strategy.position_size, { title: "Position Size" }) ``` ### alerta.strategy.openprofit https://www.alertachart.com/alertascript/reference/builtins/strategy.openprofit Signature: strategy.openprofit Returns the unrealized profit/loss of the currently open positions. TradingView-compatible spelling: strategy.openprofit; runs without warnings. Returns: series float ``` strategy("Open Profit Plot", overlay=false) plot(strategy.openprofit, { title: "Unrealized PnL" }) ``` ### alerta.strategy.risk.max_drawdown https://www.alertachart.com/alertascript/reference/builtins/strategy.risk.max_drawdown Signature: strategy.risk.max_drawdown(value, type) Sets the maximum drawdown limit for the strategy. If reached, the strategy stops opening new positions. TradingView-compatible spelling: strategy.risk.max_drawdown; runs without warnings. - value: float; required: true; default: not specified. The maximum drawdown threshold. - type: string; required: not specified; default: not specified. "cash" or "percent". Default is "cash". Returns: void ``` strategy("Risk: Max DD", overlay=true) strategy.risk.max_drawdown(15, "percent") ``` ### alerta.strategy.risk.max_position_size https://www.alertachart.com/alertascript/reference/builtins/strategy.risk.max_position_size Signature: strategy.risk.max_position_size(size) Caps the quantity of any entry order to the specified size. TradingView-compatible spelling: strategy.risk.max_position_size; runs without warnings. - size: float; required: true; default: not specified. Maximum allowed position size. Returns: void ``` strategy("Risk: Max Size", overlay=true) strategy.risk.max_position_size(10) strategy.entry("BigOrder", "long", 100) // will be capped to 10 ``` ### alerta.strategy.risk.allow_entry_in https://www.alertachart.com/alertascript/reference/builtins/strategy.risk.allow_entry_in Signature: strategy.risk.allow_entry_in(direction) Restricts strategy entries to a specific direction. TradingView-compatible spelling: strategy.risk.allow_entry_in; runs without warnings. - direction: string; required: true; default: not specified. "long", "short", or "all". Returns: void ``` strategy("Risk: Long Only", overlay=true) strategy.risk.allow_entry_in("long") ``` ### alerta.strategy.opentrades https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades Signature: strategy.opentrades Returns the number of currently open trades in the strategy. TradingView-compatible spelling: strategy.opentrades; runs without warnings. Returns: int ``` strategy("Open Trades Count", overlay=true) plot(strategy.opentrades, { pane: "oscillator" }) ``` ### alerta.strategy.closedtrades https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades Signature: strategy.closedtrades Returns the total number of closed trades in the strategy performance history. TradingView-compatible spelling: strategy.closedtrades; runs without warnings. Returns: int ``` strategy("Closed Trades Count", overlay=true) plot(strategy.closedtrades, { pane: "oscillator" }) ``` ### alerta.strategy.opentrades.entry_price https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.entry_price Signature: strategy.opentrades.entry_price(trade_index) Returns the entry price for the specified open trade. TradingView-compatible spelling: strategy.opentrades.entry_price; runs without warnings. - trade_index: int; required: true; default: not specified. The index of the open trade (0 is oldest). Returns: float ``` strategy("strategy.opentrades.entry_price", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") value = strategy.opentrades > 0 ? strategy.opentrades.entry_price(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.profit https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.profit Signature: strategy.closedtrades.profit(trade_index) Returns the profit or loss for the specified closed trade. TradingView-compatible spelling: strategy.closedtrades.profit; runs without warnings. - trade_index: int; required: true; default: not specified. The index of the closed trade (0 is oldest). Returns: float ``` strategy("Last Trade Profit", overlay=true) lastProfit = strategy.closedtrades > 0 ? strategy.closedtrades.profit(strategy.closedtrades - 1) : 0 plot(lastProfit, { pane: "oscillator" }) ``` ### alerta.strategy.cancel https://www.alertachart.com/alertascript/reference/builtins/strategy.cancel Signature: strategy.cancel(id) Cancels pending orders and active exits with the given id. TradingView-compatible spelling: strategy.cancel; runs without warnings. - id: string; required: true; default: not specified. Order or exit id to cancel. Returns: void ``` strategy("Cancel Example", overlay=true) if bar_index == 1 strategy.entry("L1", "long", limit = close * 0.99) if bar_index == 2 strategy.cancel("L1") ``` ### alerta.strategy.cancel_all https://www.alertachart.com/alertascript/reference/builtins/strategy.cancel_all Signature: strategy.cancel_all() Cancels all pending entries and active exit orders. TradingView-compatible spelling: strategy.cancel_all; runs without warnings. Returns: void ``` strategy("Cancel All Example", overlay=true) if bar_index == 1 strategy.entry("L1", "long", limit = close * 0.99) if bar_index == 2 strategy.cancel_all() ``` ### alerta.strategy.close_all https://www.alertachart.com/alertascript/reference/builtins/strategy.close_all Signature: strategy.close_all(comment, alert_message, immediately) Closes all open positions at market. `immediately=true` fills at the signal bar's close instead of the next bar's open. TradingView-compatible spelling: strategy.close_all; runs without warnings. - comment: string; required: not specified; default: not specified. Optional close reason shown on the trade. - alert_message: string; required: not specified; default: not specified. Text for the {{strategy.order.alert_message}} placeholder. - immediately: bool; required: not specified; default: false. true = fill at this bar's close instead of the next bar's open. Returns: void ``` strategy("Close All Example", overlay=true) if bar_index == 1 strategy.entry("L1", "long") if bar_index == 2 strategy.close_all() ``` ### alerta.strategy.risk.max_cons_loss_days https://www.alertachart.com/alertascript/reference/builtins/strategy.risk.max_cons_loss_days Signature: strategy.risk.max_cons_loss_days(count) Stops new entries after the configured number of consecutive losing trades. TradingView-compatible spelling: strategy.risk.max_cons_loss_days; runs without warnings. - count: int; required: true; default: not specified. Max consecutive losing sequence. Returns: void ``` strategy("Risk Consecutive Loss", overlay=true) strategy.risk.max_cons_loss_days(2) ``` ### alerta.strategy.risk.max_intraday_filled_orders https://www.alertachart.com/alertascript/reference/builtins/strategy.risk.max_intraday_filled_orders Signature: strategy.risk.max_intraday_filled_orders(count) Limits how many fills can occur within the current bar/day approximation. TradingView-compatible spelling: strategy.risk.max_intraday_filled_orders; runs without warnings. - count: int; required: true; default: not specified. Max filled orders. Returns: void ``` strategy("Risk Filled Orders", overlay=true) strategy.risk.max_intraday_filled_orders(3) ``` ### alerta.strategy.risk.max_intraday_loss https://www.alertachart.com/alertascript/reference/builtins/strategy.risk.max_intraday_loss Signature: strategy.risk.max_intraday_loss(value, type) Stops new entries when current bar/day loss limit is exceeded. TradingView-compatible spelling: strategy.risk.max_intraday_loss; runs without warnings. - value: float; required: true; default: not specified. Loss threshold. - type: string; required: not specified; default: not specified. "cash" or "percent". Returns: void ``` strategy("Risk Intraday Loss", overlay=true) strategy.risk.max_intraday_loss(2, "percent") ``` ### alerta.strategy.opentrades.profit_percent https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.profit_percent Signature: strategy.opentrades.profit_percent(trade_index) Returns mark-to-market profit percent for an open trade. TradingView-compatible spelling: strategy.opentrades.profit_percent; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: float ``` strategy("Open Profit %", overlay=true) p = strategy.opentrades > 0 ? strategy.opentrades.profit_percent(0) : 0 plot(p, { pane: "oscillator" }) ``` ### alerta.strategy.closedtrades.profit_percent https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.profit_percent Signature: strategy.closedtrades.profit_percent(trade_index) Returns realized profit percent for a closed trade. TradingView-compatible spelling: strategy.closedtrades.profit_percent; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: float ``` strategy("Closed Profit %", overlay=true) p = strategy.closedtrades > 0 ? strategy.closedtrades.profit_percent(strategy.closedtrades - 1) : 0 plot(p, { pane: "oscillator" }) ``` ### alerta.strategy.opentrades.entry_bar_index https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.entry_bar_index Signature: strategy.opentrades.entry_bar_index(trade_index) Returns the entry bar index of an open trade. TradingView-compatible spelling: strategy.opentrades.entry_bar_index; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: int ``` strategy("strategy.opentrades.entry_bar_index", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") value = strategy.opentrades > 0 ? strategy.opentrades.entry_bar_index(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.entry_bar_index https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.entry_bar_index Signature: strategy.closedtrades.entry_bar_index(trade_index) Returns entry bar index for a closed trade. TradingView-compatible spelling: strategy.closedtrades.entry_bar_index; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: int ``` strategy("strategy.closedtrades.entry_bar_index", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.entry_bar_index(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.exit_bar_index https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.exit_bar_index Signature: strategy.closedtrades.exit_bar_index(trade_index) Returns exit bar index for a closed trade. TradingView-compatible spelling: strategy.closedtrades.exit_bar_index; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: int ``` strategy("strategy.closedtrades.exit_bar_index", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.exit_bar_index(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.opentrades.max_runup https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.max_runup Signature: strategy.opentrades.max_runup(trade_index) Returns max favorable excursion for an open trade. TradingView-compatible spelling: strategy.opentrades.max_runup; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: float ``` strategy("Open Runup", overlay=true) v = strategy.opentrades > 0 ? strategy.opentrades.max_runup(0) : 0 plot(v, { pane: "oscillator" }) ``` ### alerta.strategy.opentrades.max_drawdown https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.max_drawdown Signature: strategy.opentrades.max_drawdown(trade_index) Returns max adverse excursion for an open trade. TradingView-compatible spelling: strategy.opentrades.max_drawdown; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: float ``` strategy("Open Drawdown", overlay=true) v = strategy.opentrades > 0 ? strategy.opentrades.max_drawdown(0) : 0 plot(v, { pane: "oscillator" }) ``` ### alerta.strategy.closedtrades.max_runup https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.max_runup Signature: strategy.closedtrades.max_runup(trade_index) Returns max favorable excursion for a closed trade. TradingView-compatible spelling: strategy.closedtrades.max_runup; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: float ``` strategy("Closed Runup", overlay=true) v = strategy.closedtrades > 0 ? strategy.closedtrades.max_runup(0) : 0 plot(v, { pane: "oscillator" }) ``` ### alerta.strategy.closedtrades.max_drawdown https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.max_drawdown Signature: strategy.closedtrades.max_drawdown(trade_index) Returns max adverse excursion for a closed trade. TradingView-compatible spelling: strategy.closedtrades.max_drawdown; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: float ``` strategy("Closed Drawdown", overlay=true) v = strategy.closedtrades > 0 ? strategy.closedtrades.max_drawdown(0) : 0 plot(v, { pane: "oscillator" }) ``` ### alerta.strategy.opentrades.entry_id https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.entry_id Signature: strategy.opentrades.entry_id(trade_index) Returns entry id of an open trade. TradingView-compatible spelling: strategy.opentrades.entry_id; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: string ``` strategy("strategy.opentrades.entry_id", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") value = strategy.opentrades > 0 ? strategy.opentrades.entry_id(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.entry_id https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.entry_id Signature: strategy.closedtrades.entry_id(trade_index) Returns entry id of a closed trade. TradingView-compatible spelling: strategy.closedtrades.entry_id; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: string ``` strategy("strategy.closedtrades.entry_id", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.entry_id(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.exit_id https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.exit_id Signature: strategy.closedtrades.exit_id(trade_index) Returns the id of the order that closed the trade: the strategy.exit id, the id passed to strategy.close, the reversing entry's id, or "close_all". TradingView-compatible spelling: strategy.closedtrades.exit_id; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: string ``` strategy("strategy.closedtrades.exit_id", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.exit_id(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.opentrades.entry_comment https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.entry_comment Signature: strategy.opentrades.entry_comment(trade_index) Returns entry comment of an open trade. TradingView-compatible spelling: strategy.opentrades.entry_comment; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: string ``` strategy("strategy.opentrades.entry_comment", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") value = strategy.opentrades > 0 ? strategy.opentrades.entry_comment(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.opentrades.entry_time https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.entry_time Signature: strategy.opentrades.entry_time(trade_index) Returns entry time of an open trade. TradingView-compatible spelling: strategy.opentrades.entry_time; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: int ``` strategy("strategy.opentrades.entry_time", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") value = strategy.opentrades > 0 ? strategy.opentrades.entry_time(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.opentrades.size https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.size Signature: strategy.opentrades.size(trade_index) Returns quantity of an open trade. TradingView-compatible spelling: strategy.opentrades.size; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: float ``` strategy("Open Size", overlay=true) s = strategy.opentrades > 0 ? strategy.opentrades.size(0) : 0 plot(s, { pane: "oscillator" }) ``` ### alerta.strategy.opentrades.commission https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.commission Signature: strategy.opentrades.commission(trade_index) Returns accumulated commission of an open trade. TradingView-compatible spelling: strategy.opentrades.commission; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: float ``` strategy("Open Commission", overlay=true) c = strategy.opentrades > 0 ? strategy.opentrades.commission(0) : 0 plot(c, { pane: "oscillator" }) ``` ### alerta.strategy.opentrades.profit https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.profit Signature: strategy.opentrades.profit(trade_index) Returns current unrealized profit of an open trade. TradingView-compatible spelling: strategy.opentrades.profit; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: float ``` strategy("Open Profit", overlay=true) p = strategy.opentrades > 0 ? strategy.opentrades.profit(0) : 0 plot(p, { pane: "oscillator" }) ``` ### alerta.strategy.opentrades.max_runup_percent https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.max_runup_percent Signature: strategy.opentrades.max_runup_percent(trade_index) Returns max runup percent for an open trade. TradingView-compatible spelling: strategy.opentrades.max_runup_percent; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: float ``` strategy("Open Runup %", overlay=true) v = strategy.opentrades > 0 ? strategy.opentrades.max_runup_percent(0) : 0 plot(v, { pane: "oscillator" }) ``` ### alerta.strategy.opentrades.max_drawdown_percent https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.max_drawdown_percent Signature: strategy.opentrades.max_drawdown_percent(trade_index) Returns max drawdown percent for an open trade. TradingView-compatible spelling: strategy.opentrades.max_drawdown_percent; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: float ``` strategy("Open Drawdown %", overlay=true) v = strategy.opentrades > 0 ? strategy.opentrades.max_drawdown_percent(0) : 0 plot(v, { pane: "oscillator" }) ``` ### alerta.strategy.opentrades.entry_bar https://www.alertachart.com/alertascript/reference/builtins/strategy.opentrades.entry_bar Signature: strategy.opentrades.entry_bar(trade_index) Alias of entry bar index for open trades. TradingView-compatible spelling: strategy.opentrades.entry_bar_index; runs without warnings. - trade_index: int; required: true; default: not specified. Open trade index. Returns: int ``` strategy("strategy.opentrades.entry_bar", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") value = strategy.opentrades > 0 ? strategy.opentrades.entry_bar(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.entry_price https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.entry_price Signature: strategy.closedtrades.entry_price(trade_index) Returns entry price of a closed trade. TradingView-compatible spelling: strategy.closedtrades.entry_price; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: float ``` strategy("strategy.closedtrades.entry_price", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.entry_price(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.entry_comment https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.entry_comment Signature: strategy.closedtrades.entry_comment(trade_index) Returns entry comment of a closed trade. TradingView-compatible spelling: strategy.closedtrades.entry_comment; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: string ``` strategy("strategy.closedtrades.entry_comment", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.entry_comment(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.entry_time https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.entry_time Signature: strategy.closedtrades.entry_time(trade_index) Returns entry time of a closed trade. TradingView-compatible spelling: strategy.closedtrades.entry_time; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: int ``` strategy("strategy.closedtrades.entry_time", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.entry_time(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.exit_price https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.exit_price Signature: strategy.closedtrades.exit_price(trade_index) Returns exit price of a closed trade. TradingView-compatible spelling: strategy.closedtrades.exit_price; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: float ``` strategy("strategy.closedtrades.exit_price", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.exit_price(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.exit_comment https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.exit_comment Signature: strategy.closedtrades.exit_comment(trade_index) Returns exit comment of a closed trade. TradingView-compatible spelling: strategy.closedtrades.exit_comment; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: string ``` strategy("strategy.closedtrades.exit_comment", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.exit_comment(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.exit_time https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.exit_time Signature: strategy.closedtrades.exit_time(trade_index) Returns exit time of a closed trade. TradingView-compatible spelling: strategy.closedtrades.exit_time; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: int ``` strategy("strategy.closedtrades.exit_time", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.exit_time(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.size https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.size Signature: strategy.closedtrades.size(trade_index) Returns quantity of a closed trade. TradingView-compatible spelling: strategy.closedtrades.size; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: float ``` strategy("Closed Size", overlay=true) s = strategy.closedtrades > 0 ? strategy.closedtrades.size(0) : 0 plot(s, { pane: "oscillator" }) ``` ### alerta.strategy.closedtrades.commission https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.commission Signature: strategy.closedtrades.commission(trade_index) Returns paid commission of a closed trade. TradingView-compatible spelling: strategy.closedtrades.commission; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: float ``` strategy("Closed Commission", overlay=true) c = strategy.closedtrades > 0 ? strategy.closedtrades.commission(0) : 0 plot(c, { pane: "oscillator" }) ``` ### alerta.strategy.closedtrades.max_runup_percent https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.max_runup_percent Signature: strategy.closedtrades.max_runup_percent(trade_index) Returns max runup percent for a closed trade. TradingView-compatible spelling: strategy.closedtrades.max_runup_percent; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: float ``` strategy("Closed Runup %", overlay=true) v = strategy.closedtrades > 0 ? strategy.closedtrades.max_runup_percent(0) : 0 plot(v, { pane: "oscillator" }) ``` ### alerta.strategy.closedtrades.max_drawdown_percent https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.max_drawdown_percent Signature: strategy.closedtrades.max_drawdown_percent(trade_index) Returns max drawdown percent for a closed trade. TradingView-compatible spelling: strategy.closedtrades.max_drawdown_percent; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: float ``` strategy("Closed Drawdown %", overlay=true) v = strategy.closedtrades > 0 ? strategy.closedtrades.max_drawdown_percent(0) : 0 plot(v, { pane: "oscillator" }) ``` ### alerta.strategy.closedtrades.entry_bar https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.entry_bar Signature: strategy.closedtrades.entry_bar(trade_index) Alias of entry bar index for closed trades. TradingView-compatible spelling: strategy.closedtrades.entry_bar_index; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: int ``` strategy("strategy.closedtrades.entry_bar", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.entry_bar(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.closedtrades.exit_bar https://www.alertachart.com/alertascript/reference/builtins/strategy.closedtrades.exit_bar Signature: strategy.closedtrades.exit_bar(trade_index) Alias of exit bar index for closed trades. TradingView-compatible spelling: strategy.closedtrades.exit_bar_index; runs without warnings. - trade_index: int; required: true; default: not specified. Closed trade index. Returns: int ``` strategy("strategy.closedtrades.exit_bar", overlay=false) if bar_index == 3 strategy.entry("Long", strategy.long, comment="Example entry") if bar_index == 8 strategy.close("Long", comment="Example exit") value = strategy.closedtrades > 0 ? strategy.closedtrades.exit_bar(0) : na var result = table.new(position.top_right, 1, 1) if barstate.islast table.cell(result, 0, 0, str.tostring(value), text_color=chart.fg_color) ``` ### alerta.strategy.initial_capital https://www.alertachart.com/alertascript/reference/builtins/strategy.initial_capital Signature: strategy.initial_capital Returns the starting capital defined in the strategy() declaration. TradingView-compatible spelling: strategy.initial_capital; runs without warnings. Returns: float ``` strategy("Capital Info", overlay=true) const pct = (strategy.equity / strategy.initial_capital - 1) * 100 plot(pct, { title: "Return %", pane: "oscillator" }) ``` ### alerta.strategy.grossprofit https://www.alertachart.com/alertascript/reference/builtins/strategy.grossprofit Signature: strategy.grossprofit Returns the total profit from all winning closed trades. TradingView-compatible spelling: strategy.grossprofit; runs without warnings. Returns: float ``` strategy("P&L Breakdown", overlay=true) plot(strategy.grossprofit, { title: "Gross Profit", color: "#10B981", pane: "oscillator" }) plot(strategy.grossloss, { title: "Gross Loss", color: "#EF4444", pane: "oscillator" }) ``` ### alerta.strategy.grossloss https://www.alertachart.com/alertascript/reference/builtins/strategy.grossloss Signature: strategy.grossloss Returns the total loss (as a positive number) from all losing closed trades. TradingView-compatible spelling: strategy.grossloss; runs without warnings. Returns: float ``` strategy("Loss Report", overlay=true) const ratio = strategy.grossprofit / math.max(strategy.grossloss, 1) plot(ratio, { title: "Profit Factor", pane: "oscillator" }) ``` ### alerta.strategy.wintrades https://www.alertachart.com/alertascript/reference/builtins/strategy.wintrades Signature: strategy.wintrades Returns the number of closed trades that ended with a profit. TradingView-compatible spelling: strategy.wintrades; runs without warnings. Returns: int ``` strategy("Win Rate", overlay=true) const wr = strategy.closedtrades > 0 ? strategy.wintrades / strategy.closedtrades * 100 : 0 plot(wr, { title: "Win Rate %", pane: "oscillator" }) ``` ### alerta.strategy.losstrades https://www.alertachart.com/alertascript/reference/builtins/strategy.losstrades Signature: strategy.losstrades Returns the number of closed trades that ended with a loss. TradingView-compatible spelling: strategy.losstrades; runs without warnings. Returns: int ``` strategy("Trade Stats", overlay=true) plot(strategy.wintrades, { title: "Wins", color: "#10B981", pane: "oscillator" }) plot(strategy.losstrades, { title: "Losses", color: "#EF4444", pane: "oscillator" }) ``` ### alerta.strategy.eventrades https://www.alertachart.com/alertascript/reference/builtins/strategy.eventrades Signature: strategy.eventrades Returns the number of closed trades that ended at breakeven (no profit, no loss). TradingView-compatible spelling: strategy.eventrades; runs without warnings. Returns: int ``` strategy("Even Trades", overlay=true) plot(strategy.eventrades, { title: "Breakeven Trades", pane: "oscillator" }) ``` ### alerta.strategy.max_drawdown https://www.alertachart.com/alertascript/reference/builtins/strategy.max_drawdown Signature: strategy.max_drawdown Returns the maximum equity drawdown of the backtest, intrabar as in the Strategy Tester: the highest closed-trade equity so far minus the equity at a bar's adverse extreme (the low of a long, the high of a short). TradingView-compatible spelling: strategy.max_drawdown; runs without warnings. Returns: float ``` strategy("Drawdown Monitor", overlay=true) plot(strategy.max_drawdown, { title: "Max Drawdown", color: "#EF4444", pane: "oscillator" }) ``` ### alerta.strategy.max_runup https://www.alertachart.com/alertascript/reference/builtins/strategy.max_runup Signature: strategy.max_runup Returns the maximum equity run-up of the backtest, intrabar: the equity at a bar's favourable extreme minus the lowest closed-trade equity so far. TradingView-compatible spelling: strategy.max_runup; runs without warnings. Returns: float ``` strategy("Runup Monitor", overlay=true) plot(strategy.max_runup, { title: "Max Run-up", color: "#10B981", pane: "oscillator" }) ``` ### alerta.strategy.account_currency https://www.alertachart.com/alertascript/reference/builtins/strategy.account_currency Signature: strategy.account_currency Returns the account currency of strategy equity and P&L: the strategy() currency, or the symbol's own currency when it is currency.NONE (the default) — e.g. "USDT" on BTCUSDT. TradingView-compatible spelling: strategy.account_currency; runs without warnings. Returns: string ``` strategy("Currency Label", overlay=true) drawTable("cur", 0, 0, strategy.account_currency, { position: "top_right" }) ``` ### alerta.strategy.default_entry_qty https://www.alertachart.com/alertascript/reference/builtins/strategy.default_entry_qty Signature: strategy.default_entry_qty(fill_price) Returns the default order quantity that strategy settings imply at a given fill price. TradingView-compatible spelling: strategy.default_entry_qty; runs without warnings. - fill_price: series int|float; required: true; default: not specified. Price used to estimate the default quantity. Returns: series float ``` strategy("Qty Preview", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=10) plot(strategy.default_entry_qty(close), { title: "Default qty", pane: "oscillator" }) ``` ### alerta.plot https://www.alertachart.com/alertascript/reference/builtins/plot Signature: plot(series, { title, color, linewidth, style, pane, offset, display }) Plots a series on the chart. TradingView-compatible spelling: plot; runs without warnings. - series: series float; required: true; default: not specified. Data to plot. - options: object; required: not specified; default: not specified. Plot styling and config: { title, color, style, linewidth, pane, offset, display } Returns: void ``` plot(sma(close, 20), { color: "#2962FF", linewidth: 2 }) ``` Aliases: line ### alerta.hline https://www.alertachart.com/alertascript/reference/builtins/hline Signature: hline(price, { title, color, linestyle, linewidth }) Plots a horizontal line at a fixed price level. TradingView-compatible spelling: hline; runs without warnings. - price: float; required: true; default: not specified. Price level. - options: object; required: not specified; default: not specified. Styling config. Returns: void ``` hline(100.0, { color: "gray", linestyle: "dashed" }) ``` Aliases: horizontal line ### alerta.plotshape https://www.alertachart.com/alertascript/reference/builtins/plotshape Signature: plotshape(series, { shape, location, color, text, size, transp }) Plots visual shapes on the chart based on a condition. TradingView-compatible spelling: plotshape; runs without warnings. - series: series bool; required: true; default: not specified. Where to draw: true, or a price with location.absolute; false/na draws nothing. - options: object; required: not specified; default: not specified. Styling config (style: "label_up"/"label_down"/"triangle_up", textcolor, transp, etc). Returns: void ``` const cross = crossover(sma(close, 10), sma(close, 20)) plotshape(cross, { shape: "triangle_up", location: "belowbar", color: "green" }) ``` Aliases: shape ### alerta.plotchar https://www.alertachart.com/alertascript/reference/builtins/plotchar Signature: plotchar(series, { char, location, color, text }) Plots a specific character on the chart based on a condition. TradingView-compatible spelling: plotchar; runs without warnings. - series: series bool; required: true; default: not specified. Where to draw: true, or a price with location.absolute; false/na draws nothing. - options: object; required: not specified; default: not specified. Styling config (char: string). Returns: void ``` const isBull = close > open plotchar(isBull, { char: "↑", location: "abovebar", color: "green" }) ``` Aliases: char ### alerta.plotarrow https://www.alertachart.com/alertascript/reference/builtins/plotarrow Signature: plotarrow(series, { colorup, colordown, minheight, maxheight, offset, pane }) | plotarrow(series, title, colorup, colordown, …) Plots up/down arrows based on signed series values. Pine's positional order after the series is `title, colorup, colordown, offset, minheight, maxheight, editable, show_last, display, force_overlay` — `title` comes FIRST, as it does across the whole plot family. TradingView-compatible spelling: plotarrow; runs without warnings. - series: series float; required: true; default: not specified. Positive values draw up arrows, negative values draw down arrows. - options: object; required: not specified; default: not specified. Arrow styling options, in Pine's positional order: title, colorup, colordown, offset, minheight, maxheight, editable, show_last, display, force_overlay. Returns: void ``` sig = close - open plotarrow(sig, { colorup: "#22c55e", colordown: "#ef4444" }) ``` Aliases: arrow ### alerta.plotcandle https://www.alertachart.com/alertascript/reference/builtins/plotcandle Signature: plotcandle(open, high, low, close, { color, wickcolor, bordercolor, offset, pane }) | plotcandle(open, high, low, close, title, color, wickcolor, …) Plots custom candlesticks from OHLC series. Pine's positional order after close is `title, color, wickcolor, editable, show_last, bordercolor, display, format, precision, force_overlay` — `title` comes first and `bordercolor` sits AFTER show_last, not next to wickcolor. TradingView-compatible spelling: plotcandle; runs without warnings. - open: series float; required: true; default: not specified. Open series. - high: series float; required: true; default: not specified. High series. - low: series float; required: true; default: not specified. Low series. - close: series float; required: true; default: not specified. Close series. - options: object; required: not specified; default: not specified. In Pine's positional order: title, color, wickcolor, editable, show_last, bordercolor, display, format, precision, force_overlay (plus `offset` and `pane`). Returns: void ``` plotcandle(open, high, low, close, { color: "#22c55e", wickcolor: "#16a34a", bordercolor: "#16a34a" }) ``` Aliases: candle ### alerta.plotbar https://www.alertachart.com/alertascript/reference/builtins/plotbar Signature: plotbar(open, high, low, close, { color, offset, pane }) | plotbar(open, high, low, close, title, color, …) Plots OHLC bars (ticks on open/close). Pine's positional order after close is `title, color, editable, show_last, display, format, precision, force_overlay`. TradingView-compatible spelling: plotbar; runs without warnings. - open: series float; required: true; default: not specified. Open series. - high: series float; required: true; default: not specified. High series. - low: series float; required: true; default: not specified. Low series. - close: series float; required: true; default: not specified. Close series. - options: object; required: not specified; default: not specified. In Pine's positional order: title, color, editable, show_last, display, format, precision, force_overlay (plus `offset` and `pane`). Returns: void ``` plotbar(open, high, low, close, { color: "#ef4444" }) ``` Aliases: bar ### alerta.bgcolor https://www.alertachart.com/alertascript/reference/builtins/bgcolor Signature: bgcolor(color, options) Changes the background color of the chart based on a condition. TradingView-compatible spelling: bgcolor; runs without warnings. - color: series string; required: true; default: not specified. Color string, null for no color. - options: object; required: not specified; default: not specified. { pane, title } Returns: void ``` const c = close > open ? "rgba(0, 255, 0, 0.05)" : "rgba(255, 0, 0, 0.05)" bgcolor(c, { pane: "oscillator" }) ``` Aliases: background ### alerta.barcolor https://www.alertachart.com/alertascript/reference/builtins/barcolor Signature: barcolor(color, { offset, editable }) Overrides candle/bar color on matching bars. TradingView-compatible spelling: barcolor; runs without warnings. - color: series string; required: true; default: not specified. Color string, null for default color. - options: object; required: not specified; default: not specified. Optional render options. Returns: void ``` isBull = close > open barcolor(isBull ? "#22c55e" : "#ef4444") ``` Aliases: candlecolor ### alerta.fill https://www.alertachart.com/alertascript/reference/builtins/fill Signature: fill(plot1_id, plot2_id, y1?, y2?, color1?, color2?, { color, title, fillgaps, top_color, bottom_color }?) Fills the area between two plots (or two hlines). Each plot may be given by the handle plot() returns (p1 = plot(…)), by a plot() call written inline — fill(plot(a), plot(b), color = …) — or by its title. Pine v6's gradient form — fill(p1, p2, top_value, bottom_value, top_color, bottom_color) — works positionally and by name. TradingView-compatible spelling: fill; runs without warnings. - plot1: plot | string; required: true; default: not specified. First plot: a plot handle, an inline plot() call or the plot's title. - plot2: plot | string; required: true; default: not specified. Second plot: a plot handle, an inline plot() call or the plot's title. - y1: series float; required: not specified; default: not specified. Optional top series for advanced fills. - y2: series float; required: not specified; default: not specified. Optional bottom series for advanced fills. - color1: string; required: not specified; default: not specified. Primary fill color. - color2: string; required: not specified; default: not specified. Secondary fill color. - options: object; required: not specified; default: not specified. Optional settings, accepted as named arguments too: color, title, fillgaps, display, editable, and Pine v6's gradient form top_value / bottom_value / top_color / bottom_color. Returns: void ``` basis = sma(close, 20) deviation = stdev(close, 20) upper = basis + deviation lower = basis - deviation plot(upper, { title: "up" }) plot(lower, { title: "down" }) fill("up", "down", { color: "rgba(0,0,255,0.1)" }) ``` Aliases: cloud ### alerta.linefill https://www.alertachart.com/alertascript/reference/builtins/linefill Signature: linefill(line1_id, line2_id, options) Fills the area between two line handles. TradingView-compatible spelling: linefill.new; runs without warnings. - line1_id: line handle; required: true; default: not specified. First line handle. - line2_id: line handle; required: true; default: not specified. Second line handle. - options: object; required: not specified; default: not specified. { color, title } object. Returns: linefill handle ``` line1 = line.new(bar_index - 10, low[10], bar_index, low) line2 = line.new(bar_index - 10, high[10], bar_index, high) lf = linefill(line1, line2, { color: "rgba(239,68,68,0.15)" }) ``` Aliases: linefill.new ### alerta.drawLabel https://www.alertachart.com/alertascript/reference/builtins/drawlabel Signature: drawLabel(id, cond, x, y, text, options) Draws a persistent label element on the chart at specific coordinates. TradingView-compatible spelling: label.new; runs without warnings. - id: string; required: true; default: not specified. Unique ID per element (use mode "append" or "replace"). - cond: series bool; required: true; default: not specified. Condition to draw the label on current bar. - x: int; required: true; default: not specified. Bar index (e.g. bar_index). - y: float; required: true; default: not specified. Price level. - text: string; required: true; default: not specified. Text to display in the label. - options: object; required: not specified; default: not specified. { location, style, color, textColor, size, mode } Returns: void ``` drawLabel("LL", true, bar_index, low, "LL", { style: "label_up", color: "transparent", textColor: "white", mode: "append" }) ``` Legacy alias: prefer object API (`label.new` + `label.set_*`) for Pine parity. Aliases: label.new, label ### alerta.drawBox https://www.alertachart.com/alertascript/reference/builtins/drawbox Signature: drawBox(id, cond, x1, y1, x2, y2, options) Draws a persistent rectangle/zone on the chart. Ideal for FVG/OB. TradingView-compatible spelling: box.new; runs without warnings. - id: string; required: true; default: not specified. Unique ID. - cond: series bool; required: true; default: not specified. Condition. - x1: int; required: true; default: not specified. Left bar_index. - y1: float; required: true; default: not specified. Top price. - x2: int; required: true; default: not specified. Right bar_index. - y2: float; required: true; default: not specified. Bottom price. - options: object; required: not specified; default: not specified. { bgColor, borderColor, extend, isMitigated, mode, text } Returns: void ``` isOB = bar_index > 10 top = high bot = low drawBox("ob", isOB, bar_index - 5, top, bar_index, bot, { extend: "right", mode: "append" }) ``` Legacy alias: prefer object API (`box.new` + `box.set_*`) for Pine parity. Aliases: box.new, box, zone ### alerta.drawLine https://www.alertachart.com/alertascript/reference/builtins/drawline Signature: drawLine(id, cond, x1, y1, x2, y2, options) Draws a persistent trendline or simple line between two points. TradingView-compatible spelling: line.new; runs without warnings. - id: string; required: true; default: not specified. Unique ID. - cond: series bool; required: true; default: not specified. Condition. - x1: int; required: true; default: not specified. Left bar_index. - y1: float; required: true; default: not specified. Start price. - x2: int; required: true; default: not specified. Right bar_index. - y2: float; required: true; default: not specified. End price. - options: object; required: not specified; default: not specified. { color, lineWidth, style, extend, mode } Returns: void ``` isBOS = bar_index > 10 lastPivotX = bar_index - 5 lastPivotY = high[5] drawLine("BOS_" + bar_index, isBOS, lastPivotX, lastPivotY, bar_index, lastPivotY, { color: "gray", mode: "append" }) ``` Legacy alias: prefer object API (`line.new` + `line.set_*`) for Pine parity. Aliases: line.new, trendline ### alerta.drawTable https://www.alertachart.com/alertascript/reference/builtins/drawtable Signature: drawTable(id, row, col, text, options) Draws a persistent table cell for creating HUDs and dashboards. TradingView-compatible spelling: table.cell; runs without warnings. - id: string; required: true; default: not specified. Table ID. - row: int; required: true; default: not specified. Row index (0-based). - col: int; required: true; default: not specified. Column index (0-based). - text: string; required: true; default: not specified. Text/Value to display. - options: object; required: not specified; default: not specified. { position, bgColor, textColor, textAlign, size, fontWeight } Returns: void ``` drawTable("hud", 0, 0, "RSI: " + fixed(rsi(close, 14), 2), { position: "top_right", bgColor: "#1e222d" }) ``` Legacy alias: prefer object API (`table.new` + `table.cell`) for Pine parity. Aliases: table.new, table.cell, dashboard ### alerta.linefill.new https://www.alertachart.com/alertascript/reference/builtins/linefill.new Signature: linefill.new(line1, line2, color) Creates a linefill handle between two line handles. TradingView-compatible spelling: linefill.new; runs without warnings. - line1: line handle; required: true; default: not specified. First line handle. - line2: line handle; required: true; default: not specified. Second line handle. - color: string; required: not specified; default: not specified. Fill color. Returns: linefill handle ``` l1 = line.new(bar_index - 10, low[10], bar_index, low) l2 = line.new(bar_index - 10, high[10], bar_index, high) lf = linefill.new(l1, l2, "rgba(239,68,68,0.15)") ``` ### alerta.linefill.delete https://www.alertachart.com/alertascript/reference/builtins/linefill.delete Signature: linefill.delete(id) Deletes a linefill handle. TradingView-compatible spelling: linefill.delete; runs without warnings. - id: linefill handle; required: true; default: not specified. Linefill handle to delete. Returns: void ``` l1 = line.new(bar_index - 10, low[10], bar_index, low) l2 = line.new(bar_index - 10, high[10], bar_index, high) lf = linefill.new(l1, l2, "rgba(239,68,68,0.15)") linefill.delete(lf) ``` ### alerta.linefill.get_line1 https://www.alertachart.com/alertascript/reference/builtins/linefill.get_line1 Signature: linefill.get_line1(id) Returns the first line handle used by the linefill. TradingView-compatible spelling: linefill.get_line1; runs without warnings. - id: linefill handle; required: true; default: not specified. Linefill handle. Returns: line handle ``` l1 = line.new(bar_index - 10, low[10], bar_index, low) l2 = line.new(bar_index - 10, high[10], bar_index, high) lf = linefill.new(l1, l2, "rgba(239,68,68,0.15)") a = linefill.get_line1(lf) ``` ### alerta.linefill.get_line2 https://www.alertachart.com/alertascript/reference/builtins/linefill.get_line2 Signature: linefill.get_line2(id) Returns the second line handle used by the linefill. TradingView-compatible spelling: linefill.get_line2; runs without warnings. - id: linefill handle; required: true; default: not specified. Linefill handle. Returns: line handle ``` l1 = line.new(bar_index - 10, low[10], bar_index, low) l2 = line.new(bar_index - 10, high[10], bar_index, high) lf = linefill.new(l1, l2, "rgba(239,68,68,0.15)") b = linefill.get_line2(lf) ``` ### alerta.linefill.set_color https://www.alertachart.com/alertascript/reference/builtins/linefill.set_color Signature: linefill.set_color(id, color) Updates linefill color. TradingView-compatible spelling: linefill.set_color; runs without warnings. - id: linefill handle; required: true; default: not specified. Linefill handle. - color: string; required: true; default: not specified. New fill color. Returns: void ``` l1 = line.new(bar_index - 10, low[10], bar_index, low) l2 = line.new(bar_index - 10, high[10], bar_index, high) lf = linefill.new(l1, l2, "rgba(239,68,68,0.15)") linefill.set_color(lf, "rgba(34,197,94,0.15)") ``` ### alerta.line.new https://www.alertachart.com/alertascript/reference/builtins/line.new Signature: line.new(x1, y1, x2, y2, options) | line.new(x1, y1, x2, y2, color=, style=, width=, extend=) | line.new(x1, y1, x2, y2, xloc, extend, color, style, width) Creates a line object and returns its handle. Accepts the Alerta-canonical `options={...}` object form, the Pine v5/v6 direct-named-args dialect (`line.new(x1, y1, x2, y2, color=color.green, style=line.style_dashed, width=2, extend=extend.right)`), and Pine's fully POSITIONAL form, whose optional order is `xloc, extend, color, style, width, force_overlay`. All three forms produce identical output. TradingView-compatible spelling: line.new; runs without warnings. - x1: int; required: true; default: not specified. First X coordinate (bar index). - y1: float; required: true; default: not specified. First Y coordinate (price). - x2: int; required: true; default: not specified. Second X coordinate (bar index). - y2: float; required: true; default: not specified. Second Y coordinate (price). - options: object; required: not specified; default: not specified. Optional style settings, in Pine's positional order: xloc, extend, color, style, width, force_overlay. Equivalent to the direct named-arg form. Returns: line handle ``` ln = line.new(bar_index - 5, low, bar_index, high, color=color.green, style=line.style_dashed, width=2) ``` ### alerta.line.copy https://www.alertachart.com/alertascript/reference/builtins/line.copy Signature: line.copy(id) Creates a duplicate of an existing line and returns the new handle. TradingView-compatible spelling: line.copy; runs without warnings. - id: line handle; required: true; default: not specified. Source line handle. Returns: line handle ``` ln = line.new(bar_index - 5, low, bar_index, high) ln2 = line.copy(ln) line.set_color(ln2, "#f59e0b") ``` ### alerta.line.set_xy1 https://www.alertachart.com/alertascript/reference/builtins/line.set_xy1 Signature: line.set_xy1(id, x, y) Updates line start point (x1, y1) together. TradingView-compatible spelling: line.set_xy1; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - x: int; required: true; default: not specified. New X1 coordinate. - y: float; required: true; default: not specified. New Y1 coordinate. Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) line.set_xy1(ln, bar_index - 10, low[1]) ``` ### alerta.line.set_xy2 https://www.alertachart.com/alertascript/reference/builtins/line.set_xy2 Signature: line.set_xy2(id, x, y) Updates line end point (x2, y2) together. TradingView-compatible spelling: line.set_xy2; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - x: int; required: true; default: not specified. New X2 coordinate. - y: float; required: true; default: not specified. New Y2 coordinate. Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) line.set_xy2(ln, bar_index, high) ``` ### alerta.line.set_first_point https://www.alertachart.com/alertascript/reference/builtins/line.set_first_point Signature: line.set_first_point(id, point) Updates the line start point from a `chart.point` object. TradingView-compatible spelling: line.set_first_point; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - point: chart.point; required: true; default: not specified. New first point. Returns: void ``` var ln = line.new(bar_index - 5, low, bar_index, high) if barstate.islast p = chart.point.from_index(bar_index - 10, low[1]) line.set_first_point(ln, p) ``` ### alerta.line.set_second_point https://www.alertachart.com/alertascript/reference/builtins/line.set_second_point Signature: line.set_second_point(id, point) Updates the line end point from a `chart.point` object. TradingView-compatible spelling: line.set_second_point; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - point: chart.point; required: true; default: not specified. New second point. Returns: void ``` var ln = line.new(bar_index - 5, low, bar_index, high) if barstate.islast p = chart.point.from_index(bar_index + 1, high) line.set_second_point(ln, p) ``` ### alerta.line.set_xloc https://www.alertachart.com/alertascript/reference/builtins/line.set_xloc Signature: line.set_xloc(id, x1, x2, xloc) Sets both x-coordinates of the line and the x-location they are read in (bar index or bar time) at once. TradingView-compatible spelling: line.set_xloc; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - x1: series int; required: true; default: not specified. New x of the first point, in the given xloc. - x2: series int; required: true; default: not specified. New x of the second point, in the given xloc. - xloc: series string; required: true; default: not specified. xloc.bar_index | xloc.bar_time Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) if barstate.islast line.set_xloc(ln, time[5], time, xloc.bar_time) ``` ### alerta.line.set_x1 https://www.alertachart.com/alertascript/reference/builtins/line.set_x1 Signature: line.set_x1(id, x) Updates line start X coordinate. TradingView-compatible spelling: line.set_x1; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - x: int; required: true; default: not specified. New X1 value. Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) line.set_x1(ln, bar_index - 10) ``` ### alerta.line.set_y1 https://www.alertachart.com/alertascript/reference/builtins/line.set_y1 Signature: line.set_y1(id, y) Updates line start Y coordinate. TradingView-compatible spelling: line.set_y1; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - y: float; required: true; default: not specified. New Y1 value. Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) line.set_y1(ln, low) ``` ### alerta.line.set_x2 https://www.alertachart.com/alertascript/reference/builtins/line.set_x2 Signature: line.set_x2(id, x) Updates line end X coordinate. TradingView-compatible spelling: line.set_x2; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - x: int; required: true; default: not specified. New X2 value. Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) line.set_x2(ln, bar_index) ``` ### alerta.line.set_y2 https://www.alertachart.com/alertascript/reference/builtins/line.set_y2 Signature: line.set_y2(id, y) Updates line end Y coordinate. TradingView-compatible spelling: line.set_y2; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - y: float; required: true; default: not specified. New Y2 value. Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) line.set_y2(ln, high) ``` ### alerta.line.set_color https://www.alertachart.com/alertascript/reference/builtins/line.set_color Signature: line.set_color(id, color) Updates line color. TradingView-compatible spelling: line.set_color; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - color: string; required: true; default: not specified. New color value. Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) line.set_color(ln, "#22c55e") ``` ### alerta.line.set_width https://www.alertachart.com/alertascript/reference/builtins/line.set_width Signature: line.set_width(id, width) Updates line width. TradingView-compatible spelling: line.set_width; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - width: int; required: true; default: not specified. New width value. Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) line.set_width(ln, 2) ``` ### alerta.line.set_extend https://www.alertachart.com/alertascript/reference/builtins/line.set_extend Signature: line.set_extend(id, extend) Updates line extend mode. TradingView-compatible spelling: line.set_extend; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - extend: string; required: true; default: not specified. none | left | right | both Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) line.set_extend(ln, "right") ``` ### alerta.line.set_style https://www.alertachart.com/alertascript/reference/builtins/line.set_style Signature: line.set_style(id, style) Updates line style (solid, dashed, dotted, etc.). TradingView-compatible spelling: line.set_style; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - style: string; required: true; default: not specified. Line style token. Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) line.set_style(ln, "dashed") ``` ### alerta.line.set_zindex https://www.alertachart.com/alertascript/reference/builtins/line.set_zindex Signature: line.set_zindex(line_id, zindex) Updates line z-index ordering. TradingView-compatible spelling: line.set_zindex; runs without warnings. - line_id: line handle; required: true; default: not specified. Target line handle. - zindex: int; required: true; default: not specified. New z-index value. Returns: void ``` ln = line.new(bar_index - 5, low, bar_index, high) line.set_zindex(ln, 10) ``` ### alerta.line.delete https://www.alertachart.com/alertascript/reference/builtins/line.delete Signature: line.delete(id) Deletes a line object. TradingView-compatible spelling: line.delete; runs without warnings. - id: line handle; required: true; default: not specified. Line handle to delete. Returns: void ``` indicator("line.delete", overlay=false) var object = line.new(bar_index, low, bar_index + 5, high) if bar_index == 10 line.delete(object) plot(array.size(line.all), "line objects remaining") ``` ### alerta.line.get_x1 https://www.alertachart.com/alertascript/reference/builtins/line.get_x1 Signature: line.get_x1(id) Returns line start X coordinate. TradingView-compatible spelling: line.get_x1; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. Returns: int ``` ln = line.new(bar_index - 5, low, bar_index, high) x1 = line.get_x1(ln) plot(x1, { pane: "oscillator" }) ``` ### alerta.line.get_y1 https://www.alertachart.com/alertascript/reference/builtins/line.get_y1 Signature: line.get_y1(id) Returns line start Y coordinate. TradingView-compatible spelling: line.get_y1; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. Returns: float ``` ln = line.new(bar_index - 5, low, bar_index, high) y1 = line.get_y1(ln) plot(y1) ``` ### alerta.line.get_x2 https://www.alertachart.com/alertascript/reference/builtins/line.get_x2 Signature: line.get_x2(id) Returns line end X coordinate. TradingView-compatible spelling: line.get_x2; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. Returns: int ``` ln = line.new(bar_index - 5, low, bar_index, high) x2 = line.get_x2(ln) plot(x2, { pane: "oscillator" }) ``` ### alerta.line.get_y2 https://www.alertachart.com/alertascript/reference/builtins/line.get_y2 Signature: line.get_y2(id) Returns line end Y coordinate. TradingView-compatible spelling: line.get_y2; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. Returns: float ``` ln = line.new(bar_index - 5, low, bar_index, high) y2 = line.get_y2(ln) plot(y2) ``` ### alerta.line.get_price https://www.alertachart.com/alertascript/reference/builtins/line.get_price Signature: line.get_price(id, x) Returns interpolated price of a line at a target bar index. TradingView-compatible spelling: line.get_price; runs without warnings. - id: line handle; required: true; default: not specified. Target line handle. - x: int; required: true; default: not specified. Target bar index. Returns: float ``` ln = line.new(bar_index - 5, low, bar_index, high) p = line.get_price(ln, bar_index) plot(p) ``` ### alerta.box.new https://www.alertachart.com/alertascript/reference/builtins/box.new Signature: box.new(left, top, right, bottom, options) | box.new(left, top, right, bottom, bgcolor=, border_color=, border_width=) | box.new(left, top, right, bottom, border_color, border_width, border_style, extend, xloc, bgcolor, text, …) Creates a box object and returns its handle. Accepts the Alerta-canonical `options={...}` object form, the Pine v5/v6 direct-named-args dialect (`box.new(left, top, right, bottom, bgcolor=, border_color=, border_width=, extend=)`), and Pine's fully POSITIONAL form, whose optional order is `border_color, border_width, border_style, extend, xloc, bgcolor, text, text_size, text_color, text_halign, text_valign, text_wrap, text_font_family, force_overlay`. Note that `bgcolor` is the SIXTH optional, not the third. Snake-case aliases (`bg_color`, `border_color`, `border_style`) auto-map to canonical camelCase. All three forms produce identical output. TradingView-compatible spelling: box.new; runs without warnings. - left: int; required: true; default: not specified. Left bar index. - top: float; required: true; default: not specified. Top price. - right: int; required: true; default: not specified. Right bar index. - bottom: float; required: true; default: not specified. Bottom price. - options: object; required: not specified; default: not specified. Optional style settings, in Pine's positional order: border_color, border_width, border_style, extend, xloc, bgcolor / bg_color, text, text_size, text_color, text_halign, text_valign, text_wrap, text_font_family, force_overlay. Equivalent to the direct named-arg form. Returns: box handle ``` bx = box.new(bar_index - 5, high, bar_index, low, bgcolor=color.new(color.green, 80), border_color=color.green) ``` ### alerta.box.copy https://www.alertachart.com/alertascript/reference/builtins/box.copy Signature: box.copy(id) Creates a duplicate of an existing box and returns the new handle. TradingView-compatible spelling: box.copy; runs without warnings. - id: box handle; required: true; default: not specified. Source box handle. Returns: box handle ``` bx = box.new(bar_index - 5, high, bar_index, low) bx2 = box.copy(bx) box.set_border_color(bx2, "#f59e0b") ``` ### alerta.box.get_left https://www.alertachart.com/alertascript/reference/builtins/box.get_left Signature: box.get_left(id) Returns box left coordinate. TradingView-compatible spelling: box.get_left; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. Returns: int ``` bx = box.new(bar_index - 5, high, bar_index, low) l = box.get_left(bx) ``` ### alerta.box.get_right https://www.alertachart.com/alertascript/reference/builtins/box.get_right Signature: box.get_right(id) Returns box right coordinate. TradingView-compatible spelling: box.get_right; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. Returns: int ``` bx = box.new(bar_index - 5, high, bar_index, low) r = box.get_right(bx) ``` ### alerta.box.get_top https://www.alertachart.com/alertascript/reference/builtins/box.get_top Signature: box.get_top(id) Returns box top price. TradingView-compatible spelling: box.get_top; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. Returns: float ``` bx = box.new(bar_index - 5, high, bar_index, low) t = box.get_top(bx) ``` ### alerta.box.get_bottom https://www.alertachart.com/alertascript/reference/builtins/box.get_bottom Signature: box.get_bottom(id) Returns box bottom price. TradingView-compatible spelling: box.get_bottom; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. Returns: float ``` bx = box.new(bar_index - 5, high, bar_index, low) b = box.get_bottom(bx) ``` ### alerta.box.set_left https://www.alertachart.com/alertascript/reference/builtins/box.set_left Signature: box.set_left(id, left) Updates box left coordinate. TradingView-compatible spelling: box.set_left; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - left: int; required: true; default: not specified. New left coordinate. Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_left(bx, bar_index - 10) ``` ### alerta.box.set_top https://www.alertachart.com/alertascript/reference/builtins/box.set_top Signature: box.set_top(id, top) Updates box top price. TradingView-compatible spelling: box.set_top; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - top: float; required: true; default: not specified. New top value. Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_top(bx, high) ``` ### alerta.box.set_right https://www.alertachart.com/alertascript/reference/builtins/box.set_right Signature: box.set_right(id, right) Updates box right coordinate. TradingView-compatible spelling: box.set_right; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - right: int; required: true; default: not specified. New right coordinate. Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_right(bx, bar_index) ``` ### alerta.box.set_bottom https://www.alertachart.com/alertascript/reference/builtins/box.set_bottom Signature: box.set_bottom(id, bottom) Updates box bottom price. TradingView-compatible spelling: box.set_bottom; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - bottom: float; required: true; default: not specified. New bottom value. Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_bottom(bx, low) ``` ### alerta.box.set_border_color https://www.alertachart.com/alertascript/reference/builtins/box.set_border_color Signature: box.set_border_color(id, color) Updates box border color. TradingView-compatible spelling: box.set_border_color; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - color: string; required: true; default: not specified. New border color. Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_border_color(bx, "#ef4444") ``` ### alerta.box.set_border_style https://www.alertachart.com/alertascript/reference/builtins/box.set_border_style Signature: box.set_border_style(id, style) Updates box border style token. TradingView-compatible spelling: box.set_border_style; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - style: string; required: true; default: not specified. solid | dashed | dotted Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_border_style(bx, "dashed") ``` ### alerta.box.set_border_width https://www.alertachart.com/alertascript/reference/builtins/box.set_border_width Signature: box.set_border_width(id, width) Updates box border width. TradingView-compatible spelling: box.set_border_width; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - width: int; required: true; default: not specified. New border width. Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_border_width(bx, 2) ``` ### alerta.box.set_bgcolor https://www.alertachart.com/alertascript/reference/builtins/box.set_bgcolor Signature: box.set_bgcolor(id, color) Updates box background color. TradingView-compatible spelling: box.set_bgcolor; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - color: string; required: true; default: not specified. New background color. Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_bgcolor(bx, "rgba(16,185,129,0.15)") ``` ### alerta.box.set_extend https://www.alertachart.com/alertascript/reference/builtins/box.set_extend Signature: box.set_extend(id, extend) Updates box extend mode. TradingView-compatible spelling: box.set_extend; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - extend: string; required: true; default: not specified. none | left | right | both Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_extend(bx, "right") ``` ### alerta.box.set_xloc https://www.alertachart.com/alertascript/reference/builtins/box.set_xloc Signature: box.set_xloc(id, left, right, xloc) Updates box left/right coordinates and X-location mode together. TradingView-compatible spelling: box.set_xloc; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - left: int; required: true; default: not specified. New left coordinate. - right: int; required: true; default: not specified. New right coordinate. - xloc: string; required: true; default: not specified. bar_index | bar_time Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_xloc(bx, bar_index - 10, bar_index, xloc.bar_index) ``` ### alerta.box.set_text https://www.alertachart.com/alertascript/reference/builtins/box.set_text Signature: box.set_text(id, text) Updates text shown inside the box. TradingView-compatible spelling: box.set_text; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - text: string; required: true; default: not specified. Text value. Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_text(bx, "OB") ``` ### alerta.box.set_text_color https://www.alertachart.com/alertascript/reference/builtins/box.set_text_color Signature: box.set_text_color(id, text_color) Updates box text color. TradingView-compatible spelling: box.set_text_color; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - text_color: string; required: true; default: not specified. Text color. Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_text_color(bx, "#ffffff") ``` ### alerta.box.set_text_halign https://www.alertachart.com/alertascript/reference/builtins/box.set_text_halign Signature: box.set_text_halign(id, text_halign) Updates horizontal alignment of box text. TradingView-compatible spelling: box.set_text_halign; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - text_halign: string; required: true; default: not specified. left | center | right Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_text_halign(bx, "center") ``` ### alerta.box.set_text_valign https://www.alertachart.com/alertascript/reference/builtins/box.set_text_valign Signature: box.set_text_valign(id, text_valign) Updates vertical alignment of box text. TradingView-compatible spelling: box.set_text_valign; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - text_valign: string; required: true; default: not specified. top | center | bottom Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_text_valign(bx, "center") ``` ### alerta.box.set_text_size https://www.alertachart.com/alertascript/reference/builtins/box.set_text_size Signature: box.set_text_size(id, text_size) Updates size of box text. TradingView-compatible spelling: box.set_text_size; runs without warnings. - id: box handle; required: true; default: not specified. Target box handle. - text_size: string; required: true; default: not specified. tiny | small | normal | large | huge Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_text_size(bx, "small") ``` ### alerta.box.set_zindex https://www.alertachart.com/alertascript/reference/builtins/box.set_zindex Signature: box.set_zindex(box_id, zindex) Updates box z-index ordering. TradingView-compatible spelling: box.set_zindex; runs without warnings. - box_id: box handle; required: true; default: not specified. Target box handle. - zindex: int; required: true; default: not specified. New z-index value. Returns: void ``` bx = box.new(bar_index - 5, high, bar_index, low) box.set_zindex(bx, 5) ``` ### alerta.box.delete https://www.alertachart.com/alertascript/reference/builtins/box.delete Signature: box.delete(id) Deletes a box object. TradingView-compatible spelling: box.delete; runs without warnings. - id: box handle; required: true; default: not specified. Box handle to delete. Returns: void ``` indicator("box.delete", overlay=false) var object = box.new(bar_index, high, bar_index + 5, low) if bar_index == 10 box.delete(object) plot(array.size(box.all), "box objects remaining") ``` ### alerta.label.new https://www.alertachart.com/alertascript/reference/builtins/label.new Signature: label.new(x, y, text, options) | label.new(x, y, text, color=, textcolor=, style=, size=) | label.new(x, y, text, xloc, yloc, color, style, textcolor, size, textalign, tooltip) Creates a label object and returns its handle. Accepts the Alerta-canonical `options={...}` object form, the Pine v5/v6 direct-named-args dialect (`label.new(x, y, text, color=, textcolor=, style=, size=, tooltip=)`), and Pine's fully POSITIONAL form, whose optional order is `xloc, yloc, color, style, textcolor, size, textalign, tooltip, text_font_family, force_overlay` — the order a wrapper function passes its parameters through. Snake-case `text_color` / `text_font_family` auto-map to `textColor` / `textFontFamily`. All three forms produce identical output. TradingView-compatible spelling: label.new; runs without warnings. - x: int; required: true; default: not specified. Bar index. - y: float; required: true; default: not specified. Price level. - text: string; required: false; default: not specified. Label text. Optional; defaults to empty string when omitted. Pine v5/v6 allows label.new(x, y, color=...) without text. - options: object; required: not specified; default: not specified. Optional style settings, in Pine's positional order: xloc, yloc, color, style, textcolor / text_color, size, textalign / textAlign / text_halign, tooltip, text_font_family, text_formatting, force_overlay. Equivalent to the direct named-arg form. Returns: label handle ``` lb = label.new(bar_index, high, "BoS", style=label.style_label_down, color=color.green, textcolor=color.white) ``` ### alerta.label.copy https://www.alertachart.com/alertascript/reference/builtins/label.copy Signature: label.copy(id) Creates a duplicate of an existing label and returns the new handle. TradingView-compatible spelling: label.copy; runs without warnings. - id: label handle; required: true; default: not specified. Source label handle. Returns: label handle ``` lb = label.new(bar_index, close, "Signal") lb2 = label.copy(lb) label.set_text(lb2, "Copy") ``` ### alerta.label.get_x https://www.alertachart.com/alertascript/reference/builtins/label.get_x Signature: label.get_x(id) Returns label X coordinate. TradingView-compatible spelling: label.get_x; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. Returns: int ``` lb = label.new(bar_index, close, "Signal") x = label.get_x(lb) ``` ### alerta.label.get_y https://www.alertachart.com/alertascript/reference/builtins/label.get_y Signature: label.get_y(id) Returns label Y coordinate. TradingView-compatible spelling: label.get_y; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. Returns: float ``` lb = label.new(bar_index, close, "Signal") y = label.get_y(lb) ``` ### alerta.label.get_text https://www.alertachart.com/alertascript/reference/builtins/label.get_text Signature: label.get_text(id) Returns label text. TradingView-compatible spelling: label.get_text; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. Returns: string ``` lb = label.new(bar_index, close, "Signal") t = label.get_text(lb) ``` ### alerta.label.set_xy https://www.alertachart.com/alertascript/reference/builtins/label.set_xy Signature: label.set_xy(id, x, y) Pine v6: set both x and y in a single call. TradingView-compatible spelling: label.set_xy; runs without warnings. - id: label; required: true; default: not specified. Label handle. - x: int; required: true; default: not specified. New x value. - y: float; required: true; default: not specified. New y value. Returns: void ``` lbl = label.new(bar_index, high, "x") label.set_xy(lbl, bar_index, close) ``` Aliases: alerta.label.set_xy Alternate form: label.set_xy(id, x, y) Updates label X and Y coordinates together. Returns: void - id: label handle. Target label handle. - x: int. New X coordinate. - y: float. New Y coordinate. ``` lb = label.new(bar_index, close, "Signal") label.set_xy(lb, bar_index, high) ``` ### alerta.label.set_xloc https://www.alertachart.com/alertascript/reference/builtins/label.set_xloc Signature: label.set_xloc(id, x, xloc) Pine v6: set the label's x-coordinate and switch xloc (bar_index | bar_time) at once. TradingView-compatible spelling: label.set_xloc; runs without warnings. - id: label; required: true; default: not specified. Label handle. - x: int; required: true; default: not specified. New x value. - xloc: string; required: true; default: not specified. xloc.bar_index | xloc.bar_time. Returns: void ``` lbl = label.new(bar_index, high, "x") label.set_xloc(lbl, time, xloc.bar_time) ``` Aliases: alerta.label.set_xloc Alternate form: label.set_xloc(id, x, xloc) Updates label X-location mode. Pine v6 can also update X and xloc together. Returns: void - id: label handle. Target label handle. - x: int. New X coordinate. - xloc: string. bar_index | bar_time ``` lb = label.new(bar_index, close, "Signal") label.set_xloc(lb, bar_index, xloc.bar_index) ``` ### alerta.label.set_textalign https://www.alertachart.com/alertascript/reference/builtins/label.set_textalign Signature: label.set_textalign(id, textalign) Updates label text alignment. TradingView-compatible spelling: label.set_textalign; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. - textalign: string; required: true; default: not specified. left | center | right Returns: void ``` lb = label.new(bar_index, close, "Signal") label.set_textalign(lb, "center") ``` ### alerta.label.set_tooltip https://www.alertachart.com/alertascript/reference/builtins/label.set_tooltip Signature: label.set_tooltip(id, tooltip) Updates label tooltip content. TradingView-compatible spelling: label.set_tooltip; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. - tooltip: string; required: true; default: not specified. Tooltip text. Returns: void ``` lb = label.new(bar_index, close, "Signal") label.set_tooltip(lb, "Extra context") ``` ### alerta.polyline.new https://www.alertachart.com/alertascript/reference/builtins/polyline.new Signature: polyline.new(points, curved, closed, xloc, line_color, fill_color, line_style, line_width, force_overlay) Creates a polyline through an array of chart.point values. curved=true draws smooth segments, closed=true connects the last point back to the first (fill_color fills the enclosed area). TradingView-compatible spelling: polyline.new; runs without warnings. - points: array; required: true; default: not specified. Points the polyline passes through, in order. - curved: bool; required: not specified; default: false. Draw smooth curved segments between points. - closed: bool; required: not specified; default: false. Connect the last point back to the first. - xloc: string; required: not specified; default: xloc.bar_index. xloc.bar_index or xloc.bar_time. - line_color: color; required: not specified; default: not specified. Stroke color. - fill_color: color; required: not specified; default: not specified. Fill color for closed polylines. - line_style: string; required: not specified; default: line.style_solid. solid / dashed / dotted. - line_width: int; required: not specified; default: 1. Stroke width. - force_overlay: bool; required: not specified; default: false. Pine v6: draw on the main (price) pane even from an oscillator script. Returns: polyline handle ``` pts = array.new() array.push(pts, chart.point.from_index(bar_index - 4, low)) array.push(pts, chart.point.from_index(bar_index, high)) pl = polyline.new(pts, curved=true) ``` ### alerta.polyline.push https://www.alertachart.com/alertascript/reference/builtins/polyline.push Signature: polyline.push(polyline_id, x, y) Appends a point to an existing polyline. TradingView-compatible spelling: polyline.push; runs without warnings. - polyline_id: polyline handle; required: true; default: not specified. Target polyline handle. - x: int; required: true; default: not specified. Bar index for point. - y: float; required: true; default: not specified. Price value for point. Returns: void ``` indicator("polyline.push", overlay=true) if barstate.islast points = array.from(chart.point.from_time(time[8], close[8]), chart.point.from_time(time[4], close[4]), chart.point.from_time(time[1], close[1])) p = polyline.new(points, xloc=xloc.bar_time) polyline.push(p, time, close) ``` ### alerta.polyline.delete https://www.alertachart.com/alertascript/reference/builtins/polyline.delete Signature: polyline.delete(id) Deletes a polyline object. TradingView-compatible spelling: polyline.delete; runs without warnings. - id: polyline handle; required: true; default: not specified. Polyline handle to delete. Returns: void ``` indicator("polyline.delete", overlay=false) var object = polyline.new(array.from(chart.point.from_index(bar_index, low), chart.point.from_index(bar_index + 5, high))) if bar_index == 10 polyline.delete(object) plot(array.size(polyline.all), "polyline objects remaining") ``` ### alerta.label.set_x https://www.alertachart.com/alertascript/reference/builtins/label.set_x Signature: label.set_x(id, x) Updates label X coordinate. TradingView-compatible spelling: label.set_x; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. - x: int; required: true; default: not specified. New X coordinate. Returns: void ``` lb = label.new(bar_index, close, "Signal") label.set_x(lb, bar_index) ``` ### alerta.label.set_y https://www.alertachart.com/alertascript/reference/builtins/label.set_y Signature: label.set_y(id, y) Updates label Y coordinate. TradingView-compatible spelling: label.set_y; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. - y: float; required: true; default: not specified. New Y coordinate. Returns: void ``` lb = label.new(bar_index, close, "Signal") label.set_y(lb, close) ``` ### alerta.label.set_text https://www.alertachart.com/alertascript/reference/builtins/label.set_text Signature: label.set_text(id, text) Updates label text. TradingView-compatible spelling: label.set_text; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. - text: string; required: true; default: not specified. New text value. Returns: void ``` lb = label.new(bar_index, close, "Signal") label.set_text(lb, "Updated") ``` ### alerta.label.set_zindex https://www.alertachart.com/alertascript/reference/builtins/label.set_zindex Signature: label.set_zindex(label_id, zindex) Updates label z-index ordering. TradingView-compatible spelling: label.set_zindex; runs without warnings. - label_id: label handle; required: true; default: not specified. Target label handle. - zindex: int; required: true; default: not specified. New z-index value. Returns: void ``` lb = label.new(bar_index, close, "Signal") label.set_zindex(lb, 12) ``` ### alerta.label.set_color https://www.alertachart.com/alertascript/reference/builtins/label.set_color Signature: label.set_color(id, color) Updates label background color. TradingView-compatible spelling: label.set_color; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. - color: string; required: true; default: not specified. New color value. Returns: void ``` lb = label.new(bar_index, close, "Signal") label.set_color(lb, "#ef4444") ``` ### alerta.label.set_textcolor https://www.alertachart.com/alertascript/reference/builtins/label.set_textcolor Signature: label.set_textcolor(id, textcolor) Updates label text color. TradingView-compatible spelling: label.set_textcolor; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. - textcolor: string; required: true; default: not specified. New text color. Returns: void ``` lb = label.new(bar_index, close, "Signal") label.set_textcolor(lb, "#ffffff") ``` ### alerta.label.set_size https://www.alertachart.com/alertascript/reference/builtins/label.set_size Signature: label.set_size(id, size) Updates label size. TradingView-compatible spelling: label.set_size; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. - size: string; required: true; default: not specified. Size token (small, normal, large). Returns: void ``` lb = label.new(bar_index, close, "Signal") label.set_size(lb, "small") ``` ### alerta.label.set_style https://www.alertachart.com/alertascript/reference/builtins/label.set_style Signature: label.set_style(id, style) Updates label style token. TradingView-compatible spelling: label.set_style; runs without warnings. - id: label handle; required: true; default: not specified. Target label handle. - style: string; required: true; default: not specified. Style token (label_up, label_down, none). Returns: void ``` lb = label.new(bar_index, close, "Signal") label.set_style(lb, "label_up") ``` ### alerta.label.set_location https://www.alertachart.com/alertascript/reference/builtins/label.set_location Signature: label.set_location(label_id, location) Updates label location mode. TradingView-compatible spelling: label.set_location; runs without warnings. - label_id: label handle; required: true; default: not specified. Target label handle. - location: string; required: true; default: not specified. Location token (abovebar, belowbar, absolute). Returns: void ``` lb = label.new(bar_index, close, "Signal") label.set_location(lb, "abovebar") ``` ### alerta.label.delete https://www.alertachart.com/alertascript/reference/builtins/label.delete Signature: label.delete(id) Deletes a label object. TradingView-compatible spelling: label.delete; runs without warnings. - id: label handle; required: true; default: not specified. Label handle to delete. Returns: void ``` indicator("label.delete", overlay=false) var object = label.new(bar_index, high, "Example") if bar_index == 10 label.delete(object) plot(array.size(label.all), "label objects remaining") ``` ### alerta.chart.point.new https://www.alertachart.com/alertascript/reference/builtins/chart.point.new Signature: chart.point.new(time, index, price) → chart.point Constructs a Pine v6 `chart.point` from explicit time, index, and price. Used as a coordinate argument to line.new/box.new/label.new/polyline.new. `chart.point` is also usable as a TYPE ANNOTATION, including the array shorthand: `var chart.point[] pts = array.new(0)` and `f(chart.point[] pts) =>`. TradingView-compatible spelling: chart.point.new; runs without warnings. - time: int; required: true; default: not specified. Timestamp (ms). - index: int; required: true; default: not specified. Bar index. - price: float; required: true; default: not specified. Price (y). Returns: chart.point ``` p = chart.point.new(time, bar_index, close) ln = line.new(bar_index - 1, low, bar_index, high) line.set_first_point(ln, p) ``` Aliases: alerta.chart.point.new ### alerta.chart.point.from_index https://www.alertachart.com/alertascript/reference/builtins/chart.point.from_index Signature: chart.point.from_index(index, price) → chart.point Pine v6: creates a chart.point at a given bar index; time is auto-derived from the bar at that index. TradingView-compatible spelling: chart.point.from_index; runs without warnings. - index: int; required: true; default: not specified. Bar index. - price: float; required: true; default: not specified. Price. Returns: chart.point ``` ln = line.new(bar_index - 5, low, bar_index, high) p1 = chart.point.from_index(bar_index - 10, low) p2 = chart.point.from_index(bar_index, high) line.set_first_point(ln, p1) line.set_second_point(ln, p2) ``` Aliases: alerta.chart.point.from_index ### alerta.chart.point.from_time https://www.alertachart.com/alertascript/reference/builtins/chart.point.from_time Signature: chart.point.from_time(time, price) → chart.point Pine v6: creates a chart.point at a given timestamp; bar index is resolved at draw time. TradingView-compatible spelling: chart.point.from_time; runs without warnings. - time: int; required: true; default: not specified. Timestamp (ms). - price: float; required: true; default: not specified. Price. Returns: chart.point ``` p = chart.point.from_time(time, close) ``` Aliases: alerta.chart.point.from_time ### alerta.chart.point.now https://www.alertachart.com/alertascript/reference/builtins/chart.point.now Signature: chart.point.now(price) → chart.point Pine v6: chart.point at the current bar with the given price (close when none is given). TradingView-compatible spelling: chart.point.now; runs without warnings. - price: float; required: not specified; default: not specified. Price. Optional; the default is close. Returns: chart.point ``` label.new(chart.point.now(close), "now") ``` Aliases: alerta.chart.point.now ### alerta.chart.point.copy https://www.alertachart.com/alertascript/reference/builtins/chart.point.copy Signature: chart.point.copy(point) → chart.point Pine v6: returns a shallow copy of a chart.point. TradingView-compatible spelling: chart.point.copy; runs without warnings. - point: chart.point; required: true; default: not specified. Source point. Returns: chart.point ``` p1 = chart.point.from_index(bar_index, close) p2 = chart.point.copy(p1) ``` Aliases: alerta.chart.point.copy ### alerta.polyline.set_curved https://www.alertachart.com/alertascript/reference/builtins/polyline.set_curved Signature: polyline.set_curved(id, curved) Pine v6: enables/disables curve smoothing on a polyline. TradingView-compatible spelling: polyline.set_curved; runs without warnings. - id: polyline; required: true; default: not specified. Polyline handle. - curved: bool; required: true; default: not specified. true = curved, false = straight. Returns: void ``` indicator("polyline.set_curved", overlay=true) if barstate.islast points = array.from(chart.point.from_time(time[8], close[8]), chart.point.from_time(time[4], close[4]), chart.point.from_time(time[1], close[1])) p = polyline.new(points, xloc=xloc.bar_time) polyline.set_curved(p, true) ``` Aliases: alerta.polyline.set_curved ### alerta.polyline.set_closed https://www.alertachart.com/alertascript/reference/builtins/polyline.set_closed Signature: polyline.set_closed(id, closed) Pine v6: when true, the polyline closes back to its first point. TradingView-compatible spelling: polyline.set_closed; runs without warnings. - id: polyline; required: true; default: not specified. Polyline handle. - closed: bool; required: true; default: not specified. Close the path. Returns: void ``` indicator("polyline.set_closed", overlay=true) if barstate.islast points = array.from(chart.point.from_time(time[8], close[8]), chart.point.from_time(time[4], close[4]), chart.point.from_time(time[1], close[1])) p = polyline.new(points, xloc=xloc.bar_time) polyline.set_closed(p, true) ``` Aliases: alerta.polyline.set_closed ### alerta.polyline.set_xloc https://www.alertachart.com/alertascript/reference/builtins/polyline.set_xloc Signature: polyline.set_xloc(id, xloc) Pine v6: switches x-axis between bar_index and bar_time. TradingView-compatible spelling: polyline.set_xloc; runs without warnings. - id: polyline; required: true; default: not specified. Polyline handle. - xloc: string; required: true; default: not specified. xloc.bar_index | xloc.bar_time. Returns: void ``` indicator("polyline.set_xloc", overlay=true) if barstate.islast points = array.from(chart.point.from_time(time[8], close[8]), chart.point.from_time(time[4], close[4]), chart.point.from_time(time[1], close[1])) p = polyline.new(points, xloc=xloc.bar_time) polyline.set_xloc(p, xloc.bar_time) ``` Aliases: alerta.polyline.set_xloc ### alerta.polyline.set_line_color https://www.alertachart.com/alertascript/reference/builtins/polyline.set_line_color Signature: polyline.set_line_color(id, line_color) Pine v6: sets the polyline stroke color. TradingView-compatible spelling: polyline.set_line_color; runs without warnings. - id: polyline; required: true; default: not specified. Polyline handle. - line_color: color; required: true; default: not specified. Stroke color. Returns: void ``` indicator("polyline.set_line_color", overlay=true) if barstate.islast points = array.from(chart.point.from_time(time[8], close[8]), chart.point.from_time(time[4], close[4]), chart.point.from_time(time[1], close[1])) p = polyline.new(points, xloc=xloc.bar_time) polyline.set_line_color(p, color.blue) ``` Aliases: alerta.polyline.set_line_color, polyline.set_color ### alerta.polyline.set_fill_color https://www.alertachart.com/alertascript/reference/builtins/polyline.set_fill_color Signature: polyline.set_fill_color(id, fill_color) Pine v6: sets the polyline interior fill color (applies when closed=true). TradingView-compatible spelling: polyline.set_fill_color; runs without warnings. - id: polyline; required: true; default: not specified. Polyline handle. - fill_color: color; required: true; default: not specified. Fill color. Returns: void ``` indicator("polyline.set_fill_color", overlay=true) if barstate.islast points = array.from(chart.point.from_time(time[8], close[8]), chart.point.from_time(time[4], close[4]), chart.point.from_time(time[1], close[1])) p = polyline.new(points, xloc=xloc.bar_time) polyline.set_fill_color(p, color.new(color.blue, 75)) ``` Aliases: alerta.polyline.set_fill_color ### alerta.polyline.set_line_style https://www.alertachart.com/alertascript/reference/builtins/polyline.set_line_style Signature: polyline.set_line_style(id, line_style) Pine v6: solid | dashed | dotted. TradingView-compatible spelling: polyline.set_line_style; runs without warnings. - id: polyline; required: true; default: not specified. Polyline handle. - line_style: string; required: true; default: not specified. line.style_solid | line.style_dashed | line.style_dotted. Returns: void ``` indicator("polyline.set_line_style", overlay=true) if barstate.islast points = array.from(chart.point.from_time(time[8], close[8]), chart.point.from_time(time[4], close[4]), chart.point.from_time(time[1], close[1])) p = polyline.new(points, xloc=xloc.bar_time) polyline.set_line_style(p, line.style_dashed) ``` Aliases: alerta.polyline.set_line_style ### alerta.polyline.set_line_width https://www.alertachart.com/alertascript/reference/builtins/polyline.set_line_width Signature: polyline.set_line_width(id, line_width) Pine v6: polyline stroke width in pixels. TradingView-compatible spelling: polyline.set_line_width; runs without warnings. - id: polyline; required: true; default: not specified. Polyline handle. - line_width: int; required: true; default: not specified. Width (px). Returns: void ``` indicator("polyline.set_line_width", overlay=true) if barstate.islast points = array.from(chart.point.from_time(time[8], close[8]), chart.point.from_time(time[4], close[4]), chart.point.from_time(time[1], close[1])) p = polyline.new(points, xloc=xloc.bar_time) polyline.set_line_width(p, 3) ``` Aliases: alerta.polyline.set_line_width ### alerta.polyline.set_points https://www.alertachart.com/alertascript/reference/builtins/polyline.set_points Signature: polyline.set_points(id, points) Pine v6: replaces the polyline's point array with a new array. TradingView-compatible spelling: polyline.set_points; runs without warnings. - id: polyline; required: true; default: not specified. Polyline handle. - points: array; required: true; default: not specified. New point array. Returns: void ``` indicator("polyline.set_points", overlay=true) if barstate.islast points = array.from(chart.point.from_time(time[8], close[8]), chart.point.from_time(time[4], close[4]), chart.point.from_time(time[1], close[1])) p = polyline.new(points, xloc=xloc.bar_time) polyline.set_points(p, array.from(chart.point.from_time(time[6], close[6]), chart.point.from_time(time[3], close[3]), chart.point.from_time(time[0], close[0]))) ``` Aliases: alerta.polyline.set_points ### alerta.polyline.delete_all https://www.alertachart.com/alertascript/reference/builtins/polyline.delete_all Signature: polyline.delete_all() Pine v6: deletes every polyline created by the script in one call. TradingView-compatible spelling: polyline.delete_all; runs without warnings. Returns: void ``` indicator("polyline.delete_all", overlay=false) var object = polyline.new(array.from(chart.point.from_index(bar_index, low), chart.point.from_index(bar_index + 5, high))) if bar_index == 10 polyline.delete_all() plot(array.size(polyline.all), "polyline objects remaining") ``` Aliases: alerta.polyline.delete_all ### alerta.polyline.all https://www.alertachart.com/alertascript/reference/builtins/polyline.all Signature: polyline.all → array Pine v6: read-only array containing every active polyline handle. TradingView-compatible spelling: polyline.all; runs without warnings. Returns: array ``` indicator("polyline.all", overlay=false) var object = polyline.new(array.from(chart.point.from_index(bar_index, low), chart.point.from_index(bar_index + 5, high))) plot(array.size(polyline.all), "polyline objects remaining") ``` Aliases: alerta.polyline.all ### alerta.line.all https://www.alertachart.com/alertascript/reference/builtins/line.all Signature: line.all → array An array of every line the script has drawn and not deleted, oldest first. It is a new array on every read, so deleting lines while walking it — `for l in line.all` then `line.delete(l)`, or `array.get(line.all, i)` in a counted loop — deletes them all. TradingView-compatible spelling: line.all; runs without warnings. Returns: array ``` indicator("line.all", overlay=false) var object = line.new(bar_index, low, bar_index + 5, high) plot(array.size(line.all), "line objects remaining") ``` Aliases: alerta.line.all ### alerta.line.delete_all https://www.alertachart.com/alertascript/reference/builtins/line.delete_all Signature: line.delete_all() Pine v6: deletes every line created by the script. TradingView-compatible spelling: line.delete_all; runs without warnings. Returns: void ``` indicator("line.delete_all", overlay=false) var object = line.new(bar_index, low, bar_index + 5, high) if bar_index == 10 line.delete_all() plot(array.size(line.all), "line objects remaining") ``` Aliases: alerta.line.delete_all ### alerta.label.all https://www.alertachart.com/alertascript/reference/builtins/label.all Signature: label.all → array