# Creating drawings, event markers, and bar highlights

In addition to plotting values, using the plots\[] array and UDI.onCalculate(), your UDI can also create objects on the chart:

·      Drawings, such as rectangles, lines, bar markers, trend channels etc

·      Event markers. These are markers against a specific date/time, displayed at the bottom of the chart, and automatically stacked if there are multiple markers to be displayed against the same bar.

·      Bar highlights. These change the colour of a specific bar on the chart in order to highlight it.

Note: you cannot create these objects from UDI.onInit(). If you want to create objects on start-up, do so from the first call to UDI.onCalculate() which is always issued immediately after an indicator is loaded.

For examples of the event markers and bar highlights, see the built-in Inside Bars or Outside Bars indicators.

When you create one of these objects, it stays on the chart (until your UDI is removed). You do not need to re-create the object in each call to UDI.onCalculate().

Objects are not removed if the user changes the market or timeframe of a chart. You will often want to remove and re-create objects after this sort of change, which you can detect using UDI.onContextChange().

Objects can be created from any function in your UDI, not just in response to UDI.onCalculate(). For example, you can use XMLHttpRequest to get external data, and then display that data on the chart as drawings:

```
UDI.onInit = function(data)
{
	// Make a data request 
	var xmlr = new XMLHttpRequest();
	xmlr.addEventListener("load", onMyDataLoad);
	xmlr.open("GET", "http://www.example.org/mydata");
	xmlr.send();

	// Return indicator definition
	return { … };
}

function onMyDataLoad()
{
	// Parse this.responseText and create objects…
	UDI.createDrawing(…);
}
```

Your UDI cannot see or manipulate objects which do not belong to it. You cannot modify or remove drawings, event markers, or bar highlights which were created by the user or by another indicator.


---

# 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://liquid-charts.gitbook.io/liquid-charts-api-docs/liquid-charts-pro-scripts-documentation/liquid-charts-pro-user-defined-indicators/creating-drawings-event-markers-and-bar-highlights.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.
