📰 Latest: HaasOnline Academy Is Back — Structured Education for Smarter Trade Bots
Account
Converting Other Languages

PineScript Part 3 - Command Reference

PineScript to HaasScript Command Reference

A mapping of the most common PineScript commands to their HaasScript equivalents. This covers indicators, price data, strategy functions, and utility commands.

Moving Averages

PineScript HaasScript Notes
ta.sma(source, length) SMA(prices, period) Same parameters
ta.ema(source, length) EMA(prices, period) Same parameters
ta.wma(source, length) WMA(prices, period) Same parameters
ta.rma(source, length) EMA(prices, period) RMA is equivalent to EMA in most contexts
ta.vwma(source, length) No direct equivalent HaasScript has no built-in VWMA
ta.swma(source) No direct equivalent No Symmetric Weighted Moving Average
ta.alma(source, length, offset, sigma) No direct equivalent

Oscillators

PineScript HaasScript Notes
ta.rsi(source, length) RSI(prices, period) Same parameters
ta.macd(source, 12, 26, 9) MACD(prices, 12, 26, 9) Returns array: [1] = MACD, [2] = signal, [3] = histogram
ta.stoch(source, high, low, k, d) STOCH(high, low, close, fastK, slowK, slowD) Requires separate HLC arrays
ta.sma(ta.stoch(...), smoothK) SSTOCH(prices, period) Simplified stochastic
ta.wad() No direct equivalent Williams Accumulation/Distribution
ta.cci(source, length) CCI(high, low, close, period) Requires separate HLC arrays
ta.mfi(high, low, close, volume, length) MFI(high, low, close, volume, period) Requires separate HLC + volume arrays
ta.obv(source, volume) OBV(prices, volumes) Same parameters

Volatility

PineScript HaasScript Notes
ta.atr(length) ATR(high, low, close, period) Requires separate HLC arrays
ta.natr(length) NATR(high, low, close, period) Normalized ATR (percentage)
ta.tr TRANGE(high, low, close) True Range, requires separate HLC arrays
ta.bbands(source, length, mult) BBANDS(prices, period, devUp, devDn) Separate devUp/devDn params. Returns [1]=upper, [2]=middle, [3]=lower
ta.keltner(source, length, mult) KELTNER(high, low, close, emaPeriod, atrPeriod, atrMult) Different parameter structure
ta.standardize(source, length) No direct equivalent
ta.dev(source, length) AVGDEV(prices, period) Mean absolute deviation
ta.variance(source, length) VAR(prices, period) Same parameters
ta.stdev(source, length) STDDEV(prices, period, deviation) Requires deviation parameter (usually 1)

Momentum

PineScript HaasScript Notes
ta.mom(source, length) MOM(prices, period) Same parameters
ta.roc(source, length) ROC(prices, period) Same parameters
ta.roc(source, length) ROCP(prices, period) Percentage rate of change
ta.rsi(source, length) RSI_ALTB(prices, period) Alternative RSI calculation
ta.wpr(high, low, close, length) WILLR(high, low, close, period) Williams %R
ta.cmo(source, length) CMO(prices, period) Chande Momentum Oscillator
ta.ultosc(high, low, close, ...) ULTOSC(high, low, close, period1, period2, period3) Same three periods
ta.ppo(source, length, signalLength) PPO(prices, fastPeriod, slowPeriod, signalPeriod) Different parameter structure
ta.dmi(length, adxSmoothing) ADX(high, low, close, period) Returns ADX only
ta.plusdi(length, adxSmoothing) PLUSDI(high, low, close, period) Requires separate HLC arrays
ta.minusdi(length, adxSmoothing) MINUSDI(high, low, close, period) Requires separate HLC arrays

Trend

PineScript HaasScript Notes
ta.sar(accel, max) SAR(high, low, acceleration, maxSpeed) Requires separate HL arrays
ta.supertrend(factor, atrPeriod) No direct equivalent No built-in SuperTrend
ta.ichimoku(...) ICHIMOKU(prices, tenkan, kijun, senkouB) Simplified — no displacement offset
ta.donchian(length) DONCHIAN(high, low, period) Requires separate HL arrays
ta.linreg(source, length, offset) LINEARREG(prices, period) No offset parameter

Volume

PineScript HaasScript Notes
volume Volume() Returns HaasNumberCollection
ta.obv(source, volume) OBV(prices, volumes) Same logic

Price Data

