Object visibility on different timeframes

 

Hi,

the drawn object shall be visible in different timeframes. If it is drawn in a weekly timeframe it shall be visible in weekly and all smaller timeframes. If it is drawn in daily timeframe, it shall be visible in daily and all smaller timeframes and so on.

I use:

int visibility;

ObjectSet("Weekly Level high "+ variable, OBJPROP_TIMEFRAMES,visibility);

What is the right value for the variable "visbility"?

In the documentation I found:

OBJPROP_TIMEFRAMES
15 int Value can be one or combination (bitwise addition) of object visibility constants to set/get timeframe object property.


Thank you a lot in advance!


 
Just add the values of the timeframes you want, it's all in the Documentation so if you wanted M1 and M5 you add 0x0001 and 0x0002 to get 0x0003
 
RaptorUK:
Just add the values of the timeframes you want, it's all in the Documentation so if you wanted M1 and M5 you add 0x0001 and 0x0002 to get 0x0003

That´s bitwise addition??? Man, you are so smart you even could talk to R2D2 :P

Thank you!


edit:

Did you know 0x0001 and 0x0002 is equal 0x0003

but

0x0040 + 0x0080 + 0x0020 + 0x0010 + 0x0008 + 0x0004 + 0x0002 + 0x0001 is equal 0xFF ?!?


I still do not know how to ad bitwise, but thank god, google does, lol :D

 
APeng:

tTat´s bitwise addition??? Man, you are so smart you even could talk to R2D2 :P

Thank you!

If you look at the HEX numbers used to represent the TimePeriods they do not have overlapping binary representations, as an example, OBJ_PERIOD_H1 & OBJ_PERIOD_D1 values 0x0010 & 0x0040 or 16 & 64 or 00010000 & 01000000 in binary. I use something like this to store several possible bits of information about candles in a int array which can then be accessed very, very quickly and easily manipulated using boolean logic to get at the specific information needed.
 
RaptorUK:
If you look at the HEX numbers used to represent the TimePeriods they do not have overlapping binary representations, as an example, OBJ_PERIOD_H1 & OBJ_PERIOD_D1 values 0x0010 & 0x0040 or 16 & 64 or 00010000 & 01000000 in binary. I use something like this to store several possible bits of information about candles in a int array which can then be accessed very, very quickly and easily manipulated using boolean logic to get at the specific information needed.


amazing


edit: need to make clear that I seriously find that amazing. It´s far beyound my coding skills.

 
APeng:

Hi,

the drawn object shall be visible in different timeframes. If it is drawn in a weekly timeframe it shall be visible in weekly and all smaller timeframes. If it is drawn in daily timeframe, it shall be visible in daily and all smaller timeframes and so on.

I use:

What is the right value for the variable "visbility"?

In the documentation I found:

OBJPROP_TIMEFRAMES
15 int Value can be one or combination (bitwise addition) of object visibility constants to set/get timeframe object property.


Thank you a lot in advance!


have fun :)


int PeriodToVisibility(ENUM_TIMEFRAMES VisibilityPeriod)
{
   int i;
   int periods[]    = { PERIOD_M1, PERIOD_M2, PERIOD_M3, PERIOD_M4, PERIOD_M5, PERIOD_M6, PERIOD_M10, PERIOD_M12, PERIOD_M15, PERIOD_M20, PERIOD_M30, PERIOD_H1, PERIOD_H2, PERIOD_H3, PERIOD_H4, PERIOD_H6, PERIOD_H8, PERIOD_H12, PERIOD_D1, PERIOD_W1, PERIOD_MN1};
   int visibility[] = { OBJ_PERIOD_M1, OBJ_PERIOD_M2, OBJ_PERIOD_M3, OBJ_PERIOD_M4, OBJ_PERIOD_M5, OBJ_PERIOD_M6, OBJ_PERIOD_M10, OBJ_PERIOD_M12, OBJ_PERIOD_M15, OBJ_PERIOD_M20, OBJ_PERIOD_M30, OBJ_PERIOD_H1, OBJ_PERIOD_H2, OBJ_PERIOD_H3, OBJ_PERIOD_H4, OBJ_PERIOD_H6, OBJ_PERIOD_H8, OBJ_PERIOD_H12, OBJ_PERIOD_D1, OBJ_PERIOD_W1, OBJ_PERIOD_MN1};
   if (VisibilityPeriod == PERIOD_CURRENT)
      VisibilityPeriod = Period();
   for (i = 0; i < 21; i++)
      if (VisibilityPeriod == periods[i])
         break;
   return(visibility[i]);
}