> For the complete documentation index, see [llms.txt](https://sway-technologies.gitbook.io/sway-charts-pro-scripts-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](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).

# 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;
};
```
