API Support Forum
OEC API > Market Data > Subscribe to previous bar high
Author Topic: Subscribe to previous bar high
(5 messages, Page 1 of 1)
Moderators: VPfau
HReyneke1498
Posts: 5
Joined: Nov 06, 2017


Posted: Apr 05, 2018 @ 09:10 AM             Msg. 1 of 5
Hi. I would like to subscribe to the previous bar's high price. So that every time there is a new bar, I have the previous bar's high.

SubscribeBars(contract, 2, SubscriptionType.Bar, 1, false);
This gives 2 bars the first time, but from then on only the current bar.

Any help will be appreciated.
Edited by HReyneke1498 on Apr 05, 2018 09:10 AM
VPfau
Moderator
Posts: 154
Joined:


Posted: Apr 05, 2018 @ 10:20 AM             Msg. 2 of 5
HReyneke1498,

That's right. First answer includes historical bars + current bar. Then we send updates only. If you need previous bar info, you need store current bar somewhere and compare it with next updates.
Vitaliy Pfau
HReyneke1498
Posts: 5
Joined: Nov 06, 2017


Posted: Apr 05, 2018 @ 10:30 AM             Msg. 3 of 5
Thanks for the reply Vitaliy. That should work perfectly for open prices, but since we are only at the beginning of the bar at save time, we don't have the final bar high.
VPfau
Moderator
Posts: 154
Joined:


Posted: Apr 05, 2018 @ 10:35 AM             Msg. 4 of 5
First check if current bar is new, if it is, the prev stored bar will have valid high value.
Vitaliy Pfau
HReyneke1498
Posts: 5
Joined: Nov 06, 2017


Posted: Apr 05, 2018 @ 11:04 AM             Msg. 5 of 5
That is true for the first bars array received. It contains 2 bars: The first bar is the completed previous bar. The second bar is the uncompleted current bar.

From then on one receives bars arrays containing only the current bar.
Edited by HReyneke1498 on Apr 05, 2018 11:05 AM
Edited by HReyneke1498 on Apr 05, 2018 11:12 AM