Problem with OBJPROP_TIMEFRAMES

To add comments, please log in or register
Stanislav Ivanov
6607
Stanislav Ivanov  
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);
  }
Marco vd Heijden
Moderator
12729
Marco vd Heijden  
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...
Stanislav Ivanov
6607
Stanislav Ivanov  
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) ];
  }
//+------------------------------------------------------------------+
To add comments, please log in or register