Download MetaTrader 5

Vline 50 bars after the current time/bar

To add comments, please log in or register
Thierry Ramaniraka
356
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).

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


Thank you.
Regards.
whroeder1
17828
whroeder1  
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
Taras Slobodyanik
25385
Taras Slobodyanik  
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();
Keith Watford
Moderator
12060
Keith Watford  

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();
whroeder1
17828
whroeder1  
Taras Slobodyanik:
time=Time[0]+50*PeriodSeconds();

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

Thierry Ramaniraka
356
Thierry Ramaniraka  
Hello to all.
the solutions by Taras Slobodyanik & Keith Watford are ok for me. Perfect !
Thank you very very much.
Thierry Ramaniraka
356
Thierry Ramaniraka  
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
Moderator
12060
Keith Watford  
Thierry Ramaniraka
356
Thierry Ramaniraka  
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 ?

whroeder1
17828
whroeder1  
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.
Thierry Ramaniraka
356
Thierry Ramaniraka  
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");
  }
//+------------------------------------------------------------------+

123
To add comments, please log in or register