# 4.1 UDI.onContextChange()

UDI.onContextChange() is called whenever there is a change to the chart such as a switch of market or timeframe. The function receives a data parameter which contains the same context information which is passed to UDI.onInit().&#x20;

For example:

```
UDI.onContextChange = function(data) 
{
	// Get current chart timeframe
	var tf = data.context.instrument.timeframe;
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sway-technologies.gitbook.io/sway-charts-pro-scripts-documentation/sway-charts-pro-user-defined-indicators/changes-to-the-chart-or-parameters/4.1-udi.oncontextchange.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
