Last Completed Candle ?

Moderator: Moderator

Last Completed Candle ?

Postby frAnton » Fri Aug 12, 2011 5:37 pm

Hi there,

I just wonder if you guys can add functionality to retrieve the very last completed candle for the instrument.

I know that it is possible to get the historical price by using MarketDataSnapshot and passing HistoryType constant, start time, end time etc.
It works just fine, and the performance is very good if the Client requests the data for the large period, like 300 or > 300 candles.
However, using the same method in getting just the very last completed candle works I think a little bit slower than I expected.
So I think that it would be very nice if you guys would cache the very last completed candle somewhere on the server side, and return the data to the client by let say GetLastCandle() request.

Just a suggestion.

thanks,
Anton.
frAnton
 
Posts: 74
Joined: Tue Apr 05, 2011 11:41 pm
Location: California

Re: Last Completed Candle ?

Postby sunshine » Mon Aug 15, 2011 5:53 am

Hi Anton,

Thanks for the suggestion.

frAnton wrote:So I think that it would be very nice if you guys would cache the very last completed candle somewhere on the server side, and return the data to the client by let say GetLastCandle() request.

Please tell us how do you plan to use this function? How often do you plan to call the function?
sunshine
 

Re: Last Completed Candle ?

Postby frAnton » Mon Aug 15, 2011 8:48 am

sunshine wrote:Hi Anton,

Thanks for the suggestion.
Please tell us how do you plan to use this function? How often do you plan to call the function?


Hi sunshine,

It's very hard to tell when exactly the client is needed the very last completed candle.
I'd say that if an algorithm follows 5 min chart let say for the scalping, it needs to sync the very last completed candle with the server side every 1 and 5 minutes.
I am using the MarketDataSnapShot for it right now. However, I think that the performance can be improved if FxConnect had the shortcut in getting the very last completed candle from the cache.

Just an example.

Thanks,
Anton.
frAnton
 
Posts: 74
Joined: Tue Apr 05, 2011 11:41 pm
Location: California

Re: Last Completed Candle ?

Postby sunshine » Wed Aug 17, 2011 7:07 am

Hi Anton,

I've discussed your request with the developers.
It looks like the best solution for you is to implement a class which will process price updates and form a candle. You'll be able to get the last candle at any time without sending a request to the server.
If you have problems implementing such a class, we could prepare an example for you.
sunshine
 

Re: Last Completed Candle ?

Postby frAnton » Wed Aug 17, 2011 9:18 am

sunshine wrote:Hi Anton,

I've discussed your request with the developers.
It looks like the best solution for you is to implement a class which will process price updates and form a candle. You'll be able to get the last candle at any time without sending a request to the server.
If you have problems implementing such a class, we could prepare an example for you.


Hi sunshine,

well, this is what I actually do. I form a candle on the client side using price update.
However, because of today there is no way for the Client to sync the timer with the server side the last completed candle eventually run out of sync. This is with regards to the 1 min chart. If I got 1 min candle chart properly I can form any candle from it. However, because of the timer on the client and on the server work independently the candle I got sometime quite different than the one on the server.
This is the main reason why I asked you to get last completed candle cached on the server.

Anyway, it'd be great if you guys provide some king of example of how you suggest to form a candle from the price update.

thanks,
Anton.
frAnton
 
Posts: 74
Joined: Tue Apr 05, 2011 11:41 pm
Location: California

Re: Last Completed Candle ?

Postby sunshine » Thu Aug 18, 2011 4:04 am

Hi Anton,

Developers have promised to prepare an example in the beginning of the next week.
sunshine
 

Re: Last Completed Candle ?

Postby allpin » Mon Aug 22, 2011 5:20 pm

Hello Anton,
you can use the program http://www.fxcodebase.com/code/viewtopi ... =27&t=4685 for your purpose.
If you need only get last candle, please use <NumBars>1</NumBars> in configuration file.
This program will get the last candle and continue to update it based on coming ticks.
allpin
FXCodeBase: Confirmed User
 
