vertical line after a specific number of bars

 

hi

am traying to make a simple indicator that put a vertical line after a numbr of bars.....example.....i will enter the date and time and the indicator will draw a vertical line after 25 bar

my code is as follow.......but need some help to finish it......

 **************

this is the last code that i arrived at after times of trials

still have a problem with it 

if i put 40 in the barsahead setting  the indicator will draw the line after 19 bars of the startdate

any help will be welcomed

//+------------------------------------------------------------------+
//|                                                            vertical.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
extern string LineName="VERTECALLINE";
extern datetime  StartTime=D'2010.05.19 00:00';
extern int BarsAhead=20;
extern color LineColor=Red; 
extern int LineStyle=STYLE_DASH;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {

   ObjectDelete("OBJ_VLINE");

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   
   
  
   int D=StartTime;
int i=BarsAhead;i=i*10;
  
//      ObjectCreate(LineName, OBJ_VLINE, "2009/11/04","15:00", Bid);
   ObjectCreate(LineName, OBJ_VLINE, TIME_DATE,D+Bars*i+Period()*60,High[2]); 
      ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
      ObjectSet(LineName, OBJPROP_COLOR, LineColor);
        
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+

 

 

 

 

if i use this code

 

ObjectCreate(LineName, OBJ_VLINE, 0,Time[i]+Period()*60, High[0] ); 

and put the

(extern int BarsAhead=)

to equal 3   the line will be drawn 3 bar befor the last bar in the chart

so what is the problem?any one can help plz 

 
abdI do you want to set a fixed datetime point like 24.11.2010 00:00 and set BarsAHead. Indicator shall draw 1 vertical line from 24.11.2010 00:00 + BarsAhead or till last bar many?
 

hi ..thanks for u my frind......this what i need

indicator shall draw 1 vertical line from 24.11.2010 00:00 + BarsAhead

' but the startdate and barsahead is avariables that i could change from the indicator settings

 
ObjectCreate(LineName, OBJ_VLINE, 0,StartTime + (BarsAhead * Period()*60), High[0] ); 

ho BTW

ObjectDelete(LineName);

& not

ObjectDelete("OBJ_VLINE");

 

hi

thanks for u qjol for ur help

after using ur code......i enter 20 in the BarsAhead setting  but the indicator draw the line after 14 bar......may be because the indicator count the holidays.......... 

 

what's value u used for starttime & what TF u using to check

 

the time frame is daily.......the value for starttime is as in the original code post #1

by the way i removed this part of the code 

   int D=StartTime;
int i=BarsAhead;i=i*10;

because i think it's not useful 

 

because there is 3 weekends between StartTime & StartTime + (BarsAhead * Period()*60) = missing 6 days

 

hi qjol

i want the indicator to ignore weekend..and count bars only....if i give the indicator a starttime.and 15 in barsahead

the indicator will draw the Vline after 15 bars ignoring the weekend

could that be done in mql4?

 
abdI:

hi qjol

i want the indicator to ignore weekend..and count bars only....if i give the indicator a starttime.and 15 in barsahead

the indicator will draw the Vline after 15 bars ignoring the weekend

could that be done in mql4?


of course

u have to find how many weekends u have & add it to BarsAhead * Period()*60

Reason: