draw rectangle everyday in Period _H1

 

Hi everyone, 


im not sure is this question is raised by other fellow community. but i would like draw rectangle everyday in Period _H1. However, my coding just stop at first rectangle on the first day.. but the switch case run perfectly if it is use to send orders. 

Any help from anyone is high appreciated.


Thank you 



void OnTick()
  {
datetime LastActiontime;

int dayOfWeek = DayOfWeek();
  
  
if((LastActiontime!=iTime(NULL,PERIOD_D1,0))&& (ObjectsTotal() <10))
{
  datetime tomorrows_time = iTime(NULL,PERIOD_D1,0) + 172799;
  double openPrice= iOpen(Symbol(),0,0);
  switch (dayOfWeek)
  {
  case 0: Comment ("it is Sunday, Go rest") ; break;
  case 1: ObjectCreate("Rectangle", OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break;
  case 2: ObjectCreate("Rectangle", OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break; 
  case 3: ObjectCreate("Rectangle", OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break;
  case 4: ObjectCreate("Rectangle", OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break;
  case 5: ObjectCreate("Rectangle", OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break;
  case 6: Comment ("It is Saturday, Go Yim Cha"); break;
  default : Comment ("No Data Found");
  }
}  

LastActiontime=iTime(NULL,PERIOD_D1,0);

}


 
 

 
  1. cklaii: i would like draw rectangle everyday in Period _H1. However, my coding just stop at first rectangle on the first day..
      case 1: ObjectCreate("Rectangle", OBJ_RECTANGLE, 
      case 2: ObjectCreate("Rectangle", OBJ_RECTANGLE, 
      case 3: ObjectCreate("Rectangle", OBJ_RECTANGLE, 
      case 4: ObjectCreate("Rectangle", OBJ_RECTANGLE, 
      case 5: ObjectCreate("Rectangle", OBJ_RECTANGLE,  

    Of course, it does. You can only create one object with a given name.

    You can't use an as-series index in names as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g. "name0",) same, existing, previous, name (e.g. "name0" now on bar one.)

    Use time (as int) or a non-series index:

    #define  SERIES(I)   (Bars - 1 - I) // As-series to non-series or back.
  2.   datetime tomorrows_time = iTime(NULL,PERIOD_D1,0) + 172799;
    That is 47.9997 hours from today,
              Find bar of the same time one day ago - MQL4 programming forum 2017.10.06
  3. and assumes that tomorrow is not a market holiday.
  4. If you want the rectangle to stop on the last bar of today use iTime(NULL,PERIOD_D1,0) + PeriodSecond(PERIOD_D1) - 1.
 
cklaii :


An example of an indicator that draws the borders of the day with the given 'Indent' - Day rectangle Indent :

Day rectangle Indent



 
William Roeder:
  1. Of course, it does. You can only create one object with a given name.

    You can't use an as-series index in names as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g. "name0",) same, existing, previous, name (e.g. "name0" now on bar one.)

    Use time (as int) or a non-series index:

  2. That is 47.9997 hours from today,
              Find bar of the same time one day ago - MQL4 programming forum 2017.10.06
  3. and assumes that tomorrow is not a market holiday.
  4. If you want the rectangle to stop on the last bar of today use iTime(NULL,PERIOD_D1,0) + PeriodSecond(PERIOD_D1) - 1.

Hi Sir,

It works!

Thank you for your swift reply and your help.

Thank you very much. 

 
William Roeder:
  1. Of course, it does. You can only create one object with a given name.

    You can't use an as-series index in names as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g. "name0",) same, existing, previous, name (e.g. "name0" now on bar one.)

    Use time (as int) or a non-series index:

  2. That is 47.9997 hours from today,
              Find bar of the same time one day ago - MQL4 programming forum 2017.10.06
  3. and assumes that tomorrow is not a market holiday.
  4. If you want the rectangle to stop on the last bar of today use iTime(NULL,PERIOD_D1,0) + PeriodSecond(PERIOD_D1) - 1.
Hi Sir, 

Very Appreciated your earlier help, after your help  i had changed the name for each rectangle name as follow, it will give me 5 rectangle.
  switch (dayOfWeek)
  {
  case 1: ObjectCreate("Draw1", OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break; 
  case 2: ObjectCreate("Draw2", OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break; 
  case 3: ObjectCreate("Draw3", OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break;
  case 4: ObjectCreate("Draw4", OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break;
  case 5: ObjectCreate("Draw5", OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break;
  case 6: Print ("It is Saturday, Go Yim Cha"); break;
  case 0: Print ("it is Sunday, Go rest") ; break;
  default : Print ("No Data Found");
  }

but when i putting a for loop to draw rectangle for every day with different names,  there are no rectangle were drawn. is there any function i miss use or missing. 
for (int i = 0; i >50; i++)
  { 
  string date = TimeToStr(Time[i],TIME_DATE);
  
  switch (dayOfWeek)
  {
  case 1: ObjectCreate("Draw1"+date, OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break; 
  case 2: ObjectCreate("Draw2"+date, OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break; 
  case 3: ObjectCreate("Draw3"+date, OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break;
  case 4: ObjectCreate("Draw4"+date, OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break;
  case 5: ObjectCreate("Draw"+date, OBJ_RECTANGLE, 0,iTime(NULL,PERIOD_D1,0), (openPrice+(200*_Point)),tomorrows_time, openPrice); break;
  case 6: Print ("It is Saturday, Go Yim Cha"); break;
  case 0: Print ("it is Sunday, Go rest") ; break;
  default : Print ("No Data Found");
  }
  }

I'm thank you in advance.