iBarShift()

 

Please confirm if I am right or correct me if I am wrong:

If I use this function like this:

int NumberofBars = iBarShift(Null,0,OrderOpenTime());

Will it show me(assign to the var NumberofBars) the number of bars that have been created since the time my order has been opened? ( i run it in the OrdeSelect loop)
Because from the functions' description its not so clear, and do I need to specify "exact" at the end and what does it mean.
Thanks.
 
t0mbfunk:

Please confirm if I am right or correct me if I am wrong:

If I use this function like this:

 Will it show me(assign to the var NumberofBars) the number of bars that have been created since the time my order has been opened? ( i run it in the OrdeSelect loop)

Because from the functions' description its not so clear, and do I need to specify "exact" at the end and what does it mean.

exact == false:   if your OrderOpenTime() is contained within the time/duration of a bar then that bar number will be returned,  if not the number of the bar nearest the time will be returned.

exact == true:   if your OrderOpenTime() is contained within the time/duration of a bar then that bar number will be returned,  if not -1 will be returned.

 

be aware problems have been reported with this function . . .

 iBarShift doesn't match documentation.

 
t0mbfunk: Please confirm if I am right or correct me if I am wrong:

I never use exact=true. All it does is an additional check:

  1. int iBarShiftTrue(... dt){
       int i = iBarShift(NULL, 0, dt, false);         // Found bar i
       if( Time[i] > dt)                  return(-1); // dt is earlier than max bar on chart.
       if( Time[i] + Period() * 60 <= dt) return(-1); // dt is between two bars. E.g. weekend.
       return(i);
    }
  2. See also iBarShift doesn't match documentation. - MQL4 forum

  3. int NumberofBars = iBarShift(Null,0,OrderOpenTime());
    
    It's NULL not Null
 

Ok, thanks.

Here is my function :

void AbsoleteOrders()
{
  for(int A=OrdersTotal()-1;A>=0;A--)
  {
    if(OrderSelect(A,SELECT_BY_POS,MODE_TRADES)
      if(OrderMagicNumber()==MagicNumber)
        if(OrderSymbol()==Symbol())
          if(OrderType()==OP_SELLSTOP || OrderType()==OP_BUYSTOP)
            int BarShift = iBarShift(NULL,0,OrderOpenTime(),false);
              if(BarShift > 2)
                OrderDelete(OrderTicket(),CLR_NONE);
  }
}
 
t0mbfunk:

Ok, thanks.

Here is my function :

Don't you want to know if your OrderDelete() failed ?  and if it did fail don't you want to know why ?

What are Function return values ? How do I use them ? 

 

Thank you raptor will do..meanwhile it gives me end_of_program unbalanced left parentheses.. I cant seem to find whats the problem..

I've added the GetLastError check..but cant run it because it wont compile

And I am sure its in this block of code..

 
'\end_of_program' - unbalanced left parenthesis
 if(OrderSelect(A,SELECT_BY_POS,MODE_TRADES)
   Can you find it....
 
ffs,, lol i've been looking at it for 2 hours
 
t0mbfunk:
ffs,, lol i've been looking at it for 2 hours

A few spaces will help you see more clearly sometimes . . .

if( OrderSelect( A,SELECT_BY_POS, MODE_TRADES )
 
RaptorUK: A few spaces will help you see more clearly sometimes . . .
What I do is alternate the spaces from the inside out
// if(OrderSelect( A,SELECT_BY_POS, MODE_TRADES )
   if( OrderSelect(A,SELECT_BY_POS, MODE_TRADES) )

if( GlobalVariableSetOnCondition(TC.GV.Name, LOCK, !LOCK) ){

if(IsAboveDIR( Bid, IfD(trigBuy,trigSell) )){

double   DIRtrade    = Direction( OrderType() ),   

return( iHighest(NULL,p, MODE_HIGH, n, iBeg) ); }

return( values[iNth] );

return( (b - a)*d > Point_2 );
 
WHRoeder:
What I do is alternate the spaces from the inside out

Yep, that works too,  a little forethought goes a long way  
Reason: