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.

Last updated