How to set the Object visibility ?.

 

I want to know how to set objects visible only for certain time frame. ex - Line 01 should be visible only for timeframes bellow 1h. 

I'm here in the Weekly timeframe, so I want to only to see monthly pivot points. Can you suggest me a function to achieve this?


currently used this functions to draw these lines. 

void Draw_PivotLevels()
  {
   if(ChartPeriod() == PERIOD_MN1)
     {
      Draw_Lines("Monthly_R1",TimeMonth,Month_R1,TimeEnd_Month,Month_R1,Monthly_Resistance,"Monthly_R1");
      Draw_Lines("Monthly_R2",TimeMonth,Month_R2,TimeEnd_Month,Month_R2,Monthly_Resistance,"Monthly_R2");
      Draw_Lines("Monthly_R3",TimeMonth,Month_R3,TimeEnd_Month,Month_R3,Monthly_Resistance,"Monthly_R3");
      Draw_Lines("Monthly_S1",TimeMonth,Month_S1,TimeEnd_Month,Month_S1,Monthly_Support,"Monthly_S1");
      Draw_Lines("Monthly_S2",TimeMonth,Month_S2,TimeEnd_Month,Month_S2,Monthly_Support,"Monthly_S2");
      Draw_Lines("Monthly_S3",TimeMonth,Month_S3,TimeEnd_Month,Month_S3,Monthly_Support,"Monthly_S3");
       
      
     }

   if(ChartPeriod() == PERIOD_W1)
     {
      Draw_Lines("Weekly_R1",TimeWeekly,Weekly_R1,TimeEnd_Month,Weekly_R1,Weekly_Resistance,"Weekly_R1");
      Draw_Lines("Weekly_R2",TimeWeekly,Weekly_R2,TimeEnd_Month,Weekly_R2,Weekly_Resistance,"Weekly_R2");
      Draw_Lines("Weekly_R3",TimeWeekly,Weekly_R3,TimeEnd_Month,Weekly_R3,Weekly_Resistance,"Weekly_R3");
      Draw_Lines("Weekly_S1",TimeWeekly,Weekly_S1,TimeEnd_Month,Weekly_S1,Weekly_Support,"Weekly_S1");
      Draw_Lines("Weekly_S2",TimeWeekly,Weekly_S2,TimeEnd_Month,Weekly_S2,Weekly_Support,"Weekly_S2");
      Draw_Lines("Weekly_S3",TimeWeekly,Weekly_S3,TimeEnd_Month,Weekly_S3,Weekly_Support,"Weekly_S3");
     }

   if(ChartPeriod() == PERIOD_D1)
     {
      Draw_Lines("Daily_R1",TimeDaily,Daily_R1,TimeEnd_Month,Daily_R1,Daily_Resistance,"Daily_R1");
      Draw_Lines("Daily_R2",TimeDaily,Daily_R2,TimeEnd_Month,Daily_R2,Daily_Resistance,"Daily_R2");
      Draw_Lines("Daily_R3",TimeDaily,Daily_R3,TimeEnd_Month,Daily_R3,Daily_Resistance,"Daily_R3");
      Draw_Lines("Daily_S1",TimeDaily,Daily_S1,TimeEnd_Month,Daily_S1,Daily_Support,"Daily_S1");
      Draw_Lines("Daily_S2",TimeDaily,Daily_S2,TimeEnd_Month,Daily_S2,Daily_Support,"Daily_S2");
      Draw_Lines("Daily_S3",TimeDaily,Daily_S3,TimeEnd_Month,Daily_S3,Daily_Support,"Daily_S3");
     }

   if(ChartPeriod() == PERIOD_H4)
     {
      Draw_Lines("H4_R1",Time4H,H4_R1,TimeEnd_Month,H4_R1,H4_Resistance,"H4_R1");
      Draw_Lines("H4_R2",Time4H,H4_R2,TimeEnd_Month,H4_R2,H4_Resistance,"H4_R2");
      Draw_Lines("H4_R3",Time4H,H4_R3,TimeEnd_Month,H4_R3,H4_Resistance,"H4_R3");
      Draw_Lines("H4_S1",Time4H,H4_S1,TimeEnd_Month,H4_S1,H4_Support,"H4_S1");
      Draw_Lines("H4_S2",Time4H,H4_S2,TimeEnd_Month,H4_S2,H4_Support,"H4_S2");
      Draw_Lines("H4_S3",Time4H,H4_S3,TimeEnd_Month,H4_S3,H4_Support,"H4_S3");
     }

   if(ChartPeriod() == PERIOD_H1)
     {
      Draw_Lines("H1_R1",Time1H,H1_R1,TimeEnd_Month,H1_R1,H1_Resistance,"H1_R1");
      Draw_Lines("H1_R2",Time1H,H1_R2,TimeEnd_Month,H1_R2,H1_Resistance,"H1_R2");
      Draw_Lines("H1_R3",Time1H,H1_R3,TimeEnd_Month,H1_R3,H1_Resistance,"H1_R3");
      Draw_Lines("H1_S1",Time1H,H1_S1,TimeEnd_Month,H1_S1,H1_Support,"H1_S1");
      Draw_Lines("H1_S2",Time1H,H1_S2,TimeEnd_Month,H1_S2,H1_Support,"H1_S2");
      Draw_Lines("H1_S3",Time1H,H1_S3,TimeEnd_Month,H1_S3,H1_Support,"H1_S3");
     }
  }
