Init() and DeInit() execution sequence - page 25

 
Alexey Viktorov:

Dimitri you seem to me to be an educated programmer. You have not been taught the rules of etiquette in programming?

For the rest you can write like in old mql4 with the possibility of array overruns and other assumptions. You get an error in response... Well, flag it back... let's go on, we don't have time... And then you run into a problem that is not worth a damn in a stricter language and start to blame developers...

Christ is risen.


When you create an existing object nothing terrible happens, nothing terrible happens either, the object is just not created and that's all.
 
Nikolai Semko:

I think I will also add a solution later, but without using global variables of the terminal and files, and with possibility to apply several identical indicators in one window.

By the way, it's an interesting task to write a function that produces a different value for each different set of indicator input parameters.

The first thing that came to mind was through the ChartSaveTemplate.


Giving up global - apparently resources.

 
fxsaber:

By the way, it's an interesting task to write a function that produces a different value for each different set of indicator input parameters.

The first thing that came to mind was through ChartSaveTemplate.


To give up the global ones - apparently resources.


Of course resources - they seem to me the best solution, because they're invisible, unlike global terminal variables and files, and fast. Also, you can pass arrays through them, just like through files, but faster, because everything happens in RAM. They also belong to the window, not to the terminal, as in the case of the global. Moreover, you can create one resource for all the same indicators in a window.

No, I think that ChartSaveTemplate is too cumbersome. I will try to create a common resource for all instances of one indicator without using global changes, templates and files.

 
Nikolai Semko:

My example was created to show the problem of an ambiguous sequence of the Unit of the new TF and the Unit of the old TF, not as a solution.

You just bypassed the problem, not solved it.
In my example, it's just important to delete the object in the Unit of the old TF in any case, including when the TF is changed, and in the Unit of the new object it is created again.

If the sequence is first Deunit of the old TF, then Unit of the new TF, as it should be logically. Then the object is deleted and then created again.

If the sequence is first the Unit of the new TF and then the Deunit of the old TF, then the object is simply modified when you try to create it in the Unit, because it is not yet deleted. And then it is deleted by the Deunit of the old TF. This is the bug.

That was the point of this example - to show what any programmer who has not read this branch and is unaware of this "feature" may encounter.
This example was not meant to be a solution. As variants of the solution are presented here and here. I think I will also add a solution later, but without using global variables and files of the terminal and for this solution to work even if several identical indicators are set in one window. Have you tried to solve this problem? Or you are only capable of finding errors in other people's code, especially when they are not there.


It's a sin to swear today, but I feel like it...

I couldn't even read your nonsense to the end.

I repeat once again do not make a problem where there is no problem.

The answer to all your questions in your code was here

Alexey Viktorov:

What's the point of using primitive two-way street example?

You'd better use an example of almost-correct code.

I wasn't counting on absoluteness.

That's all ... go away Satan, do not lead me to sin.

 
Alexey Viktorov:

It's a sin to swear today, but I feel like it...

I couldn't even read your nonsense to the end.

I'll say it again, don't put the problem where it doesn't exist.

The answer to all the questions in your code was here.

I wasn't counting on absolutes.

That's it...Satan be gone, don't lead us to sin.


Oh, man, you need to go to another forum. Where psychotherapists give advice. I understand, I understand. Childhood love deficit, want attention and love. I'm sorry. I'll help you if you need anything. You can write me in person. I'm not kidding.

And you'd better not do it here, because we've amused people too much.

THE RESURRECTION INDEED!

 

Forum on trading, automated trading systems and trading strategy testing

Sequence of execution of Init() and DeInit()

fxsaber, 2017.04.14 13:52

A little tipster's tipster's tipster's tipster's tipster's tipster's tipster's tipster's tipster's tipster's tipster
No complaints to the developers.
Cool how-to! Run
#property indicator_chart_window
#property indicator_plots   0

void OnInit()
{
  Print(__FUNCTION__ + (string)ChartIndicatorGet(0, 0, MQLInfoString(MQL_PROGRAM_NAME)));
}

void OnDeinit( const int Reason )
{
  Print(__FUNCTION__);
}

int OnCalculate (const int rates_total,
                 const int prev_calculated,
                 const int begin,
                 const double& price[])
{
  return(rates_total);
}

And switch the TF. There will not be a single Deinit! All indicators will run unnoticed, eating up resources. And just wanted to

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

fxsaber, 2016.09.22 16:14

How do I know my handle on a chart in an indicator? ThroughChartIndicatorName is not suitable as it returns a short name. And with the same name may be already running the same indicator with different input parameters.

It turns out that if you want to know its handle, you must use ChartIndicatorGet, but as shown in the example above, it will be a real problem - the indicator will be uninstallable.

What a bummer.


I cannot even do this.

Forum on trading, automated trading systems & strategy testing

Bugs, bugs, questions

fxsaber, 2016.09.23 10:20

How do I know myINDICATOR_SHORTNAME? IndicatorGet*-functions do not exist!

No way to know from the indicator which sub_window it hit. It's just a bunch of bummers.

 
fxsaber:

You can't tell from the indicator which sub_window it's in. It's just a bunch of bummers.

https://www.mql5.com/ru/docs/chart_operations/chartwindowfind
Документация по MQL5: Операции с графиками / ChartWindowFind
Документация по MQL5: Операции с графиками / ChartWindowFind
  • www.mql5.com
Операции с графиками / ChartWindowFind - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
fxsaber:
A cool little tiphack! Run

And switch the TF. There won't be a single Deinit! All indicators will run stealthily, eating up resources. And I only wanted to

It turns out that if you want to know its handle, you should use ChartIndicatorGet, but, as shown in the example above, it will be a real bummer - the indicator will be undeletable.

It will become unrecoverable.

I have faced such a thing. The developers advised to read the help more carefully as there is an example:

//+------------------------------------------------------------------+ 
//| Script program start function                                    | 
//+------------------------------------------------------------------+ 
void OnStart() 
  { 
   //--- количество окон на графике (всегда есть хотя бы одно главное окно) 
   int windows=(int)ChartGetInteger(0,CHART_WINDOWS_TOTAL); 
   //--- про ходим по окнам 
   for(int w=0;w<windows;w++) 
     { 
      //--- сколько индикаторов в данном окне/подокне 
      int total=ChartIndicatorsTotal(0,w); 
      //--- переберем все индикаторы в окне 

      for(int i=0;i<total;i++) 
        { 
         //--- получим короткое имя индикатора 
         string name=ChartIndicatorName(0,w,i); 
         //--- получим хэндл индикатора 
         int handle=ChartIndicatorGet(0,w,name); 
         //--- выведем в журнал 
         PrintFormat("Window=%d,  index=%d,  Name=%s,  handle=%d",w,i,name,handle); 
         //--- обязательно освобождаем хендл индикатора, как только он становится ненужным 
         IndicatorRelease(handle); 
        } 
     } 
  }
However, they then added that the behaviour would be "corrected". But apparently it is still being adjusted.
 
Alexey Kozitsyn:
https://www.mql5.com/ru/docs/chart_operations/chartwindowfind

Thanks, but there's the same limitation - there's no way without a shortname (how do you know it?).

 
Alexey Kozitsyn:

I've come across something like this. The developers advised me to read the help more carefully as there is an example:

However, then added that the behaviour would be "corrected". But apparently it's still being adjusted.

This really helped, Thank you!

The main thing is not to do IndicatorRelease in Deinit.

Reason: