The OnBarUpdate will successfully draw the rectangle after the bar has closed so this is working as expected.
The OnMarketData, which is much different from the OnMarketUpdate does begin drawing the rectangle as expected, but continues modifying the the rectangle after the bar closed.
Comment