Week Open Price for indicator

Back to topics list To post a new topic, please log in or register
avatar
37
Max-Enrik 2016.05.29 14:40
 

Hi,

I try below code for Week Open Price on Indicator. I have not any error code but below code does not shows me correct time.

if(TimeDayOfWeek(Time[i]) != TimeDayOfWeek(Time[i+1]))

Any help would be better.

Best,

Max 

avatar
37
Max-Enrik 2016.05.29 15:30 #
 

Thanks for your reply.

I use below code for Day Open Price.

if(TimeDay(Time[i]) != TimeDay(Time[i+1]))

It does work for me. Even Month and Year, but Week is not.

 

Thanks,

Max 

avatar
13009
WHRoeder 2016.05.29 16:14 #
 
Max-Enrik: I try below code for Week Open Price on Indicator. I have not any error code but below code does not shows me correct time.
if(TimeDayOfWeek(Time[i]) != TimeDayOfWeek(Time[i+1]))

Your code asks if bar i is the start of a new day not a new week. You want to find the "Week Open Price," here are three ways:

  1. double wop = iOpen(NULL, PERIOD_W1, 0)
  2. datetime  BOW = iTime(NULL, PERIOD_W1, 0);
    int      iBOW = iBarShift(NULL,0, BOW);
    double   wop  = Open[iBow];
  3. Find the first bar of the new week: the DOW(Monday) < DOW(Friday)
    int i=0;
    while( TimeDayOfWeek(Time[i]) >= TimeDayOfWeek(Time[i+1]) ) ++i;
    double wop = Open[i];

avatar
37
Max-Enrik 2016.05.29 17:04 #
 

WHRoeder:

int i=0;
while( TimeDayOfWeek(Time[i]) >= TimeDayOfWeek(Time[i+1]) ) ++i;
double wop = Open[i];

That was awesome. Yeah, I found what I want. Thank you so much - @WHRoeder

Everything OK at any TimeFrames. But indicator Opened wrong Price & Time when I want to use it at the "W1 / Weekly" TimeFrame.


Best,

Max 

Back to topics list  

To add comments, please log in or register