PineScript HaasScript Returns
close ClosePrices() HaasNumberCollection
open OpenPrices() HaasNumberCollection
high HighPrices() HaasNumberCollection
low LowPrices() HaasNumberCollection
volume Volume() HaasNumberCollection
syminfo.ticker CurrentPrice() Current price data
syminfo.basecurrency BaseCurrency() String
syminfo.quotecurrency QuoteCurrency() String
timeframe.period No direct equivalent Intervals are configured in the bot, not read in script
bar_index No direct equivalent Track manually with a counter
ta.highest(source, length) GetHigh(prices, depth) Returns number
ta.lowest(source, length) GetLow(prices, depth) Returns number
ta.highestbars(source, length) MAXINDEX(prices, period) Returns index of highest
ta.lowestbars(source, length) MININDEX(prices, period) Returns index of lowest
ta.cross(source, target) CrossOver(a, b) Returns boolean
ta.crossover(source, target) CrossOver(a, b) Returns boolean
ta.crossunder(source, target) CrossUnder(a, b) Returns boolean
ta.rising(source, length) IsRising(array, lookback) Returns boolean
ta.falling(source, length) IsFalling(array, lookback) Returns boolean

Multi-Timeframe Data

PineScript HaasScript Notes
request.security(symbol, tf, source) ClosePrices(interval) Interval in minutes: 1, 5, 15, 60, 240, 1440
-- PineScript
weeklyClose = request.security(syminfo.tickerid, "1W", close)

-- HaasScript
local weeklyClose = ClosePrices(10080)  -- 10080 minutes = 1 week

Strategy Functions

Entry and Exit

PineScript HaasScript Notes
strategy.entry(id, strategy.long) DoLong() Managed trading — no size needed
strategy.entry(id, strategy.short) DoShort() Managed trading — no size needed
strategy.entry(id, strategy.long, qty=10) Unmanaged trading Requires PlaceBuyOrder() or similar
strategy.close(id) DoExitPosition() Closes the current position
strategy.close_all() DoExitPosition() Same — HaasScript has one open position per bot

Position State

PineScript HaasScript Notes
strategy.position_size > 0 GetPositionDirection() == PositionLong Returns enum, not numeric
strategy.position_size < 0 GetPositionDirection() == PositionShort Returns enum
strategy.position_size == 0 GetPositionDirection() == NoPosition Returns enum
strategy.position_avg_price GetPositionEnterPrice() Entry price

Risk Management

PineScript HaasScript Notes
strategy.exit("SL", stop=price) StopLoss(percentage) Accepts percentage, not price
strategy.exit("TP", limit=price) TakeProfit(percentage) Accepts percentage, not price
strategy.exit("Trail", trail_points=...) TrailingStopLoss(percentage) Single percentage parameter
strategy.risk.max_entries_count No direct equivalent Managed by bot configuration

Trade Information

PineScript HaasScript Notes
strategy.closedtrades No direct equivalent Access trade history through backtest reports
strategy.equity No direct equivalent
strategy.netprofit No direct equivalent
strategy.wintrades No direct equivalent

Utility Functions

PineScript HaasScript Notes
input.int(def, title) Input(title, default) Auto-detects type from default
input.float(def, title) Input(title, default) Same — auto-detects
input.bool(def, title) Input(title, default) Same
input.string(def, title) Input(title, default) Same
input.source(def, title) Input(title, default) Same
input.timeframe(def, title) No direct equivalent Intervals set in bot config
math.abs(x) Abs(x) HaasScript version handles collections
math.round(x) Round(x, decimals) HaasScript version handles collections
math.max(a, b) Max(a, b)
math.min(a, b) Min(a, b)
math.sqrt(x) Sqrt(x) HaasScript version handles collections
str.tostring(x) tostring(x) Standard Lua
str.tonumber(x) tonumber(x) Standard Lua
str.replace(src, target, replacement) string.gsub(src, target, replacement) Lua string library
str.length(s) string.len(s) or #s Lua string library
str.contains(s, substr) StringContains(s, substr) HaasScript command
color.new(red, green, blue) 'rgb(r, g, b)' Pass as string
color.rgb(r, g, b, transp) 'rgba(r, g, b, a)' Pass as string
na nil
nz(x) IfNull(x, 0) Replaces nil with default
barstate.isconfirmed No direct equivalent Use fullCandles parameter on price data
timeframe.change(newTF) No direct equivalent Not possible at runtime

Plotting

PineScript HaasScript Notes
plot(series, title, color) Plot(series, title, color) Color passed as string
hline(price, title, color) PlotHorizontalLine(price, title, color)
bgcolor(condition, color) MarkCandle(condition, color) Marks individual candles
barcolor(color) MarkCandle(true, color) Marks current candle
plotshape(condition, style) PlotShapes(condition, style) Various shape options
plotchar(condition, char) PlotShapes(condition, style) No char — use shapes
plotarrow(direction) No direct equivalent Use PlotSignalBar()
fill(h1, h2, color) PlotCloud(upper, lower, color) Fills between two plots

Common Parameter Patterns

HaasScript indicators that need OHLC data take separate array arguments instead of a single source. When converting from PineScript, split out the arrays:

-- PineScript: single source
myAtr = ta.atr(14)
myStoch = ta.stoch(close, high, low, 14, 3, 3)

-- HaasScript: separate HLC arrays
local atr = ATR(HighPrices(), LowPrices(), ClosePrices(), 14)
local stoch = STOCH(HighPrices(), LowPrices(), ClosePrices(), 14, 3, 3)