Non -executing the OnDestroy() function

Created at 20 Jun 2024, 00:55
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AlgoCreators's avatar

AlgoCreators

Joined 16.01.2022

Non -executing the OnDestroy() function
20 Jun 2024, 00:55


Hi friends, I think the OnDestroy function used to be executed when the indicator was removed, but now it is not executed?
is it right?
What is the solution for running a series of commands when the indicator is removed?

 

using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.FullAccess,IsOverlay =true)]
    public class _A : Indicator
    {
        protected override void Initialize()
        {
        }

        public override void Calculate(int index)
        {
        }
        protected override void OnDestroy()
        {
             Print("OnDestroy");
             API.MessageBox.Show("OnDestroy");
        }
    }
}

 

 


@AlgoCreators
Replies

PanagiotisCharalampous
20 Jun 2024, 06:59

Hi there,

I don't think this was ever working. When the indicator is unloaded and destroyed, all references created by the indicator will do as well, same for the indicator's log. If you want to check this, write in an external file.

Best regards,

Panagiotis


@PanagiotisCharalampous

AlgoCreators
20 Jun 2024, 09:18

RE: Non -executing the OnDestroy() function

PanagiotisCharalampous said: 

Hi there,

I don't think this was ever working. When the indicator is unloaded and destroyed, all references created by the indicator will do as well, same for the indicator's log. If you want to check this, write in an external file.

Best regards,

Panagiotis

Ok, now there is no way for the indicator to clear the interactive objects it created when it is deleted.


@AlgoCreators

Spotware
21 Jun 2024, 05:22

RE: RE: Non -executing the OnDestroy() function

AlgoCreators said: 

PanagiotisCharalampous said: 

Hi there,

I don't think this was ever working. When the indicator is unloaded and destroyed, all references created by the indicator will do as well, same for the indicator's log. If you want to check this, write in an external file.

Best regards,

Panagiotis

Ok, now there is no way for the indicator to clear the interactive objects it created when it is deleted.

I am not sure what you mean, can you elaborate?


@Spotware

AlgoCreators
21 Jun 2024, 12:43

RE: RE: RE: Non -executing the OnDestroy() function

Spotware said: 

AlgoCreators said: 

PanagiotisCharalampous said: 

Hi there,

I don't think this was ever working. When the indicator is unloaded and destroyed, all references created by the indicator will do as well, same for the indicator's log. If you want to check this, write in an external file.

Best regards,

Panagiotis

Ok, now there is no way for the indicator to clear the interactive objects it created when it is deleted.

I am not sure what you mean, can you elaborate?

When my indicator is on the chart. Adds objects to the chart, such as rectangles and trend lines
These objects are interactive.
"IsInteractive = true;"
When I remove the indicator from the chart, those objects remain in the chart! If their interactive feature is false, they will be deleted automatically, but as I said, I will turn on their interactive feature.
I want to delete all the objects added to the chart when the indicator is deleted


@AlgoCreators

PanagiotisCharalampous
26 Jun 2024, 06:48 ( Updated at: 26 Jun 2024, 06:50 )

RE: RE: RE: RE: Non -executing the OnDestroy() function

AlgoCreators said: 

Spotware said: 

AlgoCreators said: 

PanagiotisCharalampous said: 

Hi there,

I don't think this was ever working. When the indicator is unloaded and destroyed, all references created by the indicator will do as well, same for the indicator's log. If you want to check this, write in an external file.

Best regards,

Panagiotis

Ok, now there is no way for the indicator to clear the interactive objects it created when it is deleted.

I am not sure what you mean, can you elaborate?

When my indicator is on the chart. Adds objects to the chart, such as rectangles and trend lines
These objects are interactive.
"IsInteractive = true;"
When I remove the indicator from the chart, those objects remain in the chart! If their interactive feature is false, they will be deleted automatically, but as I said, I will turn on their interactive feature.
I want to delete all the objects added to the chart when the indicator is deleted

Hi there,

Can you share the code you are using to delete the objects so that we can check?

Best regards,

Panagiotis


@PanagiotisCharalampous

firemyst
02 Nov 2024, 11:40 ( Updated at: 04 Nov 2024, 06:49 )

RE: RE: RE: RE: RE: Non -executing the OnDestroy() function

PanagiotisCharalampous said: 

AlgoCreators said: 

Spotware said: 

AlgoCreators said: 

PanagiotisCharalampous said: 

Hi there,

I don't think this was ever working. When the indicator is unloaded and destroyed, all references created by the indicator will do as well, same for the indicator's log. If you want to check this, write in an external file.

Best regards,

Panagiotis

Ok, now there is no way for the indicator to clear the interactive objects it created when it is deleted.

I am not sure what you mean, can you elaborate?

When my indicator is on the chart. Adds objects to the chart, such as rectangles and trend lines
These objects are interactive.
"IsInteractive = true;"
When I remove the indicator from the chart, those objects remain in the chart! If their interactive feature is false, they will be deleted automatically, but as I said, I will turn on their interactive feature.
I want to delete all the objects added to the chart when the indicator is deleted

Hi there,

Can you share the code you are using to delete the objects so that we can check?

Best regards,

Panagiotis

I posted example code here:

https://ctrader.com/forum/ctrader-algo/45312/

In the OnDestroy method, I set all the objects “IsInteractive” properties back to “false”, and the objects aren't removed from the chart.


@firemyst