How to move a vertical line x amount of bars to the right?

 
Hello, can't seem to figure out how to move a vertical line x amount of bars to the right and even into the future where bars don't exist yet. Moving it by using time data kind of works but not shown weekend data messes it up. How do I solve the weekend data issue when moving vertical line to the right? Thanks.
 
Mong00se:
Hello, can't seem to figure out how to move a vertical line x amount of bars to the right and even into the future where bars don't exist yet. Moving it by using time data kind of works but not shown weekend data messes it up. How do I solve the weekend data issue when moving vertical line to the right? Thanks.


How did you try ??

 
deVries:


How did you try ??


For example, let's take 4 hour chart. I convert 4 hours to seconds = 14400. You add that to the time of the vertical line and it moves one bar. When I need to move it 50 bars or any other number of bars, several weekends are involved along the way and that's when I can't figure out the logic how to properly ignore weekend data that is not shown on the chart. I want to be able to move it X number of bars, but not X number of seconds to the right and off the chart as well. Hope that makes it clearer.
 

You should be able to do everything you need with combinations of these:

Return time for shift value - https://docs.mql4.com/series/iTime (OR just use this in suitable situations - https://docs.mql4.com/predefined/variables/time).

Return shift for time value - https://docs.mql4.com/series/iBarShift

Return time for shift value (of object) - https://docs.mql4.com/objects/ObjectGetValueByShift

Return shift for time value (of object) - https://docs.mql4.com/objects/ObjectGetShiftByValue

Be aware that when using iBarShift() you may want to make sure you check the result each time, otherwise you might get the wrong value without realizing it. Also, there can be problems involved with using iBarShift() in backtesting.

Remember that whenever you are working on a bar which is not the current bar in the current chart then it is always best to actively specify the currency and timeperiod to avoid errors creeping in.

Eg, XYZ("EURUSD", PERIOD_H1, ... ... ..., shift) rather than just defaulting to XYZ(Symbol(), NULL, ... ... ..., shift).

 
Mong00se:

For example, let's take 4 hour chart. I convert 4 hours to seconds = 14400. You add that to the time of the vertical line and it moves one bar. When I need to move it 50 bars or any other number of bars, several weekends are involved along the way and that's when I can't figure out the logic how to properly ignore weekend data that is not shown on the chart. I want to be able to move it X number of bars, but not X number of seconds to the right and off the chart as well. Hope that makes it clearer.


You want to move a vertical line

Is the line to show every day same time ?

So is X number of bars a day ?? when it is not weekend.

 
Mong00se:

For example, let's take 4 hour chart. I convert 4 hours to seconds = 14400. You add that to the time of the vertical line and it moves one bar. When I need to move it 50 bars or any other number of bars, several weekends are involved along the way and that's when I can't figure out the logic how to properly ignore weekend data that is not shown on the chart. I want to be able to move it X number of bars, but not X number of seconds to the right and off the chart as well. Hope that makes it clearer.
In practical terms you cannot move a vertical line x bars into the future past bar 0, there are no bars to the right of bar 0 so it isn't possible. You can however, move a line to a time in the future but as time passes you will need to adjust the position of that line so that it is correct within the context of the weekends . . . how do you do that ? well that depends on what you are trying to achieve, you haven't explained that yet.
 

I use an indicator that sends rectangles off into the future something like you're talking about. Here's the two key lines of code that do that for me.

datetime timeGap = (Time[0] - Time[1]); // find time from one bar to the next

ObjectSet("tensRec"+ix,OBJPROP_TIME2,Time[0] + (timeGap*500)); // keep the rectangle stretching off screen right


And here's the entire indicator if you're interested. It will give you a nice visual of 10 pips vertically. It also includes some vertical lines the correspondent to moving averages I use.

#property indicator_chart_window

int nLines = 1000;      // Number of total rectangles to draw
datetime CurrentTime;

int start()
{  
   if (CurrentTime != Time[0])
   {
      CurrentTime = Time[0];
      double lineInterval = 0.0020;       // interval between rectangles
      double normPrice = NormalizeDouble(Close[1],3);     // Current price is rounded to nearest "10"
      datetime timeGap = (Time[0] - Time[1]); // find time from one bar to the next
      for (int ix = 0; ix < nLines; ix++)       // Loop span number of times
      {
         ObjectCreate("tensRec"+ix, OBJ_RECTANGLE, 0, Bars, normPrice+((ix-(nLines/2))*lineInterval), Time[0], normPrice+((ix-(nLines/2))*lineInterval+0.0010));  // Place half above and half below the current price
         ObjectSet("tensRec"+ix,OBJPROP_TIME2,Time[0] + (timeGap*500)); // keep the rectangle stretching off screen right
         ObjectSet("tensRec"+ix,OBJPROP_COLOR,0x101010); // Make the rectangles look better
      }
      ObjectCreate("VertLine4", OBJ_VLINE, 0, Time[4], Bid); // draw vert line
      ObjectSet("VertLine4", OBJPROP_TIME1, Time[4]);
      ObjectSet("VertLine4", OBJPROP_COLOR, 0x202020);
      ObjectSet("VertLine4", OBJPROP_BACK, true);
      
      ObjectCreate("VertLine8", OBJ_VLINE, 0, Time[8], Bid); // draw vert line
      ObjectSet("VertLine8", OBJPROP_TIME1, Time[8]);
      ObjectSet("VertLine8", OBJPROP_COLOR, 0x202020);
      ObjectSet("VertLine8", OBJPROP_BACK, true);
      
      ObjectCreate("VertLine24", OBJ_VLINE, 0, Time[24], Bid); // draw vert line
      ObjectSet("VertLine24", OBJPROP_TIME1, Time[24]);
      ObjectSet("VertLine24", OBJPROP_COLOR, 0x202020);
      ObjectSet("VertLine24", OBJPROP_BACK, true);
      return(0); //All done
   }
}
Reason: