Rectangle objects wont follow price to the last closed candle as price keeps moving - page 2

 
Ismail Hassan Lemin #:
I also find it strange. Everything seems perfect and the code looks solid from drawings to the supporting function but for some reason, the boxes won't move with price. 

prev_calculated in

   static int lastProcessedBar = 0;
   if (rates_total <= lastProcessedBar)
      return prev_calculated;
   lastProcessedBar = rates_total;

seems to be isolated from

int lastClosedBar = rates_total - 2;

and

   for (int i = startBar; i <= lastClosedBar; i++)


When I count forward (i++) in and indicator loop and return rates_total from OnCalculate(), I always reference prev_calculated--albeit through a variable. In your code, it appears that lastProcessedBar is such a variable.

 
Ryan L Johnson #:

prev_calculated in

seems to be isolated from

and


When I count forward (i++) in and indicator loop and return rates_total from OnCalculate(), I always reference prev_calculated--albeit through a variable. In your code, it appears that lastProcessedBar is such a variable.

Honestly am stuck what do you suggest I do here. I have been going round in circles missing trades because I can't ficus on the charts being at woke and coming to finish the code which won't allow me to complete it. 
 
Ismail Hassan Lemin #:
Honestly am stuck what do you suggest I do here. I have been going round in circles missing trades because I can't ficus on the charts being at woke and coming to finish the code which won't allow me to complete it. 

I copied your code and did this:

   //for (int i = startBar; i <= lastClosedBar; i++) {  // ✅ Only use closed bars
   for (int i = startBar; i <= lastProcessedBar - 2; i++) {  // ✅ Only use closed bars

and it did not fix the rectangle cleanup.

Upon testing, the indicator draws multiple rectangles immediately upon loading but then deletes any rectangle that is breached by price. Therefore, the solution would seem to be to prevent immediate drawing of multiple rectangles.

Interestingly, I now see that there is no OnInit() event handler in the indicator. I didn't even know that an indicator could load without OnInit(). This can't be good.

 
Ryan L Johnson #:

I copied your code and did this:

and it did not fix the rectangle cleanup.

Upon testing, the indicator draws multiple rectangles immediately upon loading but then deletes any rectangle that is breached by price. Therefore, the solution would seem to be to prevent immediate drawing of multiple rectangles.

Interestingly, I now see that there is no OnInit() event handler in the indicator. I didn't even know that an indicator could load without OnInit(). This can't be good.

Yes the rectangles are the foundation of the indicator. Once broken they are deleted. So on loading you will see the once that are still valid within the lookback window period. As long as they all are valid they have to show until they are either invalidated by age or price action crosses and close beyond them. It loads perfectly well and seems lightweight no lags even without the OnInit() function. Execpet for the drawing part to keep up with new bars. 
 
Ismail Hassan Lemin #:
Yes the rectangles are the foundation of the indicator. Once broken they are deleted. So on loading you will see the once that are still valid within the lookback window period. As long as they all are valid they have to show until they are either invalidated by age or price action crosses and close beyond them. It loads perfectly well and seems lightweight no lags even without the OnInit() function. Execpet for the drawing part to keep up with new bars. 

Ok. Thanks for confirming.

I'm still working on it...

 

I made a few more edits. I manually drew the blue vertical time line when the indicator loaded. Is this as intended?

IFVG

 
Ryan L Johnson #:

I made a few more edits. I manually drew the blue vertical time line when the indicator loaded. Is this as intended?

You see the blue lines were once the last closed bars I think when you started the tester. Now a few bars have printed and the line and boxes stay behind not following the price on each closed candle. 
 
Ismail Hassan Lemin #:
You see the blue lines were once the last closed bars I think when you started the tester. Now a few bars have printed and the line and boxes stay behind not following the price on each closed candle. 

I added 3 lines of code to your original code. The time1 line can be commented out or deleted. I left it in place merely for illustrative purposes.

         ulong time1 = ObjectGetInteger(0, name, OBJPROP_TIME, 0);
         ulong time2 = ObjectGetInteger(0, name, OBJPROP_TIME, 1);
         
         ObjectSetInteger(0, name, OBJPROP_TIME, 1, TimeCurrent());


IFVG_2

Files:
IFVG.mq5  27 kb
 
hey sorry I wasnt in the charts today, caught up with day job. Definitely I will check this out and place on the charts too.
 
Ismail Hassan Lemin #:
hey sorry I wasnt in the charts today, caught up with day job. Definitely I will check this out and place on the charts too.

No worries.

I never really looked into fair value gaps until you posted this. Interesting.