Vline 50 bars after the current time/bar

 
Hi there,
I come to you to ask you :
How can i draw a VLINE on the 50th (or Xth) bar in the future.
In my case, i want to put the Vline 50 bars after the current time/bar (what ever the timeframe, always the 50th bar in the future).

ObjectCreate("My_Vline", OBJ_VLINE, 0, TIME ???, 0);


Thank you.
Regards.
 
Thierry Ramaniraka: How can i draw a VLINE on the 50th (or Xth) bar in the future.
You can't, only on a specific datetime. This assumes every bar every exists. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekends and market holidays (country and broker specific.) requires knowledge of when your broker stops and starts (not necessary the same as the market.)
          "Free-of-Holes" Charts - MQL4 Articles
          No candle if open = close ? - MQL4 and MetaTrader 4 - MQL4 programming forum
 
Thierry Ramaniraka:
Hi there,
I come to you to ask you :
How can i draw a VLINE on the 50th (or Xth) bar in the future.
In my case, i want to put the Vline 50 bars after the current time/bar (what ever the timeframe, always the 50th bar in the future).
time=Time[0]+50*PeriodSeconds();
 

Taras Slobodyanik:

time=Time[0]+50*PeriodSeconds();



Yes, but you would need to check it every time a new bar is opened.

Find the iBarShift() of the bar with the line

Say it's the next bar, the shift will be 1 so

time=Time[0]+(50-1)*PeriodSeconds();
 
Taras Slobodyanik:
time=Time[0]+50*PeriodSeconds();

That assumes that all bars will exist. Go re-read my answer #1

 
Hello to all.
the solutions by Taras Slobodyanik & Keith Watford are ok for me. Perfect !
Thank you very very much.
 
If let the M1 timeframe going, the shifted VLINE does not refresh its place ; it's approaching...
How can I make it refresh itself please ?

Regards.
 
 
Keith Watford:
Use ObjectMove()

Hello,
thank you.

I tried this, no error when compiling, but still not refreshing

if(ObjectFind("Current_Time2_Vline") < 0){
  ObjectCreate("Current_Time2_Vline", OBJ_VLINE, 0, time2, 0);
  ObjectMove("Current_Time2_Vline", 0, time2, 0);
  }
  else
  {
  ObjectMove("Current_Time2_Vline", 0, time2, 0);
  }

Can you tel me the way to make it work please ?

 
Thierry Ramaniraka:


I tried this, no error when compiling, but still not refreshing

if(ObjectFind("Current_Time2_Vline") < 0){
  ObjectCreate("Current_Time2_Vline", OBJ_VLINE, 0, time2, 0);
  ObjectMove("Current_Time2_Vline", 0, time2, 0);
}else{
  ObjectMove("Current_Time2_Vline", 0, time2, 0);
}

Can you tel me the way to make it work please ?

  1. Equivalent code
    /*void*/  ObjectCreate("Current_Time2_Vline", OBJ_VLINE, 0, time2, 0);
              ObjectMove(  "Current_Time2_Vline",            0, time2, 0);
    Or efficient
    if(!      ObjectMove(  "Current_Time2_Vline",            0, time2, 0) )
    /*void*/  ObjectCreate("Current_Time2_Vline", OBJ_VLINE, 0, time2, 0);
    

  2. Post all the relevant code. The problem is elsewhere.
 
whroeder1:
  1. Equivalent codeOr efficient
  2. Post all the relevant code. The problem is elsewhere.

Your solution deosn't seems to work in my case.

Here below is the whole code.
Thank you very much for your help.

#property version   "1.0"
#property indicator_chart_window
          

color Current_Time_Color = Red;
       
datetime  Current_Time = TimeCurrent();

extern int Datas_BarShift_Time = 35;
extern int Datas_BarShift_Time2 = 60;

int time2=Time[0]+(Datas_BarShift_Time-1)*PeriodSeconds();
int time3=Time[0]+(Datas_BarShift_Time2-1)*PeriodSeconds();

 
int init()
  {
  
   return(0);
  }
  
//-------------------------------------------------------- 
  
int deinit()
  {
   DeleteObjects();

   return(0);
  }
//--------------------------------------------------------- 

int start()
 {
 
  ObjectCreate("Current_Time_Vline", OBJ_VLINE, 0, Current_Time, 0);
  ObjectSet("Current_Time_Vline",OBJPROP_COLOR,Current_Time_Color);  
  ObjectSet("Current_Time_Vline",OBJPROP_BACK,true);   
  ObjectSet("Current_Time_Vline",OBJPROP_SELECTABLE,false); 
  
  if(! ObjectMove("Current_Time2_Vline", 0, time2, 0))
/*void*/
  ObjectCreate("Current_Time2_Vline", OBJ_VLINE, 0, time2, 0);
  ObjectSet("Current_Time2_Vline",OBJPROP_COLOR,Current_Time_Color);  
  ObjectSet("Current_Time2_Vline",OBJPROP_BACK,true);   
  ObjectSet("Current_Time2_Vline",OBJPROP_SELECTABLE,false); 
  
  /**/
  ObjectCreate("Current_Time3_Vline", OBJ_VLINE, 0, time3, 0);
  ObjectSet("Current_Time3_Vline",OBJPROP_COLOR,Current_Time_Color);  
  ObjectSet("Current_Time3_Vline",OBJPROP_BACK,true);   
  ObjectSet("Current_Time3_Vline",OBJPROP_SELECTABLE,false);
  

   return(0);
}

//--------------------------------------------------------
 

 
//--------------------------------------------------------
void DeleteObjects()
 {   
     
    ObjectDelete("Current_Time_Vline");
    ObjectDelete("Current_Time2_Vline");
    ObjectDelete("Current_Time3_Vline");
  }
//+------------------------------------------------------------------+

Reason: