Docs

Deepwick Script reference

Deepwick Script is the language of Deepwick's charts and backtests. It reads Pine Script v5 code, so most indicators and strategies written for TradingView run unchanged. This page lists everything the engine supports today and what it does not.

New to Deepwick? Start with the step-by-step guide: How to backtest a Pine Script strategy for free.

Updated:

Language

Deepwick Script reads Pine Script v5 syntax. A script runs once per bar, from the oldest bar to the newest, and every variable keeps its history.

SyntaxWhat it does
x = expr / x := exprDeclare a variable, then reassign it with :=. An optional type (int, float, bool, string, color, series, simple, const, line, label) may precede the name.
var / varipInitialise once on the first bar and keep the value across bars. varip behaves like var, since scripts run on closed bars.
x[n]History operator: the value of x n bars ago (na before the first bar).
if / elseConditional blocks, indented by four spaces. if can also be used as an expression.
cond ? a : bTernary operator.
switchMulti-way branch, with or without a value to match.
for i = a to b [by step]Counted loop. break and continue are supported.
while condLoop while a condition holds.
f(x, y) => exprUser-defined function, on one line or as an indented block whose last expression is returned. Each call site keeps its own ta.* state, as in Pine.
[a, b] = f()Tuples: functions can return several values, and built-ins like ta.macd() and ta.bb() do.
and / or / notLogical operators. Arithmetic: + - * / %; comparison: == != < <= > >=.

Declarations

SyntaxWhat it does
indicator(title, shorttitle, overlay, precision)Declares an indicator: it draws on the chart and has nothing to backtest. study() is accepted as an alias.
strategy(title, overlay, initial_capital, default_qty_type, default_qty_value, commission_type, commission_value, slippage, pyramiding)Declares a strategy. Defaults: initial_capital 100000, 1 contract per order, commission 0, slippage 0 ticks, pyramiding 1. Other arguments, such as process_orders_on_close, are ignored.

Inputs

Inputs appear next to the editor and in the indicator's settings, so you can change them without touching the code.

SyntaxWhat it does
input.int(defval, title, minval, maxval, step)Whole number.
input.float(defval, title, minval, maxval, step)Decimal number.
input.bool(defval, title)Checkbox.
input.string(defval, title, options)Text, or a list of options.
input.source(defval, title)A price source: open, high, low, close, hl2, hlc3, ohlc4 or hlcc4.
input.color(defval, title)Colour picker.
input(defval, title)Generic input; the type follows the default value.

Bar data and time

Times are UTC milliseconds. hour() and the other time functions take an optional time; hour() also takes a time zone from a fixed list of offsets, without daylight saving.

SyntaxWhat it does
open, high, low, close, volumePrices and volume of the current bar.
hl2, hlc3, ohlc4, hlcc4Common price averages.
bar_index, last_bar_indexIndex of the current bar (0 is the oldest) and of the last bar.
time, time_closeOpen and close time of the bar.
year, month, weekofyear, dayofmonth, dayofweek, hour, minute, secondCalendar parts of the bar's time; also callable with a time, e.g. hour(time, "America/New_York"). dayofweek: 1 = Sunday … 7 = Saturday.
barstate.isfirst, islast, isnew, isconfirmed, ishistory, isrealtimeWhere the script is in the bar history.
timeframe.period, multiplier, isintraday, isdaily, isweekly, ismonthlyThe chart's timeframe.
syminfo.ticker, tickerid, mintick, pointvalueThe chart's symbol, its price step and its point value.

Technical analysis (ta.*)

Every call site keeps its own state, as in Pine: two ta.ema() calls on different lines are two independent averages. Results are na until enough bars exist.

SyntaxWhat it does
ta.sma(source, length)Simple moving average.
ta.ema(source, length)Exponential moving average.
ta.rma(source, length)Wilder's moving average, used by RSI and ATR.
ta.wma(source, length)Weighted moving average.
ta.vwma(source, length)Volume-weighted moving average.
ta.hma(source, length)Hull moving average.
ta.linreg(source, length, offset)Linear regression line value.
ta.vwap(source)Volume-weighted average price, restarting at 00:00 UTC each day.
ta.rsi(source, length)Relative Strength Index, 0 to 100.
ta.macd(source, fastlen, slowlen, siglen)Returns [macd, signal, histogram].
ta.stoch(source, high, low, length)Stochastic %K, 0 to 100.
ta.cci(source, length)Commodity Channel Index.
ta.mfi(series, length)Money Flow Index.
ta.wpr(length)Williams %R, -100 to 0.
ta.dmi(diLength, adxSmoothing)Returns [+DI, -DI, ADX].
ta.supertrend(factor, atrPeriod)Returns [supertrend, direction]; direction is -1 in an uptrend and 1 in a downtrend.
ta.sar(start, inc, max)Parabolic SAR.
ta.mom(source, length)Momentum: source minus source length bars ago.
ta.roc(source, length)Rate of change, in percent.
ta.change(source, length)Difference from length bars ago (1 by default).
ta.tr / ta.tr(handle_na)True range.
ta.atr(length)Average true range (Wilder).
ta.bb(series, length, mult)Bollinger Bands: returns [middle, upper, lower].
ta.bbw(series, length, mult)Bollinger Band width: (upper - lower) / middle.
ta.kc(series, length, mult)Keltner Channels: returns [middle, upper, lower], with an EMA of the true range.
ta.stdev(source, length, biased)Standard deviation.
ta.variance(source, length, biased)Variance.
ta.dev(source, length)Mean absolute deviation.
ta.median(source, length)Median.
ta.highest(source, length) / ta.highest(length)Highest value over length bars (the high by default).
ta.lowest(source, length) / ta.lowest(length)Lowest value over length bars (the low by default).
ta.highestbars(source, length)Offset to the highest value: 0 or negative.
ta.lowestbars(source, length)Offset to the lowest value: 0 or negative.
ta.rising(source, length)True if source is above each of its previous length values.
ta.falling(source, length)True if source is below each of its previous length values.
ta.crossover(source1, source2)True on the bar where source1 crosses above source2.
ta.crossunder(source1, source2)True on the bar where source1 crosses below source2.
ta.cross(source1, source2)True on a cross in either direction.
ta.pivothigh(source, leftbars, rightbars)The pivot high price, known rightbars bars after the pivot; na otherwise. The source is optional (the high by default).
ta.pivotlow(source, leftbars, rightbars)The pivot low price, known rightbars bars after the pivot; na otherwise. The source is optional (the low by default).
ta.valuewhen(condition, source, occurrence)Value of source on the occurrence-th most recent bar where condition was true.
ta.barssince(condition)Bars since condition was last true.
ta.cum(source)Running total since the first bar.

Strategies (strategy.*)

Market orders fill at the next bar's open. Stop and limit orders fill along the bar: open, then the extreme nearer the open, then the other extreme, then close. If price gaps through an order, it fills at the open. Commission is charged on every fill; slippage applies to market and stop fills.

SyntaxWhat it does
strategy.entry(id, direction, qty, limit, stop, comment)Open or add to a position; market order unless limit or stop is given.
strategy.order(id, direction, qty, limit, stop, comment)Same arguments as strategy.entry().
strategy.exit(id, from_entry, qty_percent, profit, limit, loss, stop, comment)Take-profit and stop-loss for an entry: profit and loss in ticks, limit and stop as prices.
strategy.close(id, comment, qty_percent)Close an entry at market on the next bar.
strategy.close_all(comment)Close every open position.
strategy.cancel(id) / strategy.cancel_all()Cancel pending orders.
strategy.position_size, position_avg_priceCurrent position (positive long, negative short) and its average price.
strategy.equity, netprofit, openprofit, grossprofit, grossloss, initial_capitalAccount figures.
strategy.closedtrades, opentrades, wintrades, losstradesTrade counts.
strategy.long, strategy.shortDirections.
strategy.fixed, strategy.cash, strategy.percent_of_equityValues for default_qty_type.
strategy.commission.percent, cash_per_order, cash_per_contractValues for commission_type.

Plots and alerts

SyntaxWhat it does
plot(series, title, color, linewidth, style)Draw a series on the chart or in a pane.
plotshape(series, title, style, location, color, text)Draw a shape on bars where series is true.
plotchar(series, title, char, location, color)Draw a character on bars where series is true.
hline(price, title, color, linestyle)Horizontal line at a fixed level.
fill(plot1, plot2, color)Fill between two plots or two hlines.
bgcolor(color)Colour the background of the bar.
barcolor(color)Colour the bar itself.
alertcondition(condition, title, message)Declare a condition you can turn into an alert by email, Telegram, Discord or webhook.
plot.style_*line, linebr, stepline, histogram, columns, circles, cross, area.
hline.style_*solid, dashed, dotted.
shape.*triangleup, triangledown, arrowup, arrowdown, circle, xcross, cross, diamond, square, flag, labelup, labeldown.
location.*abovebar, belowbar, top, bottom, absolute.
size.*auto, tiny, small, normal, large, huge. Accepted, but shapes are drawn at one size.

Lines and boxes

SyntaxWhat it does
line.new(x1, y1, x2, y2, extend, color, style, width)Draw a line between two bar indexes and prices; returns its id.
line.set_x1, set_y1, set_x2, set_y2, set_xy1, set_xy2, set_color, set_style, set_widthChange a line.
line.delete(id)Remove a line.
box.new(left, top, right, bottom, border_color, bgcolor, extend)Draw a rectangle; returns its id.
box.set_left, set_top, set_right, set_bottom, set_bgcolor, set_border_color, set_extendChange a box.
box.delete(id)Remove a box.
line.style_*, box.style_*solid, dashed, dotted.
extend.*none, left, right, both.

Math, strings and colours

SyntaxWhat it does
math.abs, ceil, floor, round(number, precision), sign, sqrt, exp, log, log10, pow(base, exponent)Arithmetic.
math.max(...), math.min(...), math.avg(...)Of any number of values.
math.sum(source, length)Sum over the last length bars.
math.pi, math.eConstants.
na, na(x), nz(x, replacement), fixnan(x)The missing value, a test for it, a replacement for it, and the last non-na value.
int(x), float(x), bool(x)Conversions.
str.tostring(value, format), str.format(text, ...), str.length(s), str.contains(s, part)Strings. str.format replaces {0}, {1}… with the arguments.
color.new(color, transp), color.rgb(red, green, blue, transp)Build a colour; transparency from 0 to 100.
color.*red, green, blue, orange, yellow, purple, aqua, lime, fuchsia, teal, maroon, navy, olive, gray, silver, white, black.

Arrays (array.*)

SyntaxWhat it does
array.new_float, new_int, new_bool, new_string, new_color, new_line, new_box, new_label, new_table(size)Create an array.
array.get, set, insert, push, pop, shift, unshiftRead and change elements.
array.size, first, last, sum, avg, min, max, stdevSize and statistics.

Not supported yet

A function the engine does not know stops the script with "Unknown function" and the line and column.

SyntaxWhat it does
request.security()Compiles but returns na: data from other symbols or timeframes is not available inside scripts yet.
label.new(), table.new()Not available yet. Lines and boxes are.
type, method, import, map.*, matrix.*User-defined types, methods, libraries, maps and matrices are not supported.
strategy.risk.*, trailing stopsRisk rules and trailing stops in strategy.exit() are not supported.

Questions

Is Deepwick Script the same as Pine Script?

No. It is Deepwick's own engine, which reads Pine Script v5 syntax and implements the functions on this page. Most v5 indicators and strategies run unchanged. Deepwick is not affiliated with TradingView; Pine Script is a trademark of TradingView, Inc.

Can I run Pine Script v6 code?

The //@version line is not enforced, so a v6 script runs if it only uses what this page lists. Behaviour that only exists in v6 is not implemented.

Does Deepwick support request.security()?

Not yet. The call compiles but returns na, so anything built on another symbol or timeframe stays empty.

How are strategy orders filled in a backtest?

Market orders fill at the next bar's open. Stops and limits fill along the bar (open, nearer extreme, farther extreme, close), and an order the price gaps through fills at the open. Commission is charged on every fill and slippage on market and stop fills, as set in strategy(); both default to zero.

Where do scripts run?

On the chart, in your browser, over the bars loaded on the chart. Saved backtests run on Deepwick's servers over up to 5,000 bars.