Thread: quick question
View Single Post
  #2 (permalink)  
Old 12-02-2005, 04:13 PM
codersguru's Avatar
codersguru codersguru is offline
Senior Member
 
Join Date: Oct 2005
Posts: 987
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Exclamation Welcome!

Quote:
Originally Posted by murky waters
question: how do you write an "if" function that triggers code at the END of each bar on the chart (which works independent of chart timeframe)?
murky waters,
Welcome to our forum!

Test this code:

PHP Code:
bool NewBar() //this function will return true if there's a new bar.
   
{
      
      static 
bool first_call true;
      static 
int start_bar 0;
      if(
first_call)
      {
         
start_bar=Bars;
         
first_call=false;
      }
      if(
Bars == (start_bar+1))
      {
         
first_call=true;
         return (
true);
      }
      else
      {
         return (
false);
      }
   } 

int start() //<-- in your start function you may use code like this
{
    if (
NewBar)
    {
       
//do something
    
}
    return (
0);

__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Reply With Quote