Problem with OBJPROP_TIMEFRAMES

 
Hi, Im having some problems with showing certain objects only in specific TF. What happens is that it doesnt show  em at all.
string tf = "";
int timeframe = 0;
string comment="";
     switch(Period()){
      case 1: comment="BB_M1"; tf="M1";timeframe=0x0001;
      case 5: comment="BB_M5";tf="M5";timeframe =0x0002;
      case 15:comment="BB_M15";tf="M15";timeframe=0x0004;
      case 30:comment="BB_M30";tf="M30";timeframe=0x0008;
      case 60:comment="BB_H1";tf="H1";timeframe=0x0010;
      case 240: comment="BB_H4";tf="H4";timeframe=0x0020;
      case 1440: comment="BB_D1";tf="D1";timeframe=0x0040;
      case 10080: comment="BB_W1";tf="W1";timeframe=0x0080;
      case 43200: comment="BB_MN1";tf="MN1";timeframe=0x0100;
}
bool ArrowCreate(const long              chart_ID=0,           // chart's ID
                 const string            name="Arrow",         // arrow name
                 const int               sub_window=0,         // subwindow index
                 datetime                time=0,               // anchor point time
                 double                  price=0,              // anchor point price
                 const uchar             arrow_code=232,       // arrow code
                 const ENUM_ARROW_ANCHOR anchor=ANCHOR_TOP,    // anchor point position
                 const color             clr=clrRed,           // arrow color
                 const ENUM_LINE_STYLE   style=STYLE_SOLID,    // border line style
                 const int               width=2,              // arrow size
                 const bool              back=false,           // in the background
                 const bool              selection=false,      // highlight to move
                 const bool              hidden=false,          // hidden in the object list
                 const long              z_order=0,
                  int             prd = 0x01ff       // Object Visibility TimeFrame
                 )            // priority for mouse click
  {
//--- set anchor point coordinates if they are not set
//--- reset the error value
   ResetLastError();
//--- create an arrow
   if(!ObjectCreate(chart_ID,name,OBJ_ARROW,sub_window,time,price))
     {
      Print(__FUNCTION__,
            ": failed to create an arrow! Error code = ",GetLastError());
      return(false);
     }
//--- set the arrow code
   ObjectSetInteger(chart_ID,name,OBJPROP_ARROWCODE,arrow_code);
//--- set anchor type
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- set the arrow color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set the border line style
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set the arrow's size
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the arrow by mouse
//--- when creating a graphical object using ObjectCreate function, the object cannot be
//--- highlighted and moved by default. Inside this method, selection parameter
//--- is true by default making it possible to highlight and move the object
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
   //===================================
ObjectSetInteger(chart_ID,name,OBJPROP_TIMEFRAMES,prd);     
//--- successful execution
   return(true);
  }
 
Please youse the search function https://www.mql5.com/en/forum/154574#comment_3795637
Question about OBJPROP_TIMEFRAMES
Question about OBJPROP_TIMEFRAMES
  • 2015.01.23
  • www.mql5.com
Hi, I made a small script which should tell me if a horizontal line is visible in the current timeframe...
 
Marco vd Heijden:
Please youse the search function https://www.mql5.com/en/forum/154574#comment_3795637Ш

Thanks , I did search, but nothing usefull came up, this is good, but even through using that code didnt quite work, arrows are ok now, but  are  not restsricted to tf

   ObjectSetInteger(chart_ID,name,OBJPROP_TIMEFRAMES,PeriodToVisibility(0));

This is what i used, after cleaning a bit the code

int TfToPeriod(eTF tf)
  {
   return periods[tf];
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
eTF PeriodToTf(int period=PERIOD_CURRENT)
  {
   eTF tf=eTF_M1;
   while(periods[tf]!=period)++tf;
   return tf;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int PeriodToVisibility(int period=PERIOD_CURRENT)
  {
   return visibility[ PeriodToTf(period) ];
  }
//+------------------------------------------------------------------+
 
Stanislav Ivanov:

Thanks , I did search, but nothing usefull came up, this is good, but even through using that code didnt quite work, arrows are ok now, but  are  not restsricted to tf

This is what i used, after cleaning a bit the code

Hi guys,


you can use this function for MQL5 and edit as you wish for MT4:


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]);
}
 
Koros Jafarzadeh #:

Hi guys,


you can use this function for MQL5 and edit as you wish for MT4:


Thank you.