ScriptingConceptsChart information

Chart Information

Introduction

Lipi Script provides a set of built-in variables that allow scripts to obtain information about the chart and symbol they are currently running on. The variables covered here enable access to:

  • The chart’s prices and volume
  • The chart’s symbol
  • The chart’s timeframe
  • The session (or time period) the symbol trades on

Prices and Volume

The built-in variables for OHLCV values are:

  • open: The bar’s opening price.
  • high: The bar’s highest price, or the highest price reached during the real-time bar’s elapsed time.
  • low: The bar’s lowest price, or the lowest price reached during the real-time bar’s elapsed time.
  • close: The bar’s closing price, or the current price in the real-time bar.
  • volume: The volume traded during the bar, or the volume traded during the real-time bar’s elapsed time. The unit of volume varies by instrument (shares for stocks, lots for forex, contracts for futures, base currency for crypto, etc.).

Other available values include:

  • hl2: The average of the bar’s high and low values.
  • hlc3: The average of the bar’s high, low, and close values.
  • ohlc4: The average of the bar’s open, high, low, and close values.

On historical bars, the values of these variables remain constant during the bar because only OHLCV information is available at that point. Scripts run on historical bars at the bar’s close, so all data is known and cannot change during the execution.

Real-time bars behave differently. When indicators (or strategies with calc_on_every_tick = true) run in real-time, the values of the above variables (except for open) will vary between successive script iterations on the real-time bar, as they represent the current value at one point in time during the bar’s progress. This may lead to repainting. See the section on Lipi Script’s execution model for more details.

The [] history-referencing operator can be used to refer to past values of built-in variables, e.g., close[1] refers to the close value on the previous bar, relative to the current bar.

Symbol Information

Lipi Script provides built-in variables in the syminfo namespace to access information about the symbol of the chart the script is running on. This information updates whenever the chart’s symbol changes, causing the script to re-execute on all the chart’s bars using the new values:

  • syminfo.basecurrency: The base currency (e.g., “BTC” in “BTCUSD”, or “EUR” in “EURUSD”).
  • syminfo.currency: The quote currency (e.g., “USD” in “BTCUSD”, or “CAD” in “USDCAD”).
  • syminfo.description: The long description of the symbol.
  • syminfo.mintick: The symbol’s tick value, or the minimum increment the price can move. Not to be confused with pips or points (e.g., for “ES1!” (“S&P 500 E-Mini”), the tick size is 0.25).
  • syminfo.pointvalue: The point value, which determines the value of a contract based on the underlying asset. For “ES1!” (“S&P 500 E-Mini”), the point value is 50, so a contract is worth 50 times the price of the instrument.
  • syminfo.prefix: The exchange or broker’s identifier (e.g., “NASDAQ” or “BATS” for “AAPL”, “CME_MINI_DL” for “ES1!”).
  • syminfo.root: The ticker’s prefix for structured tickers like futures (e.g., “ES” for “ES1!”, “ZW” for “ZW1!”).
  • syminfo.session: Reflects the session setting on the chart for that symbol. If the “Chart settings/Symbol/Session” field is set to “Extended”, it will return “extended” if the symbol and user’s feed allow extended sessions.
  • syminfo.ticker: The symbol’s name without the exchange part (e.g., “BTCUSD”, “AAPL”, “ES1!”, “USDCAD”).
  • syminfo.tickerid: A rarely used string, mostly for arguments in request.security()’s symbol parameter, including session, prefix, and ticker info.
  • syminfo.timezone: The timezone the symbol is traded in, using IANA time zone database names (e.g., “America/New_York”).
  • syminfo.type: The market type of the symbol

Chart Timeframe

A script can obtain information on the type of timeframe used on the chart using these built-in variables, which all return a “simple bool” result:

  • timeframe.isseconds
  • timeframe.isminutes
  • timeframe.isintraday
  • timeframe.isdaily
  • timeframe.isweekly
  • timeframe.ismonthly
  • timeframe.isdwm

Additional Built-ins for Specific Timeframe Information

  1. timeframe.multiplier:
    Returns a “simple int” containing the multiplier of the timeframe unit. Examples:

    • A chart timeframe of one hour returns 60 because intraday timeframes are expressed in minutes.
    • A 30-second timeframe returns 30 (seconds).
    • A daily chart returns 1 (day).
    • A quarterly chart returns 3 (months).
    • A yearly chart returns 12 (months).

    Note: The value of this variable cannot be used as an argument to timeframe parameters in built-in functions, as they expect a string in timeframe specifications format.

  2. timeframe.period:
    Returns a string in Lipi Script’s timeframe specification format.

Refer to the page on Timeframes for more details.


Session Information

Session information is available in different forms:

  1. syminfo.session:
    This built-in variable returns a value that is either session.regular or session.extended. It reflects the session setting on the chart for that symbol.

    • If the “Chart settings/Symbol/Session” field is set to Extended, it will only return extended if the symbol and the user’s feed allow for extended sessions.
    • This variable is used when a session type is expected, such as an argument for the session parameter in ticker.new().
  2. Session State Built-ins:
    Provide information about the trading session to which a bar belongs.