# Script Helpers

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

<a id="get_chart_data"></a>
## get_chart_data

```python
get_chart_data()
```

Get chart OHLCV data as a pandas DataFrame.

Returns the current chart's data with columns: `time`, [`open`](https://quantchartsllc.com/docs/python/py-data.md#open), [`high`](https://quantchartsllc.com/docs/python/py-data.md#high), [`low`](https://quantchartsllc.com/docs/python/py-data.md#low), [`close`](https://quantchartsllc.com/docs/python/py-data.md#close), [`volume`](https://quantchartsllc.com/docs/python/py-data.md#volume). Only available in [`@script`](https://quantchartsllc.com/docs/python/py-decorators.md#script) classes.

### Returns

pandas DataFrame

### Example

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

### Output

```text
>>> 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
```

<a id="get_symbol"></a>
## get_symbol

```python
get_symbol()
```

Get the current chart's symbol/ticker name.

### Returns

str

### Example

```python
symbol = get_symbol()
```

### Output

```text
>>> get_symbol()
'MNQM5'
```

<a id="get_timeframe"></a>
## get_timeframe

```python
get_timeframe()
```

Get the current chart timeframe.

### Returns

str

### Example

```python
tf = get_timeframe()
```

### Output

```text
>>> get_timeframe()
'5m'
```

<a id="export_csv"></a>
## export_csv

```python
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

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

<a id="export_parquet"></a>
## export_parquet

```python
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

```python
path = export_parquet(df, "processed_data")
```

### Notes

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

<a id="export_json"></a>
## export_json

```python
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

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

<a id="get_indicators"></a>
## get_indicators

```python
get_indicators()
```

Get all indicators currently running on the chart.

### Returns

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

### Example

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

### Output

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

<a id="get_indicator_values"></a>
## get_indicator_values

```python
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

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

### Output

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