MQL4 - automated forex trading   /  

Forum

getting the close for a specific bar

Back to topics list To post a new topic, please log in or register

avatar
1
tonyfox 2008.02.24 08:34 

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

article

30 Days of Registration

30 days have passed since Registration started. Almost 650 people have already applied for participation. This is practically equal to the total amount of applications in Championship 2006. There are still 52 days left until Registration is over.


avatar
13
PipRaider 2008.02.24 09:28 

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);


avatar
10
bearking 2008.03.27 19:04 
PipRaider wrote:

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.

avatar
2462
phy 2008.03.27 19:15 


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]);

}

avatar
10
bearking 2008.03.27 19:30 
phy wrote:


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??

avatar
2462
phy 2008.03.27 20:56 


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]);

}

avatar
10
bearking 2008.03.28 08:16 
phy wrote:


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.....

Back to topics list  

To add comments, please log in or register