It is as expected, a handle to the indicator in memory to be used in code when creating, and when you add it to the chart it takes another handle for terminal use.
Thanks for your comment, but something is wrong here.
ChartIndicatorGet behaves differently in OnDeinit when changing timeframe or removing the EA.
int handle = INVALID_HANDLE;
intOnInit()
{
Print("\nOnInit");
handle=iMA(Symbol(),Period(),20,0,MODE_SMA,PRICE_CLOSE);
Print("Indicator handle is ",handle);
ChartIndicatorAdd(0, 0, handle);
Print("Indicator added with handle ",handle);
int handleOnChart=ChartIndicatorGet(0,0,ChartIndicatorName(0,0,0));
Print("Handle found on chart is ",handleOnChart);
returnINIT_SUCCEEDED;
}
voidOnDeinit(constint reason)
{
Print("\nOnDeinit");
int handleOnChart=ChartIndicatorGet(0,0,ChartIndicatorName(0,0,0));
Print("Handle found on chart is ",handleOnChart);
IndicatorRelease(handle);
}
Nr 1:
Nr 2:
In case I missed something, I'd like to apologize in advance ;D
I twicked a bit your code and now it works. The problem was that the number of indicators changes as you start removing them, so you need to start removing from the last one to the first one, in reverse order:
int num_windows = (int)ChartGetInteger(0, CHART_WINDOWS_TOTAL);
for (int window = num_windows - 1; window > -1; window--)
{
int numIndicators = ChartIndicatorsTotal(0, window);
for (int index = numIndicators; index >= 0; index--)
{
ResetLastError();
string name = ChartIndicatorName(0, window, index);
if (GetLastError() != 0)
{
PrintFormat("ChartIndicatorName error: %d", GetLastError());
ResetLastError();
}
if (!ChartIndicatorDelete(0, window, name))
{
if (GetLastError() != 0)
{
PrintFormat("Delete indicator error: %d", GetLastError());
ResetLastError();
}
}
else
{
Print("Delete indicator with handle:", name);
}
}
}
int total = (int)ChartGetInteger(0, CHART_WINDOWS_TOTAL);
for(int i = total - 1; i >= 0; i--)
{
for(int k = ChartIndicatorsTotal(0, i) - 1; k >= 0; k--)
{
string name = ChartIndicatorName(0, i, k);
ChartIndicatorDelete(0, i, name);
}
}
Just a little clean way of doing it. Similar to what Juan Calvo did.
Looping over the list of indicator names in inverse order - instead of continuing to make it properly work with indicator handles (which never worked, despite the many, many hours of work) - was such an amazing ease of pain! Thank you!
(P.S.: This thread should be somehow pinned / marked as important for deep dive learning MQL5 ;-))
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.
Thanks man, but I add the indicator to the chart.
I want to make the problem a little clearer.
Change from H1 timeframe to M30.
Result:
I want to make the problem a little clearer.
Change from H1 timeframe to M30.
Thanks for your comment, but something is wrong here.
ChartIndicatorGet behaves differently in OnDeinit when changing timeframe or removing the EA.
Nr 1:
Nr 2:
In case I missed something, I'd like to apologize in advance ;D
I twicked a bit your code and now it works. The problem was that the number of indicators changes as you start removing them, so you need to start removing from the last one to the first one, in reverse order:
Just a little clean way of doing it.
Similar to what Juan Calvo did.
Looping over the list of indicator names in inverse order - instead of continuing to make it properly work with indicator handles (which never worked, despite the many, many hours of work) - was such an amazing ease of pain! Thank you!
(P.S.: This thread should be somehow pinned / marked as important for deep dive learning MQL5 ;-))