Creating a robot - page 7

 
Vladimir M.:
I usually clear the handle and the calculation part in OnDeinit and everything is removed. The object is not an indicator.

https://www.mql5.com/ru/docs/chart_operations/chartindicatordelete

"Removing an indicator from a chart does not mean that the calculation part of the indicator will also be removed from the terminal memory. To release the indicator handle, use IndicatorRelease() function."

Yes, Vladimir, I've already done that and written about it before, but the result is still the same.

Regards, Vladimir.

Forum on trading, automated trading systems and strategy testing

New trading robot

MrBrooklin, 2020.09.28 10:38

I have been solving this problem for more than an hour. I wanted to create and display ZigZagColor indicator on the chart at the Expert Advisor startup. It was done in int OnInit:

   handle_iCustom=iCustom(m_symbol.Name(),Period(),"Examples\\ZigzagColor",
                          Inp_ZZ_Depth,
                          Inp_ZZ_Deviation,
                          Inp_ZZ_Backstep);
   ChartIndicatorAdd(ChartID(),0,handle_iCustom);

The indicator was created and displayed. Now I need the indicator to be deleted after the Expert Advisor is removed. I am writing it:

void OnDeinit(const int reason)
  {
//---
   IndicatorRelease(handle_iCustom);
   ObjectsDeleteAll(0,"Examples\\ZigzagColor");
  }

But the indicator is not removed. I have sorted everything out. I have cleaned the handle and applied the delete function. I wonder what is the reason why it is not uninstalling.

Regards, Vladimir.


 
Alekseu Fedotov:

Remove the indicator from the chart with the function


ChartIndicatorDelete(

long chart_id, // chart ID

int sub_window // number of the subwindow

const string indicator_shortname // short indicator name

);

Thanks, Alexey, I will try it with a clear head tomorrow, I'm already confused by the information I've got. As they say, I'll sleep better in the morning!

I now have another thing that puzzled and surprised me a lot. I tried to clear the chart with the script developed by Vladimir Karputov, but this script deleted absolutely everything except for the custom indicator ZigzagColor! Tried to remove a simple ZigZag with the same script, it doesn't remove either! It's a mystery...

Regards, Vladimir.

 
MrBrooklin:

Thanks, Alexey, tomorrow I'll try it with a clear head, as I'm already in a mess of information. As the saying goes - wiser in the morning!

Now there is another thing that puzzled me a lot and surprised me. I tried to clear the chart with the script developed by Vladimir Karputov, but this script deleted absolutely everything except for the custom indicator ZigzagColor! Tried to remove a simple ZigZag with the same script, it doesn't remove either! It's a mystery...

Regards, Vladimir.

Try this script


#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int window=ChartWindowFind(0,"ZigzagColor");
   bool res=ChartIndicatorDelete(0,window,"ZigzagColor");
//--- проанализируем результат вызова ChartIndicatorDelete()
   if(!res)
     {
      PrintFormat("Не удалось удалить индикатор ZigzagColor с окна #%d. Код ошибки %d",
                  window,GetLastError());
     }
  }


 

short name ZigzagColor - and this is the default, if you set it differently you need to write those digits

2020.09.29 03:41:36.604 IndicatorDelete (XAUUSD,M30)    ZigZag(12,5,3)

and that's exactly what you need to put in

ZigZag(12,5,3)
 
SanAlex:

short name ZigzagColor - and this is the default, if you set it differently you need to write those digits

and that is how it should be spelled

or you can change the indicator itself - give a simpler name

//--- name for DataWindow and indicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"ZigZag("+(string)InpDepth+","+(string)InpDeviation+","+(string)InpBackstep+")");
   PlotIndexSetString(0,PLOT_LABEL,"ZigzagColor");
//--- set an empty value

for example

//--- name for DataWindow and indicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"ZigZag");
   PlotIndexSetString(0,PLOT_LABEL,"ZigzagColor");
//--- set an empty value

-----------------------------------------------

i already showed you the script - if this script is attached to a chart and you don't give an indicator name, it will work without deleting any indicator - but it will write in the Expert Advisor window which indicators are available

https://c.mql5.com/3/332/IndicatorDelete.mq5

This is what I have

CS      0       03:41:36.549    IndicatorDelete (XAUUSD,M30)    EWO(5,35)
DF      0       03:41:36.604    IndicatorDelete (XAUUSD,M30)    ZigZag(12,5,3)
KR      0       03:41:36.626    IndicatorDelete (XAUUSD,M30)    LeMan_BrainTrend1Sig
FE      0       03:41:36.646    IndicatorDelete (XAUUSD,M30)    Hline VSC
RN      0       03:41:36.666    IndicatorDelete (XAUUSD,M30)    Pivot Lines TimeZone
KG      0       03:41:36.686    IndicatorDelete (XAUUSD,M30)    Line through two fractals
DL      0       03:41:36.706    IndicatorDelete (XAUUSD,M30)    sanbox
 
Alekseu Fedotov:

Try this script

Good day everyone!

Aleksey, I have applied your script. I got error code 4115. I found what it means in the handbook:

ERR_CHART_INDICATOR_CANNOT_DEL

4115

Error when deleting the indicator from the chart


Regards, Vladimir.

Документация по MQL5: Константы, перечисления и структуры / Коды ошибок и предупреждений
Документация по MQL5: Константы, перечисления и структуры / Коды ошибок и предупреждений
  • www.mql5.com
Коды ошибок и предупреждений - Константы, перечисления и структуры - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
SanAlex:

or you can also change the indicator itself by giving it a simpler name

like this

-----------------------------------------------

I have already downloaded the script - if this script is attached to a chart and you do not give an indicator name it will work without deleting any Indicator - but it will write in the Expert Advisor window which Indictors are present

https://c.mql5.com/3/332/IndicatorDelete.mq5

This is what I have!

Hello! I have implemented your script. Two indicators appeared in the Experts tab : Volumes and ZigZag (80,20,0). It is indeed so, only the ZigZag indicator is written without Color for some reason.

Regards, Vladimir.

 
Alekseu Fedotov:

Try this script

MrBrooklin:

Good day everyone!

Aleksey, applied your script. I got error code 4115.

Regards, Vladimir.

I have to be more careful.

bool  ChartIndicatorDelete( 
   long           chart_id,              // идентификатор графика 
   int            sub_window             // номер подокна 
   const string   indicator_shortname    // короткое имя индикатора 
   );

Indicator name and indicator short name often do not coincide.

 
MrBrooklin:

Hello! I have applied your script. Two indicators appeared in the Experts tab: Volumes and ZigZag (80,20,0). It is indeed so, only the ZigZag indicator is written without Color for some reason.

Sincerely, Vladimir.

So, you have to write it like this - ZigZag (80,20,0).

It will definitely be deleted in this case.

-----------------

but withoutColor

because this is how it is written in the indicator

IndicatorSetString(INDICATOR_SHORTNAME,"ZigZag("+(string)InpDepth+","+(string)InpDeviation+","+(string)InpBackstep+")");

 
SanAlex:

You have to write it like this - ZigZag (80,20,0)

The ZigZag will definitely be deleted.

-----------------

but withoutColor

because this is how it is written in the indicator

If you change the settings, you need to add those numbers that you have specified in the Indicator

for example

ZigZag(12,5,3)