Get Open Price

 

I am trying to get the open price of the H1 6:00GMT bar. I can't for the life of me figure it out. Please advise.


TimeFreedom

 

https://docs.mql4.com/series/iBarShift


You'll probably have to add a GMT int shift depending on your brokers GMT offset. FXDD is +2 GMT.

 
jmca:

https://docs.mql4.com/series/iBarShift


You'll probably have to add a GMT int shift depending on your brokers GMT offset. FXDD is +2 GMT.

JMCA;


Your help is greatly appreciated but your suggestion will give the number of bars and not the open price.


Thank you,


TimeFreedom

 

hi Time,

if the bar you are looking for to find the price is the present one, I use the following:

if (High[0] == Low[0]) this means that this is a new bar

{

do whatever you want, like myBid = Bid

}

hope it helps,

 
datetime some_time = D'2004.03.21 12:00';
int shift = iBarShift("EUROUSD",PERIOD_M1,some_time);
Print(Open[shift]);
 
pabloschiki:

hi Time,

if the bar you are looking for to find the price is the present one, I use the following:

if (High[0] == Low[0]) this means that this is a new bar

{

do whatever you want, like myBid = Bid

}

hope it helps,

Pabloschiki;


I appreciate your quick response and taking the time to respond. Let me try and explain exactly what I am trying to do. At the beginning of the week I need to find the OPEN PRICE of the 6:00GMT bar and then immediatly open a BUYSTOP and SELLSTOP a number pips above and below the OPEN PRICE. I just can't seem to get my head around this problem. Please advise.


TimeFreedom

 
jmca:

JMCA,


Please read my post above and let me know if your code will do what I am trying to convey in that post?


TimeFreedom

 

yes, my post will do that.


datetime theTimeYouWant = --whatever the time is--;
int theBarIWant = iBarShift(Symbol(), PERIOD_H1, theTimeYouWant, false); //returns the BAR number
double open = Open[theBarIWant];
double close = Close[theBarIWant];


Again though, the time will relate to your broker's server time. So if their time is the same as GMT you're all set. Otherwise you might have to subtract an hour or so, or add.

Read up more on iBarShift in the forums or documents to understand it better.

 
jmca:

yes, my post will do that.


datetime theTimeYouWant = --whatever the time is--;
int theBarIWant = iBarShift(Symbol(), PERIOD_H1, theTimeYouWant, false); //returns the BAR number
double open = Open[theBarIWant];
double close = Close[theBarIWant];


Again though, the time will relate to your broker's server time. So if their time is the same as GMT you're all set. Otherwise you might have to subtract an hour or so, or add.

Read up more on iBarShift in the forums or documents to understand it better.



The only problem I see with iBarShift is I have to hard code the time? Please advise.


TimeFreedom

 
TimeFreedom:

The only problem I see with iBarShift is I have to hard code the time? Please advise.


TimeFreedom

I think I figures it out. I call out the getBarOpen() function like this:

  if(Hour()==startTradeHour && DayOfWeek()==1 && Minute()==0){getBarOpen();}

The only problem is sometimes the bar doesn't open at exactly XX:00


void getBarOpen()
   {  
   datetime thisTime = TimeCurrent();
   int      shift    = iBarShift(NULL,PERIOD_H1,thisTime);
   Print("Shift of Bar with Open Time ",TimeToStr(thisTime)," is ",iOpen(NULL,PERIOD_H1,shift));//For Testing Purposes
   }
 

Please can somebody help me with a simple EA code, that can (after meeting some requirement)

-- place a trade of either buy or sell,

-- use the open price of the trade above to form the takeprofit  (maybe adding or subtracting 100 points to open price),

still on one Expert Advisers Code sheet.

Reason: