Visualization of Objects created from current TF (<=) less than TF

Thank-god Avwerosuoghene Odukudu
171
Thank-god Avwerosuoghene Odukudu  

The problem is having object created in a TF (e.g the 4H TF) to be displayed on the the 4H TF and lower TF, anything greater than the 4H TF it won't display. I know using 

OBJ_PERIOD_D1|OBJ_PERIOD_H4
// would get you to display the Object on only the 4H and Daily TF and nothing else

but getting it to display multiple objects created from different TF is somewhat is hard to solve with that, as a single function is creating all objects

// I was able to get a good result with this
bool ObjectTF_Display(string &name, ENUM_TIMEFRAME &period)
   {
       int = tfd = (int)ObjectGetInteger(0, name, OBJPROP_TIMEFRAMES);
       if(_Period <= period)
         {
            ObjectSetInteger(0, name, OBJPROP_TIMEFRAMES, tfd);
            return true;
         }
       else
         {
            ObjectSetInteger(0, name, OBJPROP_TIMEFRAMES, OBJ_NO_PERIODS);
         }   
       return false;
   }

but looking at the visualization tab, when the object is displaying, everything is marked, when the timeframe is changed to a TF it is not suppose to display, nothing is marked. Am asking if there is a better way to get my desire result. thanks

William Roeder
24704
William Roeder  
Trapheal:
The problem is having object created in a TF (e.g the 4H TF) to be displayed on the the 4H TF and lower TF,.
but getting it to display multiple objects created from different TF is somewhat is hard to solve.

Just set the display mask from the current TF and store. What's so hard?

Not compiled, not tested, just typed.

int periodToDisplay(ENUM_TIMEFRAME period=PERIOD_CURRENT{
   if(period == PERIOD_CURRENT) period=_Period;
   const static int conv[9][2]={ PERIOD_M1, OBJECT_PERIOD_M1,
                                 PERIOD_M5, OBJECT_PERIOD_M5,
                                 ⋮
                                 PERIOD_MN1, OBJECT_PERIOD_MN1 }
   int obj_per = 0;
   for(int i=8; i >= 0; --i) if( PeriodSeconds(conv[i][0]) <= PeriodSeconds(period) )
      obj_per |= conv[i][1];
   return obj_per;
}

Not compiled, not tested, just typed.

Thank-god Avwerosuoghene Odukudu
171
Thank-god Avwerosuoghene Odukudu  
William Roeder:

Just set the display mask from the current TF and store. What's so hard?

it won't be hard, would probably need to learn bit masking and Dynamic programming (was doing some research from your reply that what I came across), I have not used  such before. Thanks

McDonald Jeremiah
62
McDonald Jeremiah  
William Roeder:

Just set the display mask from the current TF and store. What's so hard ? 

No willingness to assist  
It so irrational  , Many of those so called proffessional are not willing to help 
 They only comment for Rating sake .
So sad 
William Roeder
24704
William Roeder  
Omotayo Jeremiah:
No willingness to assist  
It so irrational  , Many of those so called proffessional are not willing to help 
 They only comment for Rating sake .
So sad 

I posted working code; OP was grateful. What did you do?

Thank-god Avwerosuoghene Odukudu
171
Thank-god Avwerosuoghene Odukudu  
working framework  ... the code did not compile, but thanks to you I learnt dynamic programming , masking etc
William Roeder:

I posted working code; OP was grateful. What did you do?

The following would work if you are looking at only the default TF(monthly, weekly ... 1H, 30M, 15M ... 1M)

Note: For all Timeframe you could change the code to set all bits of TF that are lower than the current period

int periodToDisplay(ENUM_TIMEFRAMES period=PERIOD_CURRENT)
   {
      //--- using a 9 by 2 to hold the values of the TF, and the bit value of the TF in question
      const static int conv[9][2] = {
                                    {PERIOD_M1, OBJ_PERIOD_M1},
                                    {PERIOD_M5, OBJ_PERIOD_M5},
                                    {PERIOD_M15, OBJ_PERIOD_M15},
                                    {PERIOD_M30, OBJ_PERIOD_M30},
                                    {PERIOD_H1, OBJ_PERIOD_H1},
                                    {PERIOD_H4, OBJ_PERIOD_H4},
                                    {PERIOD_D1, OBJ_PERIOD_D1},
                                    {PERIOD_W1, OBJ_PERIOD_W1},
                                    {PERIOD_MN1, OBJ_PERIOD_MN1}
                                    };
      //--- the value of the Timeframe when the object would be displayed
      int obj_per = 0;
      for (int i =8; i>=0; i--)
         //--- Check the TF if it is less or equal to the period in question
         if(conv[i][0] <= period)
            obj_per |= conv[i][1];        // if it true, add the value of TF to obj_per                           
      return obj_per;                                 
   }

Hope it helps, just another option ( I prefer smaller codes)

int periodToDisplay(string &name, ENUM_TIMEFRAMES &period)
   {
     //---  Obj_Period to be returned
     long obj_per = 1;
      //--- Rather than using PERIOD_M1, you could use "1", I used that to make more readable
      for (int i = period; i>= PERIOD_M1; i/=2)
         obj_per |= (obj_per << 1);                                 
      return obj_per;                                 
   }

Note: You will need to do one or two modifications in the above code, to get the results you would be after, I could add it, but where the fun in that, post your modification lets see... cheers

McDonald Jeremiah:
No willingness to assist  
It so irrational  , Many of those so called proffessional are not willing to help 
 They only comment for Rating sake .
So sad 

Yeah, sometimes it feels that way, but imagine if he didn't or no one responded at all, he is not obliged to respond, no one is, what ever the reason someone decides to respond, it is cool to be thankful and move on, cause at the end of the day, you won't be asking for it if you don't need it, that is how I see it