Remove indicator with all configurations

Custom indicators, trading strategies, data export and recording and more...
zcsoka
Posts: 290
Joined: Thu Dec 19, 2019 7:50 pm
Has thanked: 2 times
Been thanked: 28 times

Remove indicator with all configurations

Post by zcsoka » Thu Jun 17, 2021 1:56 pm

Greetings,

If I add indicators on onInstrumentAdded (register on the API), I seem not to be able to completely remove them on onInstrumentRemoved. The indicator config remains in the config file and when I open the Bookmap again, the configs of the removed instruments remain in the config panel (where I can enable the line and widget visibility). 
What is the way to fully remove a registered indicator when it is not needed anymore?

Many thanks in advance

Svyatoslav
Site Admin
Posts: 278
Joined: Mon Jun 11, 2018 11:44 am
Has thanked: 2 times
Been thanked: 31 times

Re: Remove indicator with all configurations

Post by Svyatoslav » Thu Jun 17, 2021 3:13 pm

Core or simplified API?

zcsoka
Posts: 290
Joined: Thu Dec 19, 2019 7:50 pm
Has thanked: 2 times
Been thanked: 28 times

Re: Remove indicator with all configurations

Post by zcsoka » Thu Jun 17, 2021 3:51 pm

Both, as a matter of fact I have implemented a similar indicator for both using multi instruments, so I would be interested in both ways. 
The core cleans up after the restart, but not before, the simplified keeps the configs forever.

Svyatoslav
Site Admin
Posts: 278
Joined: Mon Jun 11, 2018 11:44 am
Has thanked: 2 times
Been thanked: 31 times

Re: Remove indicator with all configurations

Post by Svyatoslav » Thu Jun 17, 2021 5:33 pm

Could you please clarify what you mean by "remains in config". Do you mean that it does not forget last used enabled/disabled state? Or do you actually observe menu items remaining there despite you removing those?

zcsoka
Posts: 290
Joined: Thu Dec 19, 2019 7:50 pm
Has thanked: 2 times
Been thanked: 28 times

Re: Remove indicator with all configurations

Post by zcsoka » Thu Jun 17, 2021 6:24 pm

Please see the image below. The NQM21 was unsubscribed, I am not registering it anymore in my code when I initialise at stratup time, but the indicator NQM21 is stuck on the list of indicators. On the event of onInstrumentRemoved I would like to remove it from this list as well.

RemoveProblem.png
RemoveProblem.png (99.31 KiB) Viewed 3106 times
 

Svyatoslav
Site Admin
Posts: 278
Joined: Mon Jun 11, 2018 11:44 am
Has thanked: 2 times
Been thanked: 31 times

Re: Remove indicator with all configurations

Post by Svyatoslav » Fri Jun 18, 2021 8:05 am

Hi. I'm not sure I get it right, but let me try to explain based on what I see, and feel free to correct me if I'm wrong:
1. You register an indicator with AliasFilter that matches all instruments (or at least matches whatever is on your screen and NQM21). Thus bookmap creates your indicator instances for every alias (those are independent)
2. You remove NQM21 instrument. Maybe you also change what AliasFilter responds (if you do - don't, if you need to change it you have to un-register, change, and then re-register, it's not allowed to change AliasFilter for active indicator), but you don't unregister the indicator via a message. As a result, bookmap removes an instance from NQM21 chart, but you still have an indicator named NQM21 for every other instrument that passed AliasFilter.

If the above is true - I do not see a bug. You need to use AliasFilter in order to restrict your NQM21 indicator to NQM21 instrument only. If you want NQM21 indicator to be rendered on other charts (which is fine), you must later remove it from other charts yourself (unregister indicator), because from Bookmap standpoint that is just a name - the only thing linking indicator to a charts is AliasFilter.

If you unsubscribe from an instrument and resubscribe again, all your indicators will follow their AliasFilters, so if they match - instance will be created. If that's not something you want - unregister/adjust accordingly.

Not sure if that answers your question, so if not - please describe what you are doing and what's happening in details, i.e. step by step.

zcsoka
Posts: 290
Joined: Thu Dec 19, 2019 7:50 pm
Has thanked: 2 times
Been thanked: 28 times

Re: Remove indicator with all configurations

Post by zcsoka » Fri Jun 18, 2021 10:04 am

Code: Select all

 
public void onInstrumentRemoved(String alias) {
Log.info("Removing indicator due to instrument removal " + alias + ". The new list is: " + settings.enabledInstruments);
indicators.remove(alias);
settings.enabledInstruments = settings.enabledInstruments.replace(alias, "");
api.setSettings(settings);
onSettingsUpdated();
}
Hi,

Thanks for the detailed description. I wanted to unregister the indicator, but I did not find in the docs how to do that.
I might have found what the issue is. Using simplified, when I add a completely new instrument, the 
public void onInstrumentAdded(InstrumentInfo info)
is called and I see my log statements in the overridden function.

When I click the x next to the instrument, the confirmation window comes to unsubscribe. When I do that, in the log I see the system log OnInstrumentRemoved,  but my log statements in the overridden method are not printed, what makes me think, that the overridden method is not called. Am I doing something wrong?

 

zcsoka
Posts: 290
Joined: Thu Dec 19, 2019 7:50 pm
Has thanked: 2 times
Been thanked: 28 times

Re: Remove indicator with all configurations

Post by zcsoka » Mon Jun 21, 2021 9:10 am

Hi Svyatoslav, 

I have created a workaround, but before publishing it, I wanted to check with you if you could confirm if the onInstrumentRemoved is working correctly with the simplified API implementing MultiInstrumentListener. 

Regards

Post Reply