### Input Sources and Moving Averages Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/input/input.md Provides examples and explanations for creating input selectors for source data and moving averages. ```APIDOC ## Input Selectors for Sources and Averages ### Description Convenient predefined arrays are available to create **source** and **moving average** selectors, simplifying the configuration of indicators. ### Source Input for Overlay Instruments ```lua src_idx = input(inputs.close, "Source", input.string_selection, inputs.titles_overlay) local source = inputs [src_idx] ``` ### Source Input for Standalone Instruments ```lua src_idx = input(inputs.close, "Source", input.string_selection, inputs.titles) local source = inputs [src_idx] ``` ### Moving Average Input ```lua avg_idx = input (averages.sma, "Average", input.string_selection, averages.title) local average = averages [avg_idx] ``` ``` -------------------------------- ### Input Group for Visual Styling Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/index.md Defines a group of user inputs specifically for controlling the visual appearance of an instrument's plot. This example sets up inputs for line color and width, with default values. ```lua input_group { "Line", color = input { default = "red", type = input.color }, width = input { default = 1, type = input.line_width} } ``` -------------------------------- ### Input Groups for Visual Settings in Lua Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Organizes user inputs into collapsible groups within the indicator settings UI for better organization. This example groups signal line and threshold settings. Dependencies: None. Inputs: Various, grouped for clarity. Outputs: Plots RSI and horizontal lines. ```lua instrument { name = "Multi-Line Indicator", short_name = "Multi", overlay = false } -- Signal line settings group input_group { "Signal Line", signal_color = input { default = "#56CEFF", type = input.color }, signal_width = input { default = 2, type = input.line_width }, signal_visible = input { default = true, type = input.plot_visibility } } -- Threshold settings group input_group { "Thresholds", upper_threshold = input { default = 70, type = input.integer }, lower_threshold = input { default = 30, type = input.integer } } -- Use the grouped inputs rsi_value = rsi(close, 14) plot(rsi_value, "RSI", signal_color, signal_width) if signal_visible then hline(upper_threshold, "Upper", "red") hline(lower_threshold, "Lower", "green") end ``` -------------------------------- ### User Input Definition (Integer) Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/index.md Defines a user-configurable input parameter for an instrument. This example creates an integer input named 'Period' with a default value of 14 and a minimum value of 1. ```lua period = input (14, "Period", input.integer, 1) ``` -------------------------------- ### vwma Function Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/averages/vwma.md This section details the vwma function, its parameters, and its return value, along with a mathematical formula and an example. ```APIDOC ## vwma ### Description Calculates the volume weighted moving average of an input series for a specified period. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method None (This is a function, not an API endpoint) ### Endpoint None (This is a function, not an API endpoint) ### Function Signature `vwma(series, period)` ### Parameters - **series** (`series`) - Required - Input series for calculation. - **period** (`numeric`) - Required - The period (number of bars) over which to calculate the MA. ### Returns - **series** (`series`) - The calculated volume weighted moving average series. ### Mathematical Formula $$ \mathrm{wma} = \frac{\sum_{i=0}^{\mathrm{period} - 1}\mathrm{volume}_i \mathrm{series}_i}{\sum_{i=0}^{\mathrm{period-1}}\mathrm{volume}_i} $$ ### Example ``` // Assuming 'close_prices' is a series of closing prices and 'volumes' is a series of trading volumes let vwma_series = vwma(close_prices, 14); ``` ### Response #### Success Response (200) None (This is a function, not an API endpoint) #### Response Example None (This is a function, not an API endpoint) ### Error Handling None (This is a function, not an API endpoint) ``` -------------------------------- ### Multi-Timeframe Analysis with security() in Lua Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Performs analysis by accessing data from different timeframes using the security() function. This example calculates and plots the EMA for the current timeframe and a higher timeframe (1 hour). Dependencies: None. Inputs: ema_period (integer). Outputs: Plots current TF EMA and 1H EMA. ```lua instrument { name = "Multi-Timeframe EMA", short_name = "MTF EMA", overlay = true } ema_period = input(20, "EMA Period", input.integer, 1) -- Get current timeframe data current_ema = ema(close, ema_period) -- Get higher timeframe (1 hour) data htf_data = security(current_ticker_id, "1H") htf_ema = ema(htf_data.close, ema_period) -- Plot both EMAs plot(current_ema, "Current TF EMA", "blue", 1) plot(htf_ema, "1H EMA", "red", 2) ``` -------------------------------- ### Conditional Logic and Series Conversion with Lua Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Converts boolean conditions into series for historical analysis and dynamic plotting. This example creates an uptrend indicator and colors the closing price based on whether it's above the EMA. Dependencies: None. Inputs: ema_period (integer). Outputs: Plots Close with dynamic color and EMA. ```lua instrument { name = "Trend Indicator", short_name = "Trend", overlay = true } ema_period = input(20, "EMA Period", input.integer, 1) -- Calculate EMA ema_value = ema(close, ema_period) -- Create conditional series for uptrend uptrend = conditional(close > ema_value) -- Use iff for conditional coloring trend_color = iff(uptrend, "green", "red") -- Plot close with dynamic color plot(close, "Close", trend_color, 2) plot(ema_value, "EMA", "white", 1) ``` -------------------------------- ### GET /security Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/security/security.md Fetches security data for a given ticker ID and resolution. ```APIDOC ## GET /security ### Description Retrieves historical security data (OHLCV and timestamps) for a specified ticker ID and resolution. ### Method GET ### Endpoint /security ### Parameters #### Query Parameters - **ticker_id** (integer) - Required - The ID of the ticker. This ID can be obtained using the `get_ticker_id` function. - **resolution** (string) - Required - The time resolution for the security data. Possible values include: "1s", "5s", "10s", "15s", "30s", "1m", "2m", "5m", "10m", "15m", "30m", "1H", "2H", "4H", "8H", "12H", "1D", "1W", "1M", "1Y". ### Request Example ```lua -- Assuming current_ticker_id is already defined local security_data = get('/security', { ticker_id = current_ticker_id, resolution = '1m' }) print(security_data.close) ``` ### Response #### Success Response (200) - **close** (series) - Closing price data. - **open** (series) - Opening price data. - **high** (series) - Highest price data. - **low** (series) - Lowest price data. - **volume** (series) - Trading volume data. - **open_time** (series) - Timestamp for the opening of the trading period. - **close_time** (series) - Timestamp for the closing of the trading period. #### Response Example ```json { "close": [ 100.50, 101.20, 100.80 ], "open": [ 100.00, 100.50, 101.10 ], "high": [ 101.00, 101.50, 101.00 ], "low": [ 99.80, 100.20, 100.50 ], "volume": [ 10000, 12000, 11000 ], "open_time": [ 1678886400, 1678886460, 1678886520 ], "close_time": [ 1678886459, 1678886519, 1678886579 ] } ``` ``` -------------------------------- ### Count Bars Since Condition with Lua Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Counts the number of bars that have passed since a specific condition was last met. This example counts bars since the price made a new high over a given period. Dependencies: None. Inputs: period (integer). Outputs: Plots the bar count. ```lua instrument { name = "Breakout Counter", short_name = "Breakout", overlay = false } period = input(20, "Period", input.integer, 1) -- Find highest high over period hh = highest(high, period) -- Create condition for new high new_high = conditional(get_value(high) >= get_value(hh[1])) -- Count bars since last new high bars_count = bars_since(new_high) -- Plot the count plot(bars_count, "Bars Since High", "cyan", 2) ``` -------------------------------- ### Get Value of a Series with Optional Default (Lua) Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/misc/get_value.md Retrieves the value of a series 'x' at the current bar. If 'x' is not available at the current bar, it returns the optional 'default' value. This is useful for using series as conditions in 'if' statements. If 'x' is not a series or is nil, it returns 'x' or 'default' accordingly. ```lua uptrend = conditional (close > open) if get_value (uptrend) then print ("Going up") end ``` -------------------------------- ### Input Function and Types Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/input/input.md Details the `input` function, its parameters, supported input types, and default values for various settings. ```APIDOC ## input() ### Description Creates a user-modifiable value to fine-tune the instrument's evaluation and visual settings. The `input` function requires either a `type` or a `default` value to be explicitly set. ### Method `input(default, name, type, min, max, step, options)` ### Parameters #### Path Parameters * **default** (any) - Default return value for the input. The default value depends on the `type`. * **name** (string) - Name of the input. Can be a localization key. Default value is `""`. * **type** (input_type) - Input type. Default value depends on `value`. * **min** (any) - Minimal allowed value. Default value depends on `type`. * **max** (any) - Maximal allowed value. Default value depends on `type`. * **step** (any) - Value step. Default value depends on `type`. * **options** (array[integer] | array[double] | array[string]) - Array of options for selection types. Default value is `nil`. ### Input Types * **input.integer** – Integer value. * **input.double** – Numeric value. * **input.boolean** – Boolean value. Presented as a checkbox. * **input.active** – Currently not supported. * **input.candle_duration** – Currently not supported. * **input.string** – String value. * **input.integer_selection** – Selection from the predefined list of integers. * **input.double_selection** – Selection from the predefined list of numerics. * **input.string_selection** – Selection from the predefined list of strings. * **input.color** – Color value. * **input.line_width** – Line width value. * **input.plot_visibility** – Plot visibility settings. Presented as a checkbox. * **input.plot_shape_style** – Shape style value. Not supported on mobile platforms. * **input.plot_shape_size** – Shape size value. Not supported on mobile platforms. * **input.plot_shape_location** – Shape location value. Not supported on mobile platforms. ### Indicator Settings Defaults | type | default | min | max | step | |-----------------------------|-----------|-------------|------------|------------------| | **input.integer** | 0 | $-2^{63}-1$ | $2^{63}-1$ | 1 | | **input.double** | 0 | $-1.8e+308$ | $1.8e+308$ | 1 | | **input.boolean** | false | *N/A* | *N/A* | *N/A* | | **input.string** | `""` | *N/A* | *N/A* | 1 | | **input.integer_selection** | 1 | *N/A* | *N/A* | `array[integer]` | | **input.double_selection** | 1 | *N/A* | *N/A* | `array[double]` | | **input.string_selection** | 1 | *N/A* | *N/A* | `array[string]` | ### Visual Settings Defaults | type | default | |---------------------------|-----------| | **input.color** | “white” | | **input.line_width** | 1 | | **input.plot_visibility** | true | ### Example ```lua period = input (9, "front.period", input.integer, 1) source = input (1, "front.ind.source", input.string_selection, inputs.titles) plot (sma (inputs [source], period), "SMA") ``` ### Returns Same type as the `default` parameter. ``` -------------------------------- ### Advise API Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/misc/advise.md This section details how to set the current advice for an instrument based on its values. ```APIDOC ## advise(advice) ### Description Sets the current advice for the instrument based on its current and historical values. ### Method PUT ### Endpoint /quadcodescript/advise ### Parameters #### Request Body - **advice** (enum) - Required - The advice to set for the instrument. Possible values are: - **buy**: The current instrument value advises to buy the current security. - **neutral**: The current instrument value could not be used to determine the future trend for the current security. - **sell**: The current instrument value advises to sell the current security. ### Request Example ```json { "advice": "buy" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. Example: "success" #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Create and Set Series using make_series() in Lua Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/misc/make_series.md Demonstrates how to create a new series using the make_series() function and then set its initial value using the set() method. This is useful for ensuring numeric values are correctly handled as series in Quadcode Script. ```lua cg = make_series () cg:set(1) ``` -------------------------------- ### Combine Inputs for Plotting Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/input/input.md Demonstrates how to combine different inputs, such as a data source selection and a period input, to calculate and plot a Simple Moving Average (SMA). This showcases the practical application of user-defined inputs in indicator calculations. ```lua period = input (9, "front.period", input.integer, 1) source = input (1, "front.ind.source", input.string_selection, inputs.titles) plot (sma (inputs [source], period), "SMA") ``` -------------------------------- ### Create Input Group in Lua Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/input/input_group.md Demonstrates how to create an input group using the input_group function in Lua. This function allows defining a name, description, and associating various input fields like color and line width with default values and types. ```lua input_group { "Line", color = input { default = "#56CEFF", type = input.color }, width = input { default = 1, type = input.line_width} } ``` -------------------------------- ### highest(n) - Get highest value using default series Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/misc/highest.md A convenience function that returns the highest value of the default 'high' series within the last n bars. This is equivalent to calling highest(high, n) and simplifies common use cases where the 'high' price is the desired data. ```quadcodescript highest(high, n) ``` -------------------------------- ### Define String Selection Input for Source Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/input/input.md Creates a string selection input, commonly used for selecting data sources like 'close', 'open', 'high', 'low'. It takes a default selection index, a name, the input type, and an array of available titles for the selection. ```lua source = input (1, "front.ind.source", input.string_selection, inputs.titles) ``` -------------------------------- ### highest(series, n) - Get highest value in series Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/misc/highest.md Returns the highest value of the input series within the last n bars. This function is useful for identifying peak values in historical data for technical analysis or trend monitoring. It requires a series and an integer specifying the lookback period. ```quadcodescript highest(series, n) ``` -------------------------------- ### Define Integer Input Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/input/input.md Creates an integer input for user configuration. It specifies the default value, name, type, minimum, maximum, and step for the input. This is useful for parameters like periods or counts. ```lua period = input (9, "front.period", input.integer, 1) ``` -------------------------------- ### Plot Horizontal Line with hline in Lua Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/plot/hline.md Plots a horizontal line on the instrument plot using the hline function in Lua. This function takes a source value, name, color, line width, and other optional parameters to customize the line's appearance. The example demonstrates setting an overbought level and plotting a red horizontal line at that level. ```lua overbought = input(80, "Overbought") hline (overbought, "Overbought", "red") ``` -------------------------------- ### Custom Candlestick Patterns with Lua Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Plots custom candlesticks with conditional coloring based on whether the candle is bullish (close > open) or bearish. Dependencies: None. Inputs: None directly, uses open, high, low, close. Outputs: Plots custom colored candlesticks. ```lua instrument { name = "Colored Candles", short_name = "Candles", overlay = true } -- Create bullish/bearish condition is_bullish = conditional(close > open) -- Calculate candle color based on trend candle_color = iff(is_bullish, "green", "red") -- Plot custom colored candlesticks plot_candle { open = open, high = high, low = low, close = close, color = candle_color } ``` -------------------------------- ### rgb(r, g, b) Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/misc/rgb.md This function creates a color based on its red, green, and blue components. It takes three integer parameters representing the color values and returns a color object. ```APIDOC ## rgb(r, g, b) ### Description Creates a color from its individual components. ### Parameters #### Parameters - **r** (integer) - Required - The red component of the color in the range of $[0,255]$ - **g** (integer) - Required - The green component of the color in the range of $[0,255]$ - **b** (integer) - Required - The blue component of the color in the range of $[0,255]$ ### Returns color ### Response Example { "example": "color" } ``` -------------------------------- ### Mathematical Operations on Series Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Illustrates performing arithmetic operations directly on series objects for custom calculations like rate of change and momentum. It calculates and plots percentage change and momentum oscillator based on the closing price over a specified period. Requires input for 'period'. ```lua instrument { name = "Custom Momentum", short_name = "Mom", overlay = false } period = input(10, "Period", input.integer, 1) -- Calculate rate of change manually price_change = close - close[period] percent_change = (price_change / close[period]) * 100 -- Calculate momentum oscillator momentum = close / close[period] * 100 - 100 -- Plot custom calculations plot(percent_change, "% Change", "blue", 2) plot(momentum, "Momentum", "red", 2) hline(0, "Zero Line", "gray") ``` -------------------------------- ### Built-in Series for Price Calculations Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Demonstrates the use of pre-calculated price combinations (built-in series) for technical analysis. It calculates and plots moving averages for typical price (hl2), (hlc3), and (ohlc4). Requires the 'sma' function for simple moving average calculation. ```lua instrument { name = "Price Averages", short_name = "Prices", overlay = true } period = input(14, "Period", input.integer, 1) -- Use different built-in price series hl2_ma = sma(hl2, period) -- (high + low) / 2 hlc3_ma = sma(hlc3, period) -- (high + low + close) / 3 (typical price) ohlc4_ma = sma(ohlc4, period) -- (open + high + low + close) / 4 -- Plot all averages plot(hl2_ma, "HL2", "cyan", 1) plot(hlc3_ma, "HLC3", "yellow", 1) plot(ohlc4_ma, "OHLC4", "magenta", 1) ``` -------------------------------- ### Define and Plot Simple Moving Average Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/index.md This snippet demonstrates the creation of a Simple Moving Average (SMA) technical indicator. It defines the instrument's name, short name, and plotting behavior. User inputs for the period and visual style (color, width) are configured, followed by the SMA calculation and plotting. ```lua instrument { name = "Simple Moving Average", short_name = "SMA", overlay = true } period = input (14, "Period", input.integer, 1) input_group { "Line", color = input { default = "red", type = input.color }, width = input { default = 1, type = input.line_width} } ma = sma (close, period) plot (ma, "SMA", color, width) ``` -------------------------------- ### Define String Selection Input for Moving Average Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/input/input.md Creates a string selection input for choosing a moving average type. It includes a default average type, a name, the input type, and an array of available moving average titles. ```lua avg_idx = input (averages.sma, "Average", input.string_selection, averages.title) ``` -------------------------------- ### vidya(series, period) Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/averages/vidya.md Calculates the Chande volatility index dynamic moving average (VIDYA) for a given series and period. ```APIDOC ## vidya(series, period) ### Description Returns the Chande volatility index dynamic moving average of **source** for the **period** bars. [`vidya`](#qcs.fn.vidya) is based on the [`cmo`](../oscillator/cmo.md#qcs.fn.cmo). $$ \alpha &= \frac{2|\mathrm{cmo}(\mathrm{series}, \mathrm{period})|}{\mathrm{period} + 1} \\ \mathrm{vidya} &= \alpha \mathrm{source} + (1 - \alpha) \mathrm{vidya}_1 $$ ### Method N/A (This is a function, not an API endpoint) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Find Highest and Lowest Values with Lua Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Identifies the highest high and lowest low within a lookback period, useful for support and resistance levels. It plots these extreme values and their midpoint. Dependencies: None. Inputs: lookback (integer). Outputs: Plots Highest, Lowest, and Midpoint. ```lua instrument { name = "Pivot Highs and Lows", short_name = "Pivots", overlay = true } lookback = input(10, "Lookback Period", input.integer, 1) -- Find highest high and lowest low over period highest_value = highest(high, lookback) lowest_value = lowest(low, lookback) -- Plot the levels plot(highest_value, "Highest", "red", 2) plot(lowest_value, "Lowest", "green", 2) -- Calculate and plot midpoint midpoint = (highest_value + lowest_value) / 2 plot(midpoint, "Midpoint", "yellow", 1) ``` -------------------------------- ### iff(condition, then, else) Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/misc/iff.md A functional version of the if...then...else operator. It returns a series with values from 'then' or 'else' based on the 'condition'. This is a safe and concise alternative to Lua's lack of a ternary operator. ```APIDOC ## iff(condition, then, else) ### Description A functional version of the if...then...else operator. Returns the series with the values from the *then* and *else* arguments depending on the *condition*. This is the safest and the shortest version of the ternary operator (?:), as *Lua* does not support ternary operators. ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * **condition** (series or numeric) - The condition expression. Condition is considered to be false, if it is **nil**, **nan**, **false** or **0**, true otherwise. * **then** (series or numeric) - A value to be set for the current bar of the returned series, if the *condition* is true. * **else** (series or numeric) - A value to be set for the current bar of the returned series, if the *condition* is false. ### Request Example ```json { "condition": "close > open", "then": "high", "else": "low" } ``` ### Response #### Success Response (200) * **result** (series or numeric) - The returned series or numeric value based on the condition. ``` -------------------------------- ### Calculate Linear Regression with Lua Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Calculates the line of best fit for price points over a specified period using the linreg function. It plots the regression line and the closing price for comparison. Dependencies: None. Inputs: period (integer), offset (integer). Outputs: Plots LinReg and Close. ```lua instrument { name = "Linear Regression", short_name = "LinReg", overlay = true } period = input(14, "Period", input.integer, 1) offset = input(0, "Offset", input.integer) -- Calculate linear regression linreg_value = linreg(close, period, offset) -- Plot the regression line plot(linreg_value, "LinReg", "purple", 2) -- Also plot close for comparison plot(close, "Close", "white", 1) ``` -------------------------------- ### Series Type Operations in QuadScript Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/built_in_types.md Demonstrates arithmetic and comparison operations on QuadScript 'series' types. Series support standard arithmetic operators and comparison operators when operands are series or numeric values. Note that direct comparison of a series with a single value is not supported and requires 'get_value'. ```lua if get_value(open) > 10 then print ("Hooray!") end ``` -------------------------------- ### input_group Function Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/input/input_group.md Defines an input group with a name, description, and a list of inputs. The display of these inputs varies based on their type and the platform. ```APIDOC ## input_group Function ### Description Defines an input group that allows for the implicit creation of input elements. The visual representation of these inputs can differ based on their types and the target platform. ### Method N/A (This is a function definition, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```lua input_group { "My Input Group", description = "A collection of related inputs for configuration.", color = input { default = "#FF0000", type = input.color }, size = input { default = 10, type = input.number } } ``` ### Response #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### plot(series) Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/plot/plot.md Plots the input series as a linear plot with customizable styles and NaN handling. ```APIDOC ## plot(series) ### Description Plots the input series as a linear plot. ### Method POST (or relevant method for plotting functions) ### Endpoint /plot ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **series** (series[numeric]) - Required - Input series. - **name** (string) - Optional - Name of the plot. Default value is "plot(first,second)". - **color** (color) - Optional - Color of the plot. Default value is "white". - **line_width** (integer) - Optional - Width of the line. Default value is 1. - **offset** (integer) - Optional - The offset in bars to shift the line left or right. Default value is 0. - **plot_style** (plot_style) - Optional - Plot style. Not yet handled by the engine. Default value is `style.solid_line`. - **na_handling_mode** (na_mode) - Optional - The mode for handling nan data in the input series. Default value is `na_mode.restart`. ### Request Example ```json { "series": [ 10, 12, 15, 13, 11 ], "name": "My Plot", "color": "blue", "line_width": 2, "plot_style": "style.dash_line", "na_handling_mode": "na_mode.continue" } ``` ### Response #### Success Response (200) (Response details for plotting are typically visual or data-driven, not a standard JSON object. This section would describe the output, e.g., 'A plot is rendered based on the provided series and parameters.') #### Response Example (No JSON example, as the output is a plot.) ## Enums ### plot_style * **Description:** Style for the line plots. * **Enum Items:** * **style.solid_line** – Solid line. * **style.dash_line** – Dashed line. * **style.area** – Area plot. * **style.points** – Points plot. * **style.crosses** – Crosses plot. * **style.levels** – Levels plot. ### na_mode * **Description:** The way the plot handles nan values in the input series. * **Enum Items:** * **na_mode.restart** – The line is not drawn over the areas, where series values are nan * **na_mode.continue** – The line connects subsequent valid values. ``` -------------------------------- ### Calculate Commodity Channel Index (CCI) in Lua Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Calculates the Commodity Channel Index (CCI), an oscillator that measures price deviation from its statistical mean. This script allows selection of the price source and plots the CCI with reference levels. ```lua instrument { name = "CCI Oscillator", short_name = "CCI", overlay = false } period = input(20, "Period", input.integer, 1) source_idx = input(inputs.hlc3, "Source", input.string_selection, inputs.titles) -- Get selected source (typical price by default) source = inputs[source_idx] -- Calculate CCI cci_value = cci(source, period) -- Plot CCI plot(cci_value, "CCI", "orange", 2) -- Plot reference levels hline(100, "+100", "red") hline(-100, "-100", "green") hline(0, "Zero", "gray") ``` -------------------------------- ### Instrument Definition Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/index.md Defines the full and short names for a technical analysis instrument. The full name appears in the add instruments popup, while the short name is displayed on the chart. It also specifies if the instrument should be plotted as an overlay. ```lua instrument { name = "Simple Moving Average", short_name = "SMA", overlay = true } ``` -------------------------------- ### Chande Momentum Oscillator (cmo) Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/oscillator/cmo.md Calculates the Chande Momentum Oscillator (CMO) for a given input series and period. ```APIDOC ## cmo(series, period) ### Description Calculates the Chande momentum oscillator. ### Method N/A (This is a function, not an HTTP endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Function Details #### Parameters * **series** (`series`) – Input series * **period** (`integer`) – Input period #### Returns * (`series`) – The calculated Chande momentum oscillator. #### Formula $$ \delta &= \mathrm{series} - \mathrm{series}_1\\ h &= \mathrm{sum}(max(\delta, 0), \mathrm{period})\\ l &= \mathrm{sum}(max(-\delta, 0), \mathrm{period})\\ \mathrm{cmo} &= \frac{h-l}{h+l} \times 100 $$ ``` -------------------------------- ### Bollinger Bands Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Volatility indicator using moving average and standard deviation to create upper and lower bands around price. ```APIDOC ## Bollinger Bands ### Description Volatility indicator using moving average and standard deviation to create upper and lower bands around price. ### Method N/A (This is a script function, not an API endpoint) ### Endpoint N/A ### Parameters #### User Inputs - **period** (integer) - Required - The lookback period for the moving average and standard deviation. Minimum value is 1. - **mult** (double) - Required - The multiplier for the standard deviation to determine band width. Minimum value is 0.1. ### Request Example ```lua instrument { name = "Bollinger Bands", short_name = "BB", overlay = true } period = input(20, "Period", input.integer, 1) mult = input(2.0, "Multiplier", input.double, 0.1) basis = sma(close, period) dev = stdev(close, period) upper = basis + mult * dev lower = basis - mult * dev plot(basis, "Basis", "blue", 1) plot(upper, "Upper", "red", 1) plot(lower, "Lower", "green", 1) fill(upper, basis, "rgba(255,0,0,0.1)") fill(basis, lower, "rgba(0,255,0,0.1)") ``` ### Response #### Success Response (200) N/A (This is a script function's output, not an API response) #### Response Example N/A ``` -------------------------------- ### Simple Moving Average Calculation Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/index.md Calculates the Simple Moving Average (SMA) of the 'close' price series using a specified 'period'. The result is stored in the 'ma' variable. ```lua ma = sma (close, period) ``` -------------------------------- ### Calculate Simple Moving Average (SMA) in Lua Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Calculates the arithmetic mean of a series over a specified period for trend smoothing. This script defines a Simple Moving Average instrument with user-configurable period and line styling. ```lua instrument { name = "Simple Moving Average", short_name = "SMA", overlay = true } -- User input for period with minimum value of 1 period = input(14, "Period", input.integer, 1) -- Input group for line styling input_group { "Line", color = input { default = "red", type = input.color }, width = input { default = 1, type = input.line_width } } -- Calculate SMA of closing prices ma = sma(close, period) -- Plot the moving average plot(ma, "SMA", color, width) ``` -------------------------------- ### Calculate Bollinger Bands in Lua Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Calculates Bollinger Bands, a volatility indicator consisting of a middle band (SMA) and upper/lower bands based on standard deviation. It plots these bands and fills the areas between them. ```lua instrument { name = "Bollinger Bands", short_name = "BB", overlay = true } period = input(20, "Period", input.integer, 1) mult = input(2.0, "Multiplier", input.double, 0.1) -- Calculate middle band (SMA) basis = sma(close, period) -- Calculate standard deviation dev = stdev(close, period) -- Calculate upper and lower bands upper = basis + mult * dev lower = basis - mult * dev -- Plot all three bands plot(basis, "Basis", "blue", 1) plot(upper, "Upper", "red", 1) plot(lower, "Lower", "green", 1) -- Fill areas between bands fill(upper, basis, "rgba(255,0,0,0.1)") fill(basis, lower, "rgba(0,255,0,0.1)") ``` -------------------------------- ### Retrieve Security Data with `security()` Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/security/security.md The `security()` function retrieves time-series data for a given ticker ID and resolution. It requires a ticker ID and a resolution string as input and returns a Lua table containing OHLCV data and timestamps. Possible resolutions include '1s', '1m', '1H', '1D', etc. ```lua sec = security (current_ticker_id, "1s") plot(sec.close) ``` -------------------------------- ### Find Lowest Value Using Default Series (QuadScript) Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/misc/lowest.md This overload of the lowest() function finds the lowest value over the last 'n' bars using the default 'low' series. It simplifies the call when you specifically need the lowest price. It returns a series of lowest values. ```QuadScript lowest(n) ``` -------------------------------- ### Stochastic Oscillator Calculation Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/oscillator/stochastic.md Calculates the stochastic oscillator for a given series and period. ```APIDOC ## stochastic ### Description Returns the stochastic oscillator. ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Method * Not applicable (this is a function call within a script) ### Endpoint * Not applicable (this is a function call within a script) ### Function Signature `stochastic(series, period)` ### Parameters #### Parameters - **series** (`series`) - Required - Input series. - **period** (`integer`) - Required - Input period. ### Returns - **series** (`series`) - The calculated stochastic oscillator. ### Formula $$ \mathrm{stoch} = \frac{\mathrm{series}-\mathrm{lowest}(\mathrm{series}, \mathrm{period})}{\mathrm{highest}(\mathrm{series}, \mathrm{period})-\mathrm{lowest}(\mathrm{series}, \mathrm{period})} $$ ``` -------------------------------- ### value_when Function Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/misc/value_when.md The value_when function returns the value of a series at the points where a given condition is met, considering a specific occurrence. ```APIDOC ## value_when Function ### Description Returns the source series value when the condition was **true** on the n-th most recent occurrence. ### Method N/A (This is a function, not an API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Function Signature `value_when(condition, series, occurrence)` ### Parameters - **condition** (boolean or series[boolean]) - Required - The condition to check. - **series** (series) - Required - The series to return values from. - **occurrence** (integer) - Required - The occurrence number (n-th most recent). ### Returns - **series** - The series containing values where the condition was true on the specified occurrence. ``` -------------------------------- ### Simple Moving Average (SMA) Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Calculates the arithmetic mean of a series over a specified period, smoothing price data to identify trends. ```APIDOC ## Simple Moving Average (sma) ### Description Calculates the arithmetic mean of a series over a specified period, smoothing price data to identify trends. ### Method N/A (This is a script function, not an API endpoint) ### Endpoint N/A ### Parameters #### User Inputs - **period** (integer) - Required - The number of periods to include in the average calculation. Minimum value is 1. - **color** (color) - Optional - The color of the plotted moving average line. Defaults to 'red'. - **width** (line_width) - Optional - The width of the plotted moving average line. Defaults to 1. ### Request Example ```lua instrument { name = "Simple Moving Average", short_name = "SMA", overlay = true } period = input(14, "Period", input.integer, 1) input_group { "Line", color = input { default = "red", type = input.color }, width = input { default = 1, type = input.line_width } } ma = sma(close, period) plot(ma, "SMA", color, width) ``` ### Response #### Success Response (200) N/A (This is a script function's output, not an API response) #### Response Example N/A ``` -------------------------------- ### Plot Rectangle with rect() in QuadScript Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/plot/rect.md This snippet demonstrates how to use the rect() function in QuadScript to plot a rectangle. It specifies the first and second values, along with color and width. The color is dynamically set based on a condition, and the width is set to 0.8. ```lua rect { first = 0, second = ao, color = ao >= ao[1] and up_color or down_color, width = 0.8 } ``` -------------------------------- ### fill(first, second) Source: https://github.com/quadcode-tech/quadcodescript-docs/blob/master/source/api/plot/fill.md Fills the area between two series (`first` and `second`) with a specified color. Color changes can occur at the intersection points if the color parameter is modified. ```APIDOC ## fill(first, second) ### Description Fills the area between two series (`first` and `second`) with a specified color. If the `color` parameter changes between bars where `first` crosses `second`, the color change will occur at the intersection point. ### Method N/A (This appears to be a function call within a scripting language, not a typical HTTP API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```lua fill (high, low) ``` ### Response #### Success Response (200) N/A (This is a function execution, not an API response) #### Response Example N/A ``` -------------------------------- ### Exponential Moving Average (EMA) Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Calculates a weighted moving average that gives more weight to recent prices, making it more responsive to price changes than SMA. ```APIDOC ## Exponential Moving Average (ema) ### Description Calculates a weighted moving average that gives more weight to recent prices, making it more responsive to price changes than SMA. ### Method N/A (This is a script function, not an API endpoint) ### Endpoint N/A ### Parameters #### User Inputs - **fast_period** (integer) - Required - The period for the fast EMA. Minimum value is 1. - **slow_period** (integer) - Required - The period for the slow EMA. Minimum value is 1. ### Request Example ```lua instrument { name = "Dual EMA Crossover", short_name = "EMA Cross", overlay = true } fast_period = input(9, "Fast Period", input.integer, 1) slow_period = input(21, "Slow Period", input.integer, 1) fast_ema = ema(close, fast_period) slow_ema = ema(close, slow_period) plot(fast_ema, "Fast EMA", "blue", 1) plot(slow_ema, "Slow EMA", "red", 1) crossover = conditional(get_value(fast_ema) > get_value(slow_ema)) fill(fast_ema, slow_ema, iff(crossover, "rgba(0,255,0,0.2)", "rgba(255,0,0,0.2)")) ``` ### Response #### Success Response (200) N/A (This is a script function's output, not an API response) #### Response Example N/A ``` -------------------------------- ### Calculate Exponential Moving Average (EMA) Crossover in Lua Source: https://context7.com/quadcode-tech/quadcodescript-docs/llms.txt Calculates two Exponential Moving Averages (EMAs) with different periods and plots them. It also fills the area between the EMAs based on their crossover, providing a visual representation of trend changes and momentum. ```lua instrument { name = "Dual EMA Crossover", short_name = "EMA Cross", overlay = true } fast_period = input(9, "Fast Period", input.integer, 1) slow_period = input(21, "Slow Period", input.integer, 1) -- Calculate fast and slow EMAs fast_ema = ema(close, fast_period) slow_ema = ema(close, slow_period) -- Plot both EMAs with different colors plot(fast_ema, "Fast EMA", "blue", 1) plot(slow_ema, "Slow EMA", "red", 1) -- Fill area between the two EMAs crossover = conditional(get_value(fast_ema) > get_value(slow_ema)) fill(fast_ema, slow_ema, iff(crossover, "rgba(0,255,0,0.2)", "rgba(255,0,0,0.2)")) ```