Take a look at this example and make the necessary changes to the code:
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//--- удалим подокно ChartIndicatorDelete(0,subwindow_ID,"Subwindow");
//--- удалим с главного окна индикатор PriceChannel: его короткое имя с параметрами по умолчанию - "Price Channel(22)"ChartIndicatorDelete(0,0,"Price Channel(22)");
}
//+------------------------------------------------------------------+
I think everything is very clearly commented out in the code. The first line of the code deletes the subwindow, and the second line deletes the indicator from the main window, you just need to correctly write the short name of the indicator to be deleted.
AkaEdie #: This is if the indicator has a name, but if it is added by handle, it is not so simple
I don't understand, but what prevents you from writing (inserting) this short name in the code of the indicator you are using? For example, as it is done in the indicator code of Artyom Trishkin, only replacing the name "Net Volume" with some of your own:
I don't understand, but what prevents you from writing (inserting) this short name in the code of the indicator you are using? For example, as it is done in the indicator code of Artyom Trishkin, but replacing the name "Net Volume" with some of your own:
Regards, Vladimir.
It is written in the indicator, not at the moment of its placement on the chart.
That's what I mean, I use alligator indicator, how can I connect it to the chart if I write this line of code in the indictor code? Through inlude? Will there be no conflict?
AkaEdie alligator indicator, how can I connect it to the chart if I write this line of code in the indictor code? Through inlude? Won't there be a conflict?
I'm interested in this question only now, when I looked through the documentation more carefully....
It turns out that there is no other way but with a double loop.
I got this...
Code
long chartID = ChartID();
//---
/*******************Script program start function********************/
voidOnStart()
{
int totalWnd = (int)ChartGetInteger(chartID, CHART_WINDOWS_TOTAL);
for(int w = 0; w < totalWnd; w++)
{
int totalInd = ChartIndicatorsTotal(chartID, w);
for(int i = 0; i < totalInd; i++)
{
string indName = ChartIndicatorName(chartID, w, i);
int handle = ChartIndicatorGet(chartID, w, indName);
Print("INDICATOR_SHORTNAME ", indName, " handle ", handle);
}
}
}/******************************************************************/
/********************************************************************\
Result
2024.04.2009:59:54.730 Test (EURUSD,H1) INDICATOR_SHORTNAME MA(10) handle 102024.04.2009:59:54.730 Test (EURUSD,H1) INDICATOR_SHORTNAME SAR(0.02,0.20) handle 112024.04.2009:59:54.730 Test (EURUSD,H1) INDICATOR_SHORTNAME MACD(12,26,9) handle 122024.04.2009:59:54.731 Test (EURUSD,H1) INDICATOR_SHORTNAME Stoch(5,3,3) handle 13
So it turns out that if you need to loop through all the available indicators to reach the desired one by checking the handles and when you find it, just interrupt the loop and delete the indicator by this short name.
Another option, easier... If you know that the indicator is in the main window, then the cycle of searching indicator windows can be removed.
Here I have added an indicator programmatically
long chartID = ChartID();
//---/*******************Script program start function********************/voidOnStart()
{
int hAll = iAlligator(_Symbol, PERIOD_CURRENT, 13, 8, 8, 5, 5, 3, MODE_SMA, PRICE_MEDIAN);
ChartIndicatorAdd(chartID, 0, hAll);
Print("hAll ", hAll);int totalWnd = (int)ChartGetInteger(chartID, CHART_WINDOWS_TOTAL);
for(int w = 0; w < totalWnd; w++)
{
int totalInd = ChartIndicatorsTotal(chartID, w);
for(int i = 0; i < totalInd; i++)
{
string indName = ChartIndicatorName(chartID, w, i);
int handle = ChartIndicatorGet(chartID, w, indName);
Print("INDICATOR_SHORTNAME ", indName, " handle ", handle);
}
}
}/******************************************************************/
The result is as follows
2024.04.2010:20:59.131 Test (EURUSD,H1) hAll 102024.04.2010:20:59.131 Test (EURUSD,H1) INDICATOR_SHORTNAME MA(10) handle 112024.04.2010:20:59.131 Test (EURUSD,H1) INDICATOR_SHORTNAME SAR(0.02,0.20) handle 122024.04.2010:20:59.131 Test (EURUSD,H1) INDICATOR_SHORTNAMEAlligator(13,8,5) handle 102024.04.2010:20:59.131 Test (EURUSD,H1) INDICATOR_SHORTNAME MACD(12,26,9) handle 132024.04.2010:20:59.131 Test (EURUSD,H1) INDICATOR_SHORTNAME Stoch(5,3,3) handle 14
I figured it out, I need to add this code to the place where I need to remove all indicators
long chartID = ChartID(); // Получаем идентификатор текущего графикаint totalWnd = (int)ChartGetInteger(chartID, CHART_WINDOWS_TOTAL); // Получаем общее количество подокон на графике// Перебираем каждое подокноfor (int w = 0; w < totalWnd; w++) {
int totalInd = ChartIndicatorsTotal(chartID, w); // Получаем количество индикаторов в текущем подокне// Перебираем каждый индикатор в текущем подокнеfor (int i = totalInd - 1; i >= 0; i--) {
string indName = ChartIndicatorName(chartID, w, i); // Получаем имя индикатора по индексу// Удаляем индикатор по имениif (!ChartIndicatorDelete(chartID, w, indName)) {
Print("Ошибка удаления индикатора ", indName, " с графика: ", GetLastError());
} else {
Print("Удален индикатор: ", indName);
}
}
}
Thank you very much, it is possible to remove all indicators before adding the EA to the chart from OnInit, as well as during deinitialisation in OnDeinit of the EA, it would be good to add an article on this subject. I envy your experience.
I don't understand, what prevents you from writing (inserting) this short name in the code of the indicator you are using? For example, as it is done in the indicator code of Artyom Trishkin, only replacing the name "Net Volume" with some of your own:
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Do you need to use the handle? There is a function that removes an indicator with the specified name from the specified chart window .
IndicatorDelete(int,const string) - Price Charts - Standard Library - MQL5 Reference - Reference Manual for MetaTrader 5 Algorithmic/Automated Trading Language for MetaTrader 5
Regards, Vladimir.
it works only in the indicator code or I don't know how to do it, please give me an example of adding and removing an alligator.
I think everything is very clearly commented out in the code. The first line of the code deletes the subwindow, and the second line deletes the indicator from the main window, you just need to correctly write the short name of the indicator to be deleted.
Regards, Vladimir.
This is if the indicator has a name, but if it is added by handle, it is not so simple
I don't understand, but what prevents you from writing (inserting) this short name in the code of the indicator you are using? For example, as it is done in the indicator code of Artyom Trishkin, only replacing the name "Net Volume" with some of your own:
Regards, Vladimir.
I don't understand, but what prevents you from writing (inserting) this short name in the code of the indicator you are using? For example, as it is done in the indicator code of Artyom Trishkin, but replacing the name "Net Volume" with some of your own:
Regards, Vladimir.
It is written in the indicator, not at the moment of its placement on the chart.
I'm interested in this question only now, when I looked through the documentation more carefully....
It turns out that there is no other way but with a double loop.
I got this...
Code
Result
So it turns out that if you need to loop through all the available indicators to reach the desired one by checking the handles and when you find it, just interrupt the loop and delete the indicator by this short name.
Another option, easier... If you know that the indicator is in the main window, then the cycle of searching indicator windows can be removed.
Here I have added an indicator programmatically
The result is as follows
I figured it out, I need to add this code to the place where I need to remove all indicators
Thank you very much, it is possible to remove all indicators before adding the EA to the chart from OnInit, as well as during deinitialisation in OnDeinit of the EA, it would be good to add an article on this subject. I envy your experience.
This is prescribed in the indicator, not at the moment of its placement on the chart.
Hi Alexey, I don't know, but I think I have described everything clearly and understandably in my message:
Forum on Trading, Automated Trading Systems and Testing Trading Strategies
Questions from MQL5 MT5 MetaTrader 5 beginners
MrBrooklin, 2024.04.20 05:04 AM
I don't understand, what prevents you from writing (inserting) this short name in the code of the indicator you are using? For example, as it is done in the indicator code of Artyom Trishkin, only replacing the name "Net Volume" with some of your own:
Regards, Vladimir.
I asked for the deletion code, not the function of renaming the indicator.
taking into account that there can be many indicators, the code of comrade Alexey Viktorov was more useful.
Vladimir.