Skip to content

Visibility of Objects

Visibility of Objects

The combination of object visibility flags determines chart timeframes, where the object is visible. To set/get the value of the OBJPROP_TIMEFRAMES property, you can use functions ObjectSetInteger()/ObjectGetInteger().

IDValueDescription
OBJ_NO_PERIODS0The object is not drawn in all timeframes
OBJ_PERIOD_M10x00000001The object is drawn in 1-minute chart
OBJ_PERIOD_M20x00000002The object is drawn in 2-minute chart
OBJ_PERIOD_M30x00000004The object is drawn in 3-minute chart
OBJ_PERIOD_M40x00000008The object is drawn in 4-minute chart
OBJ_PERIOD_M50x00000010The object is drawn in 5-minute chart
OBJ_PERIOD_M60x00000020The object is drawn in 6-minute chart
OBJ_PERIOD_M100x00000040The object is drawn in 10-minute chart
OBJ_PERIOD_M120x00000080The object is drawn in 12-minute chart
OBJ_PERIOD_M150x00000100The object is drawn in 15-minute chart
OBJ_PERIOD_M200x00000200The object is drawn in 20-minute chart
OBJ_PERIOD_M300x00000400The object is drawn in 30-minute chart
OBJ_PERIOD_H10x00000800The object is drawn in 1-hour chart
OBJ_PERIOD_H20x00001000The object is drawn in 2-hour chart
OBJ_PERIOD_H30x00002000The object is drawn in 3-hour chart
OBJ_PERIOD_H40x00004000The object is drawn in 4-hour chart
OBJ_PERIOD_H60x00008000The object is drawn in 6-hour chart
OBJ_PERIOD_H80x00010000The object is drawn in 8-hour chart
OBJ_PERIOD_H120x00020000The object is drawn in 12-hour chart
OBJ_PERIOD_D10x00040000The object is drawn in day charts
OBJ_PERIOD_W10x00080000The object is drawn in week charts
OBJ_PERIOD_MN10x00100000The object is drawn in month charts
OBJ_ALL_PERIODS0x001fffffThe object is drawn in all timeframes

Visibility flags can be combined using the symbol “|”, for example, the combination of flags OBJ_PERIOD_M10|OBJ_PERIOD_H4 means that the object will be visible on the 10-minute and 4-hour timeframes.

Example:

void OnStart()
  {
//---
   string highlevel="PreviousDayHigh";
   string lowlevel="PreviousDayLow";
   double prevHigh;           // The previous day High
   double prevLow;            // The previous day Low
   double highs[],lows[];     // Arrays for High and Low

//--- Reset the last error
   ResetLastError();
//--- Get the last 2 High values on the daily timeframe
   int highsgot=CopyHigh(Symbol(),PERIOD_D1,0,2,highs);
   if(highsgot>0) // If copying was successful
     {
      Print("High prices for the last 2 days were obtained successfully");
      prevHigh=highs[0]; // The previous day High
      Print("prevHigh = ",prevHigh);
      if(ObjectFind(0,highlevel)<0) // Object with the name highlevel not found
        {
         ObjectCreate(0,highlevel,OBJ_HLINE,0,0,0); // Create the Horizontal Line object
        }
      //--- Set value for the price level for the line highlevel
      ObjectSetDouble(0,highlevel,OBJPROP_PRICE,0,prevHigh);
      //--- Set the visibility only PERIOD_M10 and PERIOD_H4
      ObjectSetInteger(0,highlevel,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M10|OBJ_PERIOD_H4);
     }
   else
     {
      Print("Could not get High prices over the past 2 days, Error = ",GetLastError());
     }

//--- Reset the last error
   ResetLastError();
//--- Get the 2 days values Low on the daily timeframe
   int lowsgot=CopyLow(Symbol(),PERIOD_D1,0,2,lows);
   if(lowsgot>0) // If copying was successful
     {
      Print("Low prices for the last 2 days were obtained successfully");
      prevLow=lows[0]; // The previous day Low
      Print("prevLow = ",prevLow);
      if(ObjectFind(0,lowlevel)<0) // Object with the name lowlevel not found
        {
         ObjectCreate(0,lowlevel,OBJ_HLINE,0,0,0); // Create the Horizontal Line object
        }
      //--- Set value for the price level for the line lowlevel
      ObjectSetDouble(0,lowlevel,OBJPROP_PRICE,0,prevLow);
      //--- Set the visibility only PERIOD_M10 and PERIOD_H4
      ObjectSetInteger(0,lowlevel,OBJPROP_TIMEFRAMES,OBJ_PERIOD_M10|OBJ_PERIOD_H4);
     }
   else Print("Could not get Low prices for the last 2 days, Error = ",GetLastError());

   ChartRedraw(0); // redraw the chart forcibly
  }

See also

PeriodSeconds, Period, Chart timeframes, Date and Time

Last updated on