ObjectCreate "OBJ_RECTANGLE" doesn't work in other timeframes

 

Hey Guys,

I'm programming actually a EA. I need to visualize a specified area and I want to do this with the rectangle. But the problem is:

In the initialized is the specified area right. But if I change the timeframe to e.g. M15 the rectangle doesn't appear right... - Why is that so?
Everything else works. E.g. the object lines...

Her the code:

 

   string point = ".";   

   string spacer = " ";

   string doublepoint = ":";

   string year = IntegerToString(Year());

   string month = IntegerToString(Month());

   string day = IntegerToString(Day()); 

 

   StringAdd(year, point);

   StringAdd(month, point);

   StringAdd(day, spacer);  

   StringAdd(fromH, doublepoint);

   StringAdd(toH, doublepoint); 

 

   datetime lowest = StrToTime(fromFinal);

   datetime highest = StrToTime(toFinal);      

   int leftToShiftLowest = iBarShift(NULL, 0, lowest);

   int leftToShiftHighest = iBarShift(NULL, 0, highest); 

 

   lowestPrice = iLow(NULL, 0, lowestShifts);

   highestPrice = iHigh(NULL, 0, highestShifts);

   

   span = (highestPrice - lowestPrice);

   datetime lowestBar = iTime(Symbol(), 0, lowestShifts);

   datetime highestBar = iTime(Symbol(), 0, highestShifts); 

 

ObjectCreate("Range", OBJ_RECTANGLE, 0, lowestBar, lowestPrice, highestBar, highestPrice); 

 
FrazeColder: But if I change the timeframe to e.g. M15 the rectangle doesn't appear right...
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. You created the rectangle with the chart's time. If you created it using the D1 then the end points will be midnight. Moving to a smaller timeframe means the rectangle will not be on the extreme bar. but still on midnight. Draw a trendline from the lowest to the highest and then move down one timeframe and examine it.
  3. If you want it to be correct on all timeframes, find the lowest/highest bar in the M1 so you have accurate timestamps.
Reason: