TradeHub includes a built-in JavaScript-based scripting API that allows you to create highly customized trading bots. Whether you are new to coding or already familiar with algorithmic trading, this API is designed to be easy to use, while still powerful enough for advanced users.
This page introduces the key global objects and functions available in your trading scripts.
Your script runs in a secure JavaScript environment with several global objects already available. These globals provide access to market data, trading actions, indicators, account balances, and more.
Built-in tools for plotting and detecting indicator events.
ta.plot(name, value, settings = {}, stepBack = 0)
Plot data on the chart.
ta.clearPlot(name, stepBack = 0)
Remove a specific plot.
ta.crossUp(firstSeries, secondSeries)
Returns true if firstSeries crosses upward over secondSeries.
ta.crossDown(firstSeries, secondSeries)
Returns true if firstSeries crosses downward below secondSeries.
ta.crossAny(firstSeries, secondSeries)
Returns true if any cross occurs in either direction.
ta.calc(metaKey, name, inputs, options = {})
Calculates a built-in indicator with the given input. You can create indicators that use other indicators or your custom-calculated values as inputs, also known as Meta Indicators.
If you need standard indicators with OHLCV (candlestick) data as input, use ind.add or UI Indicator Section instead—for both better performance and ease of use.
If the indicator requires a single input, provide it directly. If it requires multiple inputs, pass them as an array—in the correct order.
Example: ta.calc("unique-name", "sma", candle.close, { period: 20 }).
Example: ta.calc("unique-name2", "adx", [candle.high,candle.close], { period: 20 }).
ind.ref(alias, outputName?) → Returns a reference to an indicator output for use in indicator releated functions.
ind.get(aliasOrRef, prevAmount = 0) → Get current or historical value of an indicator.
ind.prev(aliasaliasOrRef, prevAmount = 1) → Get indicator value from prevAmount steps back.
ind.last(aliasOrRef, amount = 14) → Get an array of the last amount values.
ind.add(indicator) → Add a new indicator for use in scripts.
Note: Functions that accept an indicator alias also accept an ind.ref(name, output) reference.
This allows you to work with specific outputs of multi-output indicators.
// Get the last 10 values of BBANDS lower band
ind.get(ind.ref('bbands','lower'),10);
This is especially useful for helpers like crossUp.
For example, a simple MACD strategy can be written as:
utils.maxBuyAmount(price?) – Returns the maximum buyable amount at the given price (or current best bid if omitted), with the estimated fee already deducted.
utils.round(number)
Rounds number to the current market precision; returns null if input is invalid.
utils.roundToDecimals(number, decimal = 2)
Rounds number to decimal places; returns null if inputs are invalid or decimal is negative.