//+------------------------------------------------------------------+
//| Expert Object Function -- 00 --  Draw Vertiacl Line              |
//+------------------------------------------------------------------+
void Draw_Lines(string ObjName,datetime Time1, double price1, datetime Time2, double price2, color clr, string label)
  {
   ObjectDelete(0,ObjName);
   ObjectCreate(0,ObjName,OBJ_TREND,0,Time1,price1,Time2,price2); // Horizonal Ray Line with times
   ObjectSetInteger(0,ObjName, OBJPROP_COLOR, clr);
   ObjectSetInteger(0, ObjName, OBJPROP_WIDTH, 1);
   ObjectSetInteger(0, ObjName, OBJPROP_BACK,1);
   ObjectSetInteger(0,ObjName,OBJPROP_COLOR,clrAliceBlue);
   ObjectSetString(0,ObjName,OBJPROP_TEXT,label);
   ObjectSetInteger(0,ObjName,OBJPROP_HIDDEN,)
   
  }


 

1. Use ObjectsDeleteAll to remove objects on chart(with a prefix included to avoid affecting other objects).

2. Then you call Draw_Pivotlevels. This will force to only have the SR levels you want for that specific time frame.

3. And make sure to do this procedure in OnInit so it will be executed every time you change time frame or load a chart.

 
Yashar Seyyedin #:

1. Use ObjectsDeleteAll to remove objects on chart(with a prefix included to avoid affecting other objects).

2. Then you call Draw_Pivotlevels. This will force to only have the SR levels you want for that specific time frame.

3. And make sure to do this procedure in OnInit so it will be executed every time you change time frame or load a chart.

bro, I'm struggling with three issues now.. can you help me. 

01. is it correct comparing    if (ChartPeriod() == PPERIOD_M15) {}    or should I use another function? 

02. I used this way, but nothing happens... I checked the object list. Object has drawn, but the visibility is not correctly setup.

03. I also used Color property directly from inputs, it's not working too. the I tried  clrAliceblue. it worked btw.

input color H1_Resistance;
input color H1_Support;


   if(ChartPeriod(0) == PERIOD_M15) // H1 Pivot Levels
     {
      Draw_Lines("H1_R1",Time1H,H1_R1,TimeEnd_Month,H1_R1,H1_Resistance,"H1_R1",PERIOD_M15);
      Draw_Lines("H1_R2",Time1H,H1_R2,TimeEnd_Month,H1_R2,H1_Resistance,"H1_R2",PERIOD_M15);
      Draw_Lines("H1_R3",Time1H,H1_R3,TimeEnd_Month,H1_R3,H1_Resistance,"H1_R3",PERIOD_M15);
      Draw_Lines("H1_S1",Time1H,H1_S1,TimeEnd_Month,H1_S1,H1_Support,"H1_S1",PERIOD_M15);
      Draw_Lines("H1_S2",Time1H,H1_S2,TimeEnd_Month,H1_S2,H1_Support,"H1_S2",PERIOD_M15);
      Draw_Lines("H1_S3",Time1H,H1_S3,TimeEnd_Month,H1_S3,H1_Support,"H1_S3",PERIOD_M15);
     }
  }
//+------------------------------------------------------------------+
//| Expert Object Function -- 00 --  Draw Vertiacl Line              |
//+------------------------------------------------------------------+
void Draw_Lines(string ObjName,datetime Time1, double price1, datetime Time2, double price2, color clr, string label, ENUM_TIMEFRAMES TF)
  {
   ObjectDelete(0,ObjName);
   ObjectCreate(0,ObjName,OBJ_TREND,0,Time1,price1,Time2,price2); // Horizonal Ray Line with times
   ObjectSetInteger(0,ObjName, OBJPROP_COLOR, clr);
   ObjectSetInteger(0, ObjName, OBJPROP_WIDTH, 1);
   ObjectSetInteger(0, ObjName, OBJPROP_BACK,1);
   ObjectSetInteger(0,ObjName,OBJPROP_COLOR,clrAliceBlue);
   ObjectSetString(0,ObjName,OBJPROP_TEXT,label);
   ObjectSetInteger(0,ObjName,OBJPROP_TIMEFRAMES,TF);
   
  }
 

The way you use ChartPeriod is correct I believe.

But there is a good solution in this topic to set visibility:

Question about OBJPROP_TIMEFRAMES - How to check if a horizontal line is visible in the current timeframe
Question about OBJPROP_TIMEFRAMES - How to check if a horizontal line is visible in the current timeframe
  • 2015.01.23
  • mar
  • www.mql5.com
Hi, i made a small script which should tell me if a horizontal line is visible in the current timeframe. The line i plotted is only visible on h1 but whatever timeframe i choose i always get "true" as a response