Posts: 21
Joined: Thu Aug 19, 2010 3:29 pm

Re: Last Completed Candle ?

Postby frAnton » Mon Aug 22, 2011 10:53 pm

allpin wrote:Hello Anton,
you can use the program http://www.fxcodebase.com/code/viewtopi ... =27&t=4685 for your purpose.
If you need only get last candle, please use <NumBars>1</NumBars> in configuration file.
This program will get the last candle and continue to update it based on coming ticks.


Hi allpin,

thank you very much for the example.
I am using similar approach and honestly I am not really happy about it.
Please correct me if I am missing something, but both your example and my Client rely on the local system timer. Another words, the assumption is made that both the Client and the Sever timers are in sync, and the timer on the Client starts the minute exactly the same moment in time that the timer on the server side did.
If this is the case, then yes this approach would work just fine and the candle that is formed on the Client side would match exactly the candle that is formed on the Server side.
However, this is not the case.
As a result, even the 1 min candle that was formed by the client is different than the one that is formed on the Server by querying the history table. And based on my experience I can see that the more volatility is on the market then the greater this difference is.

From my side, I can suggest several ways of solving the issue withe the accuracy of the very last completed candle.

1. As I suggested early in this thread, caching the very last completed candle on the server side. in this case the Client can always get the very last completed 1 min candle, for example.

2. Constantly synchronizing the timers between the Server and the Client side to make sure that they both start a minute at the same moment. I have made a request to FxConnect development team to provide the functionality that would let the Client to synchronize itself with the server periodically.

3. Define and implement some kind of O2G2Session.TheMinuteEnd() event that would signal to the Client that the minute(and the very last completed candle) is closed on the Server and the Client can form the candle from the data it received through the Price Update.

But all those solutions require the help from FxConnect development team.

Thank you,
Anton.
frAnton
 
Posts: 74
Joined: Tue Apr 05, 2011 11:41 pm
Location: California

Re: Last Completed Candle ?

Postby allpin » Tue Aug 23, 2011 9:36 am

Hello Anton,
I don't think that example relies on client and server timers being in sync. Actually we are using only server time stamps to draw the candle. We are using either O2GMarketDataSnapshotResponseReader.getDate (from historic prices) or O2GOfferRow.Time (from incoming offers). The timer on the client has no authority on the output content (.csv file). The client timer is used just to update the output periodically with new offers (to update the forming candle and/or to draw the new candle).
When the application starts, it gets the last candle, and then application adds ticks to that candle until another candle begins forming. In most cases the last candle would be a forming candle (incomplete). By adding new ticks we would be able to update the candle. It does not matter whether the application starts at the beginning of the candle or somewhere in the middle.
Marketsope application in Trading Station uses the same technique to form the candle from the ticks.
But maybe you do not need the forming candle at all and all you need is the last formed candle? This is another story. It also could be done. Please clarify you needs.
Regards.
allpin
FXCodeBase: Confirmed User
 
Posts: 21
Joined: Thu Aug 19, 2010 3:29 pm

Re: Last Completed Candle ?

Postby frAnton » Tue Aug 23, 2011 11:54 am

allpin wrote:Hello Anton,

But maybe you do not need the forming candle at all and all you need is the last formed candle? This is another story. It also could be done. Please clarify you needs.
Regards.


Hi allpin,

Yes, I am interested in the very last completed 1 min candle.
I want my Client to be able to get the very last completed candle every minute. Currently I am forming it myself based on the received price. But there is no indication for me when the actual minute is closed, that's why I have to rely on the local timer being in sync with the server.

Another question, the time stamp on a ticks, where it comes from? At what point the tick is being stamped with time?

thanks,
Anton.
frAnton
 
Posts: 74
Joined: Tue Apr 05, 2011 11:41 pm
Location: California

Next

Return to ForexConnect API

Who is online

Users browsing this forum: No registered users and 4 guests