Download MetaTrader 5

Compare Any Time Of Bar By Seconds

To add comments, please log in or register
Brian Lillard
378
Brian Lillard  
How to see time of bar and then see time of bar at like 45 seconds for example

if i had to write it out it would be something like this,

get time of bar in seconds(current time)

get time of last bar in seconds and add the time in seconds to it we want and then compare it

if the comparison results in the current time being higher then the desired time then output nothing

if the comparison results in the current time being lower than the desired time than output something

therefore it could it also be possible to output something when the comparison is equal ??
Keith Watford
Moderator
10533
Keith Watford  

int seconds=45;
if(TimeCurrent()-Time[0]<=seconds)
  {
  //Do Something;
  }
.
Brian Lillard
378
Brian Lillard  
Like what about checking the order pool for orders taken from the current bar?

if(TimeDayOfYear(OrderOpenTime())==TimeDayOfYear(TimeCurrent()) &&
         OrderSymbol()==_symbol && OrderMagicNumber()==newMagic && OrderComment()==_comment)

I think it might only work for the day .. but I would like to know if an order was placed on the current bar.
Keith Watford
Moderator
10533
Keith Watford  
 
  int bar_shift=iBarShift(Symbol(),0,OrderOpenTime());
  if(bar_shift==0)
    //Order was opened in the current bar
honest_knave
Moderator
2342
honest_knave  
Keith Watford:
 
  int bar_shift=iBarShift(Symbol(),0,OrderOpenTime());
  if(bar_shift==0)
    //Order was opened in the current bar

Or:

if(OrderOpenTime() >= Time[0])
Keith Watford
Moderator
10533
Keith Watford  
honest_knave:

Or:

if(OrderOpenTime() >= Time[0])
Now I feel foolish. That didn't even occur to me.
Brian Lillard
378
Brian Lillard  
excellent guys i like the iBarshift of OrderOpenTime() because what bar is the order from?
honest_knave
Moderator
2342
honest_knave  
Keith Watford:
Now I feel foolish. That didn't even occur to me.
Your solution is more flexible i.e. other symbols and timeframes, or checking other bars like the OP now wants.
Brian Lillard
378
Brian Lillard  
honest_knave:
Your solution is more flexible i.e. other symbols and timeframes, or checking other bars like the OP now wants.
i don't know how it even works ;)
Time[0] always incrementing, OrderOpenTime() older than Time[0]
if(OrderOpenTime() >Time[1]){//its bar 0}
honest_knave
Moderator
2342
honest_knave  
Brian Lillard:
i don't know how it even works ;)
Time[0] always incrementing, OrderOpenTime() older than Time[0]

Time[0] is the open time of the current bar, not the latest time. 

Example:

Time now is 12:03:47 (hh:mm:ss)

Time[0] on an M1 chart is 12:03:00 

Keith Watford
Moderator
10533
Keith Watford  
Brian Lillard:
i don't know how it even works ;)
Time[0] always incrementing, OrderOpenTime() older than Time[0]
if OrderOpenTime() older than Time[0] then it cannot gave been opened in the current bar.
12
To add comments, please log in or register