[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 397

 
ilunga:

Good afternoon. Question about OBJPROP_TIMEFRAMES property identifier of graphical objects... I wrote this script to create a Horizontal Line graphical object (see below).

Question: Why, although the ObjectSet(object_name,OBJPROP_TIMEFRAMES,PERIOD_H1) function explicitly states that the object should display ONLY on timeframe H1, the created object also displays on timeframes (at least) H4, M30, M15.


https://docs.mql4.com/ru/constants/objects/visible


Another constant is OBJ_PERIOD_H1


Yes, thank you it helped... But I'd like to understand why ObjectSet(object_name,OBJPROP_TIMEFRAMES,PERIOD_H1) option doesn't work (as it should)? Is it glitches in the language itself?
 
DanLett:

i.e. while the current bar[0] is being built the previous one is being defined


As an option:

datetime last_time;   // глобальная переменная

...

int start()
{
   if (last_time != Time[0])
   {
      // Ура, новый бар!
      last_time = Time[0];      // запоминаем новый бар
      //... ваши расчеты с плюсованием
   }
   
... дальше работаем
 
7777877:

Yes, thanks helped... But I want to understand why ObjectSet(object_name,OBJPROP_TIMEFRAMES,PERIOD_H1) doesn't work (like it should)? Is it glitches in the language itself?

De facto both PERIOD_H1 and OBJ_PERIOD_H1 are just an alpha substitution of some numeric value.

OBJ_PERIOD_H1 = 0x0010 (for current build) = 0001 0000 (binary)

PERIOD_H1 = 60 (for this build) = 0011 1100 (binary)


As it is easy to replace, you accidentally put 4 timeframes instead of one - H4, H1, M30 and M15


And instead of calling ObjectSet(object_name,OBJPROP_TIMEFRAMES,0x0010) (which you wanted to do) you have called

ObjectSet(object_name,OBJPROP_TIMEFRAMES,0x3C).

 
datetime last_time;   // глобальная переменная

...

int start()
{
   if (last_time != Time[0])
   {
      // Ура, новый бар!
      last_time = Time[0];      // запоминаем новый бар
      if(close[1]>open[1]) 
xBost_b=xBost_b+((close[1]-low[1])*10000);
   }

what is Time[0] and how does it affect 1 time plus ?! just a little confused...

 
DanLett:

what is Time[0] and how does it affect 1 time plus ?! just a little confused...

Time[0] is the opening time of the most recent (current) bar. As soon as a new bar comes, it changes.

Type Time in MetaEditor and press F1 for details

 
ilunga:

Time[0] is the opening time of the most recent (current) bar. As soon as a new bar comes, it changes.

Type Time in MetaEditor and press F1 for details

Will read it now! thank you very much!
 
DanLett:
I'll read it now! Thank you very much!

Then don't forget to look at iTime()
 
   datetime last_time;   // глобальная переменная
  int xBost_b;
  int xBost_s;
double hi=High[1];
double op=Open[1];
double cl=Close[1];
double lo=Low[1];
int Sum_xb;
int Sum_xs;
 
 if (last_time != Time[0])
   {
      // Ура, новый бар!
      last_time = Time[0];      // запоминаем новый бар
      if(Close[1]>Open[1]) 
xBost_b=(hi-cl)*10000;
Sum_xb=Sum_xb+xBost_b;<---------не плюсует,выдает такое же число как и xBost

      if(Close[1]<Open[1])
 xBost_s=(cl-lo)*10000; 
Sum_xs=Sum_xs+xBost_s;    
Comment("\n kolvo_b=",xBost_b,"\n Sum_xb=",Sum_xb,"\n kolvo_s=",xBost_s,"\n Sum_xs=",Sum_xs);

   }
how do you make it give you a plus every time?
 
DanLett:
how do I make it add up every time???
Theglobal variables should be outside all functions. Send the sums there too. or declare these variables as static
 
DanLett:
how do I make it add every time???
Take last_time out of start() and declare it static
Reason: