Objects Disappear problem

 

Hi all, my objects disappear & after a few seconds or so they reappear again. If you know the problem please help.

void OnTick()
 {
  int Bottom=iLowest(Symbol(),0,MODE_LOW,75,1+40);
  
  ObjectDelete(0,"Bottom");
  ObjectCreate(0,"Bottom",OBJ_RECTANGLE,0,Time[0],Close[Bottom],0,Low[Bottom]);
  ObjectSetInteger(0,"Bottom",OBJPROP_COLOR,Green);
  
  int Top=iHighest(Symbol(),0,MODE_HIGH,75,1+40);
  
  ObjectDelete(0,"Top");
  ObjectCreate(0,"Top",OBJ_RECTANGLE,0,Time[0],Close[Top],0,High[Top]);
  ObjectSetInteger(0,"Top",OBJPROP_COLOR,Red);

 }
 
Jack Buda:

Hi all, my objects disappear & after a few seconds or so they reappear again. If you know the problem please help.

Is that a serious question????????

 
Keith Watford #:

Is that a serious question????????

Yes, if there were no problems I would've not posted at all
 
Jack Buda:

Hi all, my objects disappear & after a few seconds or so they reappear again. If you know the problem please help.

Maybe adding ChartRedraw() to the end of your code could help

https://docs.mql4.com/chart_operations/chartredraw

ChartRedraw - Chart Operations - MQL4 Reference
ChartRedraw - Chart Operations - MQL4 Reference
  • docs.mql4.com
ChartRedraw - Chart Operations - MQL4 Reference
 
Jack Buda: Hi all, my objects disappear & after a few seconds or so they reappear again. If you know the problem please help.

You are deleting and recreating your rectangle each tick. Stop doing that. Create them once at the start of a new bar.

For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
          MT4: New candle - MQL4 programming forum #3 (2014)
          MT5: Accessing variables - MQL4 programming forum #3 (2022)

I disagree with making a new bar function, because it can only be called once per tick (second call returns false). A variable can be tested multiple times.
          Running EA once at the start of each bar - MQL4 programming forum (2011)

 
R4tna C #:

Maybe adding ChartRedraw() to the end of your code could help

https://docs.mql4.com/chart_operations/chartredraw

No changes, still disappears & reappear again
 
William Roeder #:

You are deleting and recreating your rectangle each tick. Stop doing that. Create them once at the start of a new bar.

For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
          MT4: New candle - MQL4 programming forum #3 (2014)
          MT5: Accessing variables - MQL4 programming forum #3 (2022)

I disagree with making a new bar function, because it can only be called once per tick (second call returns false). A variable can be tested multiple times.
          Running EA once at the start of each bar - MQL4 programming forum (2011)

Thank You William, it works now!!!
Reason: