SmartQuant Discussion
http://www.smartquant.com/forums/

Build bar from trade on live trading
http://www.smartquant.com/forums/viewtopic.php?f=75&t=9748
Page 1 of 1

Author:  truebilly [ Mon Oct 24, 2011 7:23 am ]
Post subject:  Build bar from trade on live trading

Hi, while I am on paper trading mode and receiving market data from my custom user provider,
I try to view the 1-min candlestick chart of one instrument and it looks like this:
Image

as u see, only Close(Last) data is shown on each bar, when new trade is coming, the last bar changes to the new price, but the open, high and low data do not correctly show. I've tried OHLC bar but the result is the same.

In the solution's market data configuration, I selected two market data: Trade and Bars 1 min. The Bars 1 min data is built from trades. (the property "Build bar from trades" is selected).

My custom user provider only receives and emits trade data (base.EmitNewTrade()). And I have checked the trade data in data manager, the trades are recorded correctly.

Is it because I didn't emit bar data in my user provider or I should not use build bar from trades in solution config?

Author:  Dr. Anton Fokin [ Mon Oct 24, 2011 7:48 am ]
Post subject:  Re: Build bar from trade on live trading

Hi,

it looks like all trades within a bar have the same price (O=H=L=C). Could you print out what you emit in EmitNewTrade (i.e. print out trades that you pass to this method call) in your custom data provider?

Regards,
Anton

Author:  truebilly [ Mon Oct 24, 2011 8:02 am ]
Post subject:  Re: Build bar from trade on live trading

Thanks for your reply, Anton
I guarantee that there are different prices in a bar, because I see the bar "MOVING" vertically while new trade arrives. But the old data in the same minute are lost.
The left pic is the trade data I recorded using Data Capture, right is the chart data I was seeing.
Image

Author:  Dr. Anton Fokin [ Mon Oct 24, 2011 8:07 am ]
Post subject:  Re: Build bar from trade on live trading

Strange. What happens if you run simulation with captured trades? Would you see the same or correct bars?

Author:  Dr. Anton Fokin [ Mon Oct 24, 2011 8:11 am ]
Post subject:  Re: Build bar from trade on live trading

Also, check that you have correct Input in BarFactory settings (i.e. trades).

Author:  truebilly [ Mon Oct 24, 2011 8:29 am ]
Post subject:  Re: Build bar from trade on live trading

The chart displays correct candlesticks while in history data simulation.

I've checked the barFactory settings and it's set to "Trade".

If I remember correctly, in an old version of OQ, the last candlestick bar does not show until the current minute is passed (in Live/Paper mode). But I am surprised to see that the chart draws the last bar as soon as the first trade data in this minute arrives and continues to update the last bar, although it only displays the last trade :lol:

Author:  Dr. Anton Fokin [ Mon Oct 24, 2011 8:45 am ]
Post subject:  Re: Build bar from trade on live trading

I've forwarded this issue to our developers, let's see what they say. But could you print out trades that you pass to EmitNewTrade. This would be helpful.

Author:  truebilly [ Mon Oct 24, 2011 8:51 am ]
Post subject:  Re: Build bar from trade on live trading

you mean that I add Console.Writeline(trade info) while EmitNewTrade(trade info), and post the records?

Author:  Dr. Anton Fokin [ Mon Oct 24, 2011 8:59 am ]
Post subject:  Re: Build bar from trade on live trading

yes, add Console.WriteLine before EmitNewTrade line.

Author:  Baraz Sergey [ Mon Oct 24, 2011 9:49 am ]
Post subject:  Re: Build bar from trade on live trading

Hi,

In your custom UserProvider - which datetime do you pass as a parameter to the EmitNewTrade method? Is it Clock.Now, DateTime.Now or something else?

Regards,
Sergey.

Author:  truebilly [ Mon Oct 24, 2011 10:05 am ]
Post subject:  Re: Build bar from trade on live trading

Baraz Sergey wrote:
Hi,

In your custom UserProvider - which datetime do you pass as a parameter to the EmitNewTrade method? Is it Clock.Now, DateTime.Now or something else?

Regards,
Sergey.


Hi, Sergey
My provider's trade data structure includes time, so I used the trade data's datetime. Should I use something else?

Author:  Dr. Anton Fokin [ Mon Oct 24, 2011 10:39 am ]
Post subject:  Re: Build bar from trade on live trading

Yes, Clock.Now

Author:  truebilly [ Tue Oct 25, 2011 5:09 am ]
Post subject:  Re: Build bar from trade on live trading

I've used Clock.Now and the problem solved. But by using Clock.Now, the trade data's datetime is incorrectly recorded from my computer's local time, which is different from the time I received from the broker, which I believe is more accurate.
Another thing is that the live candlestick chart's last bar stopped auto updating while receiving new trade data. I missed the time when I didn't use Clock.Now and the chart could update the last bar and indicators. :cry:
My suggestion is that you could consider adding this feature of updating the last bar and the indicators on receiving new trades of the last bar. I guess you use ZedGraph as the chart control, which I have used in my own chart-displaying application. It's not difficult to update and refresh the last bar data.

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/