Results 1 to 3 of 3
 0 Attachment(s)    

Thread: isNewBar across different timeframes

  1. #1
    Junior Member
    Join Date
    Mar 2015
    Posts
    2

    Default isNewBar across different timeframes

    Hi,

    I'm trying to figure out how to create a isNewBar function that works across multiple timeframes.

    What I've created is this but it doesn't seem to be working and I can't work out why!

    Code:
    const bool isNewBar(const datetime time, int period)
      {
       static datetime time_prev;
       if(time_prev!=time && MathMod(TimeMinute(time),period)==0)
         {
          time_prev=time;
          return(true);
         }
       return(false);
      }
    It's called by these instructions:

    Code:
    isNewBar(Time[0],PERIOD_M1)
    seems to work.

    BUT,

    Code:
    isNewBar(Time[0],PERIOD_M5)
    doesn't. Any help will be appreciated.

    Thanks!

  2. #2
    Senior Member fxtester's Avatar
    Join Date
    Nov 2008
    Posts
    3,165

    Default

    Something like that :

    Code:
    bool isnewbar(int timeframe){
       if(GlobalVariableGet(Symbol()+timeframe)!=iTime(NULL,timeframe,0)){
          GlobalVariableSet(Symbol()+timeframe,iTime(NULL,timeframe,0))
          return(true);
       }
       return(false);
    }
    Code:
    if(isnewbar(PERIOD_M5)==true)...
    When you attach the expert, it will say yes it's a new bar, so you should add a max volume condition, or set the global variable first in initialization.

  3. #3
    Junior Member
    Join Date
    Mar 2015
    Posts
    2

    Default Interesting...

    Thanks I'll give that a go, never used GlobalVariableGet before so should be interesting.

    Thanks again.

Similar Threads

  1. Replies: 0
    Last Post: 06-29-2010, 19:47
  2. Multi TimeFrames MA EA
    By funyoo in forum Expert advisors backtesting
    Replies: 0
    Last Post: 02-07-2009, 21:21

Tags for this Thread

date, how to

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •