Thread: Ask!
View Single Post
  #1438 (permalink)  
Old 01-07-2009, 07:58 PM
bobfourie bobfourie is offline
Junior Member
 
Join Date: Oct 2006
Posts: 26
bobfourie is on a distinguished road
NewBar

Quote:
Originally Posted by numbercruncher View Post
Just in case somebody's listening ...
How about this ? Does it make sense for 5min timscale?
Hi numbercruncher, I use this function that I wrote .You can use any of the timeframes to determine if its an new bar in that timeframe

Code:
int start()
{
  if(ISNewBar(5))
  {
    //do some thing
  }

}

bool ISNewBar(int iTimeFrame)
{
int iIndex = -1;

   switch(iTimeFrame)
   {
    case 1    : iIndex = 0; break;
    case 5    : iIndex = 1; break;
    case 15   : iIndex = 2; break;
    case 30   : iIndex = 3; break;
    case 60   : iIndex = 4; break;
    case 240  : iIndex = 5; break;
    case 1440 : iIndex = 6; break;
    default   : iIndex =-1; break;
   }
 static int LastBar[7]= {0,0,0,0,0,0,0}; 
 datetime curbar = iTime(Symbol() ,iTimeFrame, 0);
 if(LastBar[iIndex]!=curbar)
  {
    LastBar[iIndex]=curbar;
    return (true);
  }
  else return(false);
}
Reply With Quote