NavigationUser loginWho's new
Who's onlineThere are currently 0 users and 71 guests online.
|
New Bar Mystery!Hi folks, I've received a lot of PMs asking me "How to determine a New Bar?" "How to trigger some code at the start of the New Bar?" That's why we are going to study today a very important piece of code that working with the new bar and the open time of this new bar (I'm saying it's important, I don't know what do you think?). What does 'Bar' mean?
Let's start with a theoretical approach by defining what does 'Bar' mean? Investopedia says: Bar is: "A graphical representation of a stock's movement that usually contains the open, high, low and closing prices for a set period of time. For example, if a technical trader is working with daily data, one bar is the set of quotes for one day. In the case of one-minute data, it is the price data for one minute. Also, if the data is displayed using a candlestick chart, one bar equals one candlestick or in the case of bar charts, one bar is equal to one bar." What about New Bar?It's easy now to say that the new bar is the time that the trading platform finishes a bar (current bar) and starts to draw a new bar; this time is determined by the timeframe you use. If you use 30 minutes timeframe you have to except that the platform will draw a new bar approximately every 30 minutes (give figure 1 a look)
How to determine a New Bar?
Let's write some code in replying of this important question: bool NewBar() The above code is a straight forward and very simple one: It compares the open time of the bar which is returned from the function Time[0] into the variable curbar with the previous open time of the bar that saved in a static variable (lastbar). You will find in the Forex forums a lot of pieces of code that tries to tell the start of a New Bar, however this is code is the must clean one and self-discloser one! How to trigger some code at the start of the New Bar?
We have written the function which returns true in the case of a start of a New Bar, so, it's an easy task to write a block of code to do what we want to do in the case of a start of a new bar; here's an example: int start() You have not to forget the empty parenthesis after the NewBar keyword because it's a function which takes no prameters. I hope you find it a useful lesson and wait your comments/questions! Coders' Guru |