ObjectCreate() help!

 

Hi guys,

I am trying to get my EA to draw a rectangle a specific time. When it is that specific time, it draws it, but continuously draws it after. I get error code 4200. Any ideas to ensure it draws it once..?

 

if(DayOfWeek()==5 && Hour()==23 && Minute()==59 && Seconds()>=0)
   {
//---Drawing the W1 box for H4 timeframe       
            
       double WeeklyHigh=High[iHighest(NULL,PERIOD_H4,MODE_HIGH,30,0)];
       double WeeklyLow=Low[iLowest(NULL,PERIOD_H4,MODE_LOW,30,0)];
              
       bool createW1box=ObjectCreate("H4 W1 box",OBJ_RECTANGLE,0,Time[0],WeeklyLow,Time[30],WeeklyHigh);
        if(!createW1box) Print("Failed to create H4 W1 box, error#",GetLastError());
    }
 
Check the your object already exists before creating it : ObjectFind().
 
angevoyageur:
Check the your object already exists before creating it : ObjectFind().
Wow, thank you. Sorted.
 
if(DayOfWeek()==5 && Hour()==23 && Minute()==59 && Seconds()>=0)
  1. Seconds can never be negative.
  2. Your code assumes your broker uses NY time (UTC-4/5) + 7hours thus the market be open at server time Friday 23:59. It fails if:
    • Some broker's do many do not. UTC, market closes Friday 2100/2200. UTC+2/3 (Eastern European Time) works except when that DST differs from NY DST.
    • Some broker's do but close their charts minutes earlier (5minutes - 1 hour) because of lower liquidity.
    • Some brokers use even later server time, so there might be a partial Saturday (Sidney.)
    • There may be no ticks during the last minute.
    • If Friday is a market holiday.
  3. Wait for DOW to go down from the previous bar and then draw.
angevoyageur: Check the your object already exists before creating it : ObjectFind().
Or use my pattern If( !Object_Move(...) ){ Object_Create(...);}
Reason: