Skip to main content

Cleanup function for custom indicators

As far as I am aware, there is no function that gets called when an (custom) indicator gets removed from a chart. This means there’s no way to clean up chart objects that were created by the indicator and they are left on the chart until the user cleans them up manually or pressing hide first before removing the custom indicator. Either calling the already existing OnHide method on removal, or a new method named Cleanup would solve this. A bare bones example might look like:

class MyCustomIndicator extends IndicatorImplementation {
    private objects: string[] = []

    public Init(): void {
        // initialize
    }

    public Cleanup(): void {
        // called when indicator is removed from chart
        for (let id of this.objects) {
            this.api.RemoveChartObject(id)
        }
    }

    public Calculate(index: number): void {
        let name = getUniqueName()
        this.api.CreateChartObject(name, ...)
        // save name for clean up later
        this.objects.push(name)
    }
}

This is a minor annoyance but can cause performance issues if objects aren’t cleaned up and continue to accumulate.

How does this impact your experience?
4 comments

Comments4

  • Diana Zhoshko

    Team•

    Dec 11, 2025

    My apologies

    Our developers told us that this method already exists; it is called “Done.”

    public override Done(): void { // here we can clean up resources on indicator removal }

    • User

      •

      Dec 11, 2025

      Oh okay! I did see that function in the docs but the docs only talk about it being called after finishing calculations, not when the indicator is removed so it was not clear to me it did what I wanted. But yes, that does do what I was requesting. Thank you.

      • Diana Zhoshko

        Team•

        Dec 15, 2025

        I was glad to assist you!

  • Diana Zhoshko

    Team•

    Dec 11, 2025

    Hi @User ,

    Your request is important to us, and we've sent it to our dev team.
    While we can’t promise immediate implementation, they will thoughtfully evaluate it for future improvements.