One "physical" bar befor date time.

To add comments, please log in or register
Thierry Ramaniraka
542
Thierry Ramaniraka  
Hello again,
I need your help (always...)
I am trying to draw VLINEs one bar (what ever the time frame is switched) before a date time (in my case, begining of each week).

datetime t = iTime(NULL,PERIOD_W1,i);
      
      int Bars_Ahead =1;
      
      if (t>0)
       {
        ObjectCreate("Line "+DoubleToStr(i,0),OBJ_VLINE,0,t,0);
        //ObjectSet("Line "+DoubleToStr(i,0),OBJPROP_TIME,t);
        ObjectSet("Line "+DoubleToStr(i,0),OBJPROP_STYLE,STYLE_SOLID);
        ObjectSet("Line "+DoubleToStr(i,0),OBJPROP_COLOR,colir);
        ObjectSet("Line "+DoubleToStr(i,0),OBJPROP_WIDTH,1);
        ObjectSet("Line "+DoubleToStr(i,0),OBJPROP_BACK,true);
        
        ObjectCreate("Line2 "+DoubleToStr(i,0),OBJ_VLINE,0, t - (Bars_Ahead * Period()*60),0);

I thought i have found the answer by

t - (Bars_Ahead * Period()*60)

But it didn't work.

Can you help me please?

Regards.

Marco vd Heijden
Moderator
12670
Marco vd Heijden  
i is nowhere to be found.
Thierry Ramaniraka
542
Thierry Ramaniraka  
Marco vd Heijden:
i is nowhere to be found.

I don't want to calculate "i".
I want the 2nd VLINE place ONE BAR before the datetime "t".

If I am on D1 PERIOD, I want the 2nd VLINE one bar (one day) before,
If I am on H4 PERIOD, I want the 2nd VLINE one bar (4 hours) before,
If I am on H1 PERIOD, I want the 2nd VLINE one bar (1 hour) before   ... etc


Mladen Rakic
159741
Mladen Rakic  
Thierry Ramaniraka:
Hello again,
I need your help (always...)
I am trying to draw VLINEs one bar (what ever the time frame is switched) before a date time (in my case, begining of each week).

I thought i have found the answer by

But it didn't work.

Can you help me please?

Regards.

ObjectCreate("Line "+DoubleToStr(i,0),OBJ_VLINE,0,Time[iBarShift(NULL,0,t)+1],0);
Thierry Ramaniraka
542
Thierry Ramaniraka  
Mladen Rakic:

Perfect (!).
Thank you very much.

EDIT :
note : in my case, it will be "Line2" instead "Line".
William Roeder
20207
William Roeder  
t - (Bars_Ahead * Period()*60)
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 weekend, market holiday (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

Use iBarShift to find the bar that started at your W1 time, as Mladen Rakic posted in #3.
Thierry Ramaniraka
542
Thierry Ramaniraka  
Mladen Rakic:

Hello again,
I am converting my indicator to the "new" standard mt4 way

//from
int start()

//to
int OnCalculate // and so on..

and

int Bars_Ahead=5;

doesn't work anymore.
It always give me a result like Bars_Ahead=1...So only one bar shifted.
Why ? It's the same code. What is wrong in this case ?

Thierry Ramaniraka
542
Thierry Ramaniraka  
PS : Here is my code :
datetime Months_Start=iTime(NULL,PERIOD_MN1,im+1);
      
datetime Months_Start_BarShift=Time[iBarShift(NULL,0,Months_Start)+Bars_Ahead];
To add comments, please log in or register