Last Completed Candle ?

Moderator: Moderator

Re: Last Completed Candle ?

Postby Nikolay.Gekht » Fri Sep 30, 2011 8:14 am

Neither server, nor forex connect API has this information.

Actually, here is two parts in that task:

1) You must know the borders of the candle you are watching for. It's pretty easy for H1 and shorter candle and a bit harder for H2+ candles (since it involves the offset of the trading day) and even more complex for W1+ candles, but I can publish this algo in C++ or C#.

2) You must know the server time. This is the problem. If the client computer is synchronized via network time services and it's clock are good enough - the local time can be used. Unfortunately, clocks on the most computers shows rather weather on Mars rather than the correct time :-). Trading Station uses pretty tricky and complex algorithm to have it's internal clock synchronized with the server. I don't think that it's a good idea to put such big workaround for inconsistency of the local clocks into the trading API.

What can be done? Developer can go the following way:

We know that:
1) Ticks comes often enough. If there is not ticks, there is no reason to trade. :-)
2) Tick comes not later than in 500-750 ms after it actually appears.

So, the application must:
1) provide the fastest procedure to process ForexConnect messages. All trading logic must be isolated into the separate threads, the information from messages parsing must be sent to these threads via events/blocking queue.
2) Check the difference between the local clock and the tick time and if the difference is bigger than 1 second - keep the correction value in mind.
3) When (actually - on timer) the application need to check whether the candle is finished - it must add/subtract this correction value to the local clock to get the proper server time.

I think that such API may be very useful for many developers. I cannot promise that I personally can be actively involved into such API development, but I can open any sources related I already have or developed before. If here is anyone who would like to try, please let me know.
FXCodeBase: Site Admin
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Last Completed Candle ?

Postby frAnton » Fri Sep 30, 2011 9:03 am

Bebbspoke wrote:PLEASE - all that is needed is a LIVE flag or ping from the datastream to clock the COMPLETION of the (most recent) LAST Bar/Candlestick - this would make robot synchronization so much easier....

Hi Bebbspoke,

you already have this flag, actually.
Just think about it, every tick receives a timestamp at the moment it is generated.
To be exact, we actually do not know when exactly the tick is assigned with the time, but the assumption is that it is assigned at the moment it gets generated.
Now, the task is relatively easy:
The minute ends when tick.time.Seconds > tick+1.time.Seconds.
In this case you do not care about the local time at all.

Hope this helps. If you have more questions just ask.
Posts: 74
Joined: Tue Apr 05, 2011 11:41 pm
Location: California

Re: Last Completed Candle ?

Postby Bebbspoke » Sat Oct 01, 2011 5:15 pm

Hi Nikolay and Anton,

Thank you for your responses: -

My specific requirement is to know (ideally, directly via a ping from FXCM) exactly when the current "live" bar is effectively closed and the OHLC values are actually fixed for that specific time period. Tick prices are of no interest whatsoever.

When relevant my robot algorithm uses the OHLC values of the most recently closed bar and along with additional mathematics; to calculate the Entry, Stop and Limit levels of the next potential trade and to PLACE an order with FXCM - it is therefore essential to identify the moment the running bar becomes closed and that the OHLC values have become permanently fixed.

I do not consider a routine which relies on "waiting for the next tick" is an appropriate method of identification for the "last completed candle", particularly when the event is actually defined by FXCM - if "waiting for the next tick" is the methodology by which FXCM actually finalise and close the candle; then an appropriate ping should be generated at source.

I actually have a work-round to solve this problem but I am well aware that it is a considerable problem for many traders, especially roboteers.

Regards, Bebbspoke
User avatar
FXCodeBase: Confirmed User
Posts: 170
Joined: Tue Aug 16, 2011 4:04 am
Location: Walton on the Naze UK

Re: Last Completed Candle ?

Postby blackhat » Sun Feb 05, 2012 5:29 am

Hi all,

I also need a piece of code to retrieve the last completed candle in C++. sunshine, in august, you said that developpers have promised to prepare an example for such a task. Where is this example available?

Posts: 3
Joined: Fri Feb 03, 2012 2:21 pm

Re: Last Completed Candle ?

Postby sunshine » Mon Feb 06, 2012 7:24 am

We have the examples in C# and C. We could prepare the C++ sample this week.

Re: Last Completed Candle ?

Postby blackhat » Tue Feb 07, 2012 4:12 pm

Yes, please!
Posts: 3
Joined: Fri Feb 03, 2012 2:21 pm


Return to ForexConnect API

Who is online

Users browsing this forum: No registered users and 4 guests