Script Helpers

get_chart_data, export_csv, and other helpers available to @script files.

get_chart_data

get_chart_data()

Get chart OHLCV data as a pandas DataFrame.

Returns the current chart's data with columns: time, open, high, low, close, volume. Only available in @script classes.

Returns

pandas DataFrame

Example

from quant_charts.script_helpers import get_chart_data
df = get_chart_data()
print(df.head())

Output

>>> df.head()
         time        open        high         low       close   volume
0  2024-01-01  100.578931  102.408799  100.635641  100.993428  18702.0
1  2024-01-02  100.436809  101.137545  100.156115  100.716900  10384.0
2  2024-01-03  102.385924  102.354991  100.929226  102.012277  10404.0
3  2024-01-04  105.363522  105.860614  104.004534  105.058336  50943.0
4  2024-01-05  104.579579  104.751315  103.212360  104.590030  57926.0

get_symbol

get_symbol()

Get the current chart's symbol/ticker name.

Returns

str

Example

symbol = get_symbol()

Output

>>> get_symbol()
'MNQM5'

get_timeframe

get_timeframe()

Get the current chart timeframe.

Returns

str

Example

tf = get_timeframe()

Output

>>> get_timeframe()
'5m'

export_csv

export_csv(df, filename, subfolder?)

Export a DataFrame to a CSV file.

Parameters

  • df (DataFrame, default required): pandas DataFrame to export
  • filename (str, default required): Output filename
  • subfolder (str, default None): Subfolder within data directory

Returns

str (full file path)

Example

path = export_csv(filtered, "high_volume.csv")

export_parquet

export_parquet(df, filename, subfolder?)

Export a DataFrame to Parquet (fast, compressed).

Parameters

  • df (DataFrame, default required): pandas DataFrame to export
  • filename (str, default required): Output filename
  • subfolder (str, default None): Subfolder within data directory

Returns

str (full file path)

Example

path = export_parquet(df, "processed_data")

Notes

  • Parquet files are typically 5-10x smaller than CSV.

export_json

export_json(data, filename, subfolder?)

Export Python data to a JSON file.

Parameters

  • data (Any, default required): JSON-serializable data
  • filename (str, default required): Output filename
  • subfolder (str, default None): Subfolder within data directory

Returns

str (full file path)

Example

export_json({"sharpe": 1.42}, "results")

get_indicators

get_indicators()

Get all indicators currently running on the chart.

Returns

list[dict] with keys: name, id, parameters

Example

for ind in get_indicators():
    print(f"{ind['name']}: {ind['parameters']}")

Output

>>> get_indicators()
[{'name': 'SMA', 'id': 'sma_1', 'parameters': {'period': 20}},
 {'name': 'RSI', 'id': 'rsi_1', 'parameters': {'period': 14}}]

get_indicator_values

get_indicator_values(indicator_name)

Get output values from a running indicator.

Parameters

  • indicator_name (str, default required): Name of the indicator

Returns

pandas DataFrame or None

Example

sma_data = get_indicator_values("SMA")
if sma_data is not None:
    print(sma_data.tail())

Output

>>> get_indicator_values("SMA").tail()
       SMA(20)
14519  82.341
14520  82.297
14521  82.156
14522  82.089
14523  81.934