Remove indicator with all configurations
Remove indicator with all configurations
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
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
-
- 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
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.
The core cleans up after the restart, but not before, the simplified keeps the configs forever.
-
- 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
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?
Re: Remove indicator with all configurations
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.
-
- 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
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.
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.
Re: Remove indicator with all configurations
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();
}
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?
Re: Remove indicator with all configurations
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
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