getting the close for a specific bar

 

I need a way to get the close and open from specific bars each day.

the close from the M5 bar with time of 9:55

the open from the M5 bar with time of 00:00

I know this has something to do with ibarshift but I'm not sure how to

write the code out.


Thanks

Tony

 

datetime time=D'2008.02.22 00:00';
int shift=iBarShift(NULL,PERIOD_M5,time);
double opening_price = iOpen(NULL,PERIOD_M5,shift);

time=D'2008.02.22 09:55';
shift=iBarShift(NULL,PERIOD_M5,time);
double closing_price = iClose(NULL,PERIOD_M5,shift);

Comment("\nOpening Price : ", opening_price,
"\nClosing Price : ", closing_price);

 
PipRaider:

datetime time=D'2008.02.22 00:00';
int shift=iBarShift(NULL,PERIOD_M5,time);
double opening_price = iOpen(NULL,PERIOD_M5,shift);

time=D'2008.02.22 09:55';
shift=iBarShift(NULL,PERIOD_M5,time);
double closing_price = iClose(NULL,PERIOD_M5,shift);

Comment("\nOpening Price : ", opening_price,
"\nClosing Price : ", closing_price);


This can only shows the price at 2008.02.22, what if we need it for everyday at this time? thank you very much.
 
double value1[];

double value2[];

ArrayResize(value1, Bars);

ArrayResize(value2, Bars);

for(int i = Bars-1; i >= 0; i--){
  
  if(TimeHour(Time[i]) == 9 && TimeMinute(Time[i]) == 55) value1[i] = Close[i]);
  
  if(TimeHour(Time[i]) == 0 && TimeMinute(Time[i]) == 0)  value2[i] = Open[i]);

}
 
phy:


double value1[];

double value2[];

ArrayResize(value1, Bars);

ArrayResize(value2, Bars);

for(int i = Bars-1; i >= 0; i--){
  
  if(TimeHour(Time[i]) == 9 && TimeMinute(Time[i]) == 55) value1[i] = Close[i]);
  
  if(TimeHour(Time[i]) == 0 && TimeMinute(Time[i]) == 0)  value2[i] = Open[i]);

}

Phy, Thank you very much for your code. The problem now is when i try to run the backtest on the tick basis, it will show a lot of results, can we take in only the first result right after 9:54:59??
 
double value1[];

double value2[];

ArrayResize(value1, Bars);

ArrayResize(value2, Bars);

for(int i = Bars-1; i >= 0; i--){

if(TimeHour(Time[i]) == 10 && TimeMinute(Time[i]) == 00) value1[i+1] = Close[i+1]);

if(TimeHour(Time[i]) == 0 && TimeMinute(Time[i]) == 5) value2[i+1] = Open[i+1]);

}
 
phy:


double value1[];

double value2[];

ArrayResize(value1, Bars);

ArrayResize(value2, Bars);

for(int i = Bars-1; i >= 0; i--){

if(TimeHour(Time[i]) == 10 && TimeMinute(Time[i]) == 00) value1[i+1] = Close[i+1]);

if(TimeHour(Time[i]) == 0 && TimeMinute(Time[i]) == 5) value2[i+1] = Open[i+1]);

}

Dear Phy,

Actually what i want to do is very simple it is just to get the open price for a bar at time 21:00:00 of each day, can I know is there any specific function to get this value? I tried it with an IF loop, but when i run the back test on the tick mode, i will miss out some days, because there's no tick happening at 21:00:00 for those days, so the program is not activated.

And for the code above, i added another line Print("The closing price is :",value1);, but it doesn't print out any value, why??

Please help..... Thank you.....

Reason: