DeInitialization

Created at 16 Nov 2018, 05:01
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!
FR

freemangreat

Joined 16.10.2018

DeInitialization
16 Nov 2018, 05:01


Hey.
I have a real need to catch an indicator deletion (or reset) event. For example, to save temporary data produced during the work of the indicator.
The indicator class destructor does not work.
No DeInitialization procedure.
Are there any other ways to handle the indicator reset / delete event?


@freemangreat
Replies

PanagiotisCharalampous
19 Nov 2018, 11:25

Hi freemangreat,

There is no such event at the moment.

Best Regards,

Panagiotis


@PanagiotisCharalampous

freemangreat
19 Nov 2018, 17:35

Thanks for the reply Panagiotis.
Yes, I decided to cheat this limitation by creating a wait thread for event of closing.

But this only works when changing parameters / timeframes / symbols and not CloseEvent.

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

using System.Threading;
using System.Threading.Tasks;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TestWaitClose : Indicator
    {
        [Parameter(DefaultValue = 0)]
        public int RESET { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private static AutoResetEvent InitEvent;
        private string Status;
//......................................................        
        protected override void Initialize()
        {
            if(InitEvent != null)
                InitEvent.Set();    // send signal to previous instance of the indicator
            else
                InitEvent = new AutoResetEvent(false); // first start
            
            Status ="Init";
            
            startWaitResetHandler();
        }

        private async void startWaitResetHandler()
        {
            await Task.Run(() => InitEvent.WaitOne());
            
            // OnClose indicator operations ..
            Status ="DeInit";
            Console.Beep(1000, 200);
        }
//......................................................
        public override void Calculate(int index) 
        { 
            ChartObjects.DrawText("StatusInfo", Status, StaticPosition.Left);
        }
    }
}

 


@freemangreat

firemyst
28 Jan 2022, 03:56

RE:

PanagiotisCharalampous said:

Hi freemangreat,

There is no such event at the moment.

Best Regards,

Panagiotis

@PanagiotisCharalampous:

Are there any plans for this?

We have a Panel control we place on the chart. This panel control can have multiple indicators that add their own button/checkbox/whatever to the panel. When the indicator is deleted from the chart, the whole Panel Control is removed as there appears to be no way to execute code when an indicator is deleted nor does there appear to be any sort of "indicatorremoved" event for the chart so we can tell our panel control to remove the child control that was added by the now-deleted indicator.


@firemyst

PanagiotisCharalampous
28 Jan 2022, 07:33

Hi firemyst,

This will be introduced in 4.2.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

firemyst
28 Jan 2022, 07:43

RE:

PanagiotisCharalampous said:

Hi firemyst,

This will be introduced in 4.2.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Awesome! Thank you for the update!


@firemyst