Unique ID Generator for a Particular Indicator - page 3

 
Ovo: Not sure if you meant "taught". I use a few of them for debugging, but for __DATETIME__ I did not find any use yet... where are you aiming at?

Sorry, forgot you're looking for same indicator multiple windows.

I'll try thinking of something else.

===============================================

Ah-ha, I've got it. Create a function which does a decent length calculation.

Then return the time-lapse for the function to complete as your unique number.

 

TimeCurrent() is a unique number..

why don't you try to use the time you attach the indi ?? save it into a label

 
Ovo:
Because I do not trial every advice. I am picking only those that have sense.
I suggest you moderate your arrogance with people who try to help you. Such attitude is not welcomed on this forum.
 
angevoyageur:
I suggest you moderate your arrogance with people who try to help you. Such attitude is not welcomed on this forum.

i will try to stay away.
 

how could you say my idea is non sense??

time current is unique number..

try this code.. attach it on 1 chart.. but different input periode

#property strict
#property indicator_separate_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
extern int periode=4;
int OnInit()
  {
//--- indicator buffers mapping
string shortname=StringConcatenate(WindowExpertName(),"_",periode);
IndicatorShortName(shortname);
int wind=WindowFind(shortname);
string name=StringConcatenate("TIME_TAG",wind);
  if (ObjectFind(name)!=wind)
  {  ObjectCreate(name, OBJ_LABEL, wind, 0, 0);
      ObjectSet(name, OBJPROP_CORNER,2);
      ObjectSet(name, OBJPROP_XDISTANCE,2 );
      ObjectSet(name, OBJPROP_YDISTANCE,5); 
      ObjectSetText(name,DoubleToStr(TimeCurrent(),0)+DoubleToStr(wind,0) ,9,"Arial",Yellow);   
  }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
WDholic:

time current is unique number..

TimeCurrent() is not a unique number under various possible circumstances including the following:

* You are re-starting a copy of MT4 with multiple existing charts and multiple indicators attached to those charts. They will all get initialised at the same time, and see the same TimeCurrent()

*You are adding copies of the indicator during a period of thin liquidity. Depending on the type of your broker's price feed, there can be periods where there is no new tick for 5-10 seconds, and TimeCurrent() does not change. If you add new indicators during such a period then they will get the same value for TimeCurrent().

 
string name=StringConcatenate("TIME_TAG",wind);
  if (ObjectFind(name)!=wind)
  {  ObjectCreate(name, OBJ_LABEL, wind, 0, 0);
      ObjectSet(name, OBJPROP_CORNER,2);
      ObjectSet(name, OBJPROP_XDISTANCE,2 );
      ObjectSet(name, OBJPROP_YDISTANCE,5); 
      ObjectSetText(name,DoubleToStr(TimeCurrent(),0)+DoubleToStr(wind,0) ,9,"Arial",Yellow);   
  }

only adding time tag if we cant find TIME TAG label

so do not delete the label TIME TAG on deinit .. so the value never change

ok.. if we are affraid if there is no tick in 5 or 10 second.. may be we can use TimeLocal instead of Time Current

 
WDholic:

only adding time tag if we cant find TIME TAG label

so do not delete the label TIME TAG on deinit .. so the value never change

ok.. if we are affraid if there is no tick in 5 or 10 second.. may be we can use TimeLocal instead of Time Current

... There's also the problem discussed above about chart objects: if you add the indicator to a chart and then create a template, all new charts created from the template will have the same TIME_TAG value. And the use of the object only allows one instance of the indicator per chart; multiple indicators will get the same ID unless you put all possible parameters into the IndicatorShortName.

 
gchrmt4:

... There's also the problem discussed above about chart objects: if you add the indicator to a chart and then create a template, all new charts created from the template will have the same TIME_TAG value. And the use of the object only allows one instance of the indicator per chart; multiple indicators will get the same ID unless you put all possible parameters into the IndicatorShortName.


please try..

if you put 5 indi in different setting with 1 template..

ex.. time value is 111111000

in window 1 will show 1111110001
in window 2 will show 1111110002
in window 3 will show 1111110003
in window 4 will show 1111110004

in window 5 will show 1111110005

because i include the window number

ObjectSetText(name,DoubleToStr(TimeCurrent(),0)+DoubleToStr(wind,0),9,"Arial",Yellow);


multiple indicators will get the same ID unless you put all possible parameters into the IndicatorShortName.

yes.. it will be good to be considered.

but i think it will be easy for a master coder like OVO and You

 
WDholic:

if you put 5 indi in different setting with 1 template..

I don't know which version of MT4 you are using, but on v616 on my computer, WindowFind() returns -1 during OnInit(). The documentation has always said "WindowFind() returns -1 if custom indicator searches itself when init() function works."
Reason: