Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

First independent community of traders

First independent community of traders Logo First independent community of traders Logo

First independent community of traders Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • Buy Theme
  • Home
  • About Us
  • Blog
  • Contact Us
Home/ Questions/Q 3642
Next
In Process
setborg
setborg

setborg

  • 3 Questions
  • 3 Answers
  • 0 Best Answers
  • 20 Points
View Profile
  • 0
setborg
Asked: December 26, 20202020-12-26T13:44:17+00:00 2020-12-26T13:44:17+00:00In: Forex Expert Advisors

New Bar

  • 0

Good afternoon. Tell me how to correctly describe a new bar on any time frame ?

the compiler swears at the instruction.

‘isNewBar’ – function can be declared only in the global scope New_Bars.mq5 37 6

OK. I Declare in globalka and there is no result.

//+------------------------------------------------------------------+
//| Returns true if there is a new bar for the symbol/period |pair
//+------------------------------------------------------------------+
bool isNewBar()
{
/ / - - - in a static variable, we will remember the opening time of the last bar
static datetime last_time=0;
/ / - - - current time
datetime lastbar_time=SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);

/ / - - - if this is the first function call
if(last_time==0)
{
//--- set the time and go out
last_time=lastbar_time;
return(false);
}

/ / - - - if the time is different
if(last_time!=lastbar_time)
{
//- - - remember the time and return true
last_time=lastbar_time;
return(true);
}
/ / - - - we have reached this point-so the bar is not new, we will return false
return(false);
}

  • 6 6 Answers
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    6 Answers

    • Voted
    • Oldest
    • Recent
    1. greshnik1

      greshnik1

      • 1 Question
      • 8 Answers
      • 0 Best Answers
      • 36 Points
      View Profile
      greshnik1
      2020-12-26T13:44:45+00:00Added an answer on December 26, 2020 at 1:44 pm

      setborg:

      ‘InpTimeFrame’ – cannot convert enum New_BARS.mq5 80 35

      Swears at the enumeration 

      With such questions, it is better to refer to the help, learn how to use it.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. barabashkakvn

      barabashkakvn

      • 7 Questions
      • 162 Answers
      • 0 Best Answers
      • 314 Points
      View Profile
      barabashkakvn
      2020-12-26T13:44:40+00:00Added an answer on December 26, 2020 at 1:44 pm

      setborg:

      ‘InpTimeFrame’ – cannot convert enum New_BARS.mq5 80 35

      Swears at the enumeration 

      Show the full code. If you have a question, please develop the habit of showing the full code and attaching the code to the message in the form of an mq5 file.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    3. setborg

      setborg

      • 3 Questions
      • 3 Answers
      • 0 Best Answers
      • 20 Points
      View Profile
      setborg
      2020-12-26T13:44:36+00:00Added an answer on December 26, 2020 at 1:44 pm

      Vladimir Karputov:

      New bar. If a new bar is detected on the current symbol and on the specified timeframe “InpTimeFrame” – it skips us further, if the bar is not new-it throws us out of OnTick().

      The variable “InpTimeFrame” is of type ENUM_TIMEFRAMES.

      ‘InpTimeFrame’ – cannot convert enum New_BARS.mq5 80 35

      Swears at the enumeration 

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    4. peterkonow

      peterkonow

      • 0 Questions
      • 1 Answer
      • 0 Best Answers
      • 22 Points
      View Profile
      peterkonow
      2020-12-26T13:44:31+00:00Added an answer on December 26, 2020 at 1:44 pm

      setborg:

      Do you have an example but only for MQL5 ???

      No. And what exactly works differently on MT5? No time series Time[]? Then you can use iTime(Symbol(), TimeFrame,0);

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    5. barabashkakvn

      barabashkakvn

      • 7 Questions
      • 162 Answers
      • 0 Best Answers
      • 314 Points
      View Profile
      barabashkakvn
      2020-12-26T13:44:25+00:00Added an answer on December 26, 2020 at 1:44 pm

      New bar. If a new bar is detected on the current symbol and on the specified timeframe “InpTimeFrame” – it skips us further, if the bar is not new-it throws us out of OnTick().

      //+------------------------------------------------------------------+
      //| Expert tick function                                             |
      //+------------------------------------------------------------------+
      void OnTick()
        {
      //--- we work only at the time of the birth of new bar
         static datetime PrevBars=0;
         datetime time_0=iTime(Symbol(),InpTimeFrame,0);
         if(time_0==PrevBars)
            return;
         PrevBars=time_0;
         ...
        }

      The variable “InpTimeFrame” is of type ENUM_TIMEFRAMES.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    6. setborg

      setborg

      • 3 Questions
      • 3 Answers
      • 0 Best Answers
      • 20 Points
      View Profile
      setborg
      2020-12-26T13:44:21+00:00Added an answer on December 26, 2020 at 1:44 pm

      Reter Konow:

      check out this code. it works fast and well. maybe it will work.

      Do you have an example but only for MQL5 ???

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    Leave an answer

    Leave an answer
    Cancel reply

    Browse

    Sidebar

    Ask A Question

    Stats

    • Questions 505
    • Answers 2k
    • Posts 5
    • Comments 0
    • Best Answers 0
    • Users 689
    • Popular
    • Comments
    • Tags
    • forexcommunity

      Highlighting what’s important about questions & Answers on Discy Community!

      • 0 Comments
    • forexcommunity

      Introducing Keyboard Shortcuts, our first Labs feature

      • 0 Comments
    • forexcommunity

      Defining quality on Discy Engine — what a helpful answer ...

      • 0 Comments
    • forexcommunity

      Organizational and company accounts on Discy Engine the next step

      • 0 Comments
    • forexcommunity

      Hello world!

      • 0 Comments

    Related Questions

    • starleynsk

      SYMBOL_POINT or how to get the tick size

      • 2 Answers
    • avos

      What's wrong? possible loss of data due to type conversion

      • 5 Answers
    • worh

      pass a value from one Expert Advisor to another

      • 9 Answers
    • c00l777

      During optimization, indicators that are not present in the robot ...

      • 2 Answers
    • c00l777

      During optimization, indicators that are not present in the robot ...

      • 0 Answers

    Users

    Lindatar

    Lindatar

    • 0 Questions
    • 0 Answers
    sgarnov

    sgarnov

    • 0 Questions
    • 1 Answer
    alexandrim

    alexandrim

    • 0 Questions
    • 1 Answer

    Footer

    First independent community of traders

    About

    An independent community of forex traders. This is where traders communicate. You can ask your questions and you will receive an answer to your question.
    • Terms of Use
    • Privacy Policy
    • Cookie Policy
    • Knowledge Base
    • Support

    © 2021 Forexcommunity.net. All Rights Reserved