OHLC Current Bar
OHLC Current Bar
05 Oct 2021, 21:56
Hi
How do I get the OHCL data of the current bar?
I know how to access these values (Bars.Last(0).XXXX) but they all give me the same value for example:
- 29/09/2021 21:00:00.000 | CurrentHigh: 1,15974
- 29/09/2021 21:00:00.000 | CurrentOpen: 1,15974
Can anyone please advise? Thanks
Replies
charltonadams38
06 Oct 2021, 11:39
RE:
Hi amusleh
First, thank you for your reply and valuable input.
Second, I would like to buy using onTick() will I be able to access the hourly data of a daily candle right before a new candle opens?
For example, I would like to get the High just before a new daily candle starts to ensure the currentHigh is as accurate as possible.
I am new to programming trading bots and I've been reading through the documentation but there is so much to read through it is hard to find the information I am looking for, hence the reason I have been using OnBar().
Thank you
@charltonadams38
charltonadams38
06 Oct 2021, 11:39
( Updated at: 06 Oct 2021, 13:32 )
RE:
amusleh said:
Hi,
When a new bar opens all of its OHLC prices are same as its open price, but when new ticks are coming the high, low, and close will start to develop and change.
If you access the last bar OHLC values inside OnBar method it will be all same, because the OnBar method is called when a new bar opens and the new bar OHLC are all same.
Try this:
using cAlgo.API; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { protected override void OnTick() { Print("Open: {0} | High: {1} | Low: {2} | Close: {3}", Bars.OpenPrices.LastValue, Bars.HighPrices.LastValue, Bars.LowPrices.LastValue, Bars.ClosePrices.LastValue); } } }
If you change the OnTick to OnBar you will see whenever a new bar opens the method will be called and all OHLC prices will be same.
Hi amusleh
First, thank you for your reply and valuable input.
Second, I would like to buy using onTick() will I be able to access the hourly data of a daily candle right before a new candle opens?
For example, I would like to get the High just before a new daily candle starts to ensure the dailyHigh is as accurate as possible.
I am new to programming trading bots and I've been reading through the documentation but there is so much to read through it is hard to find the information I am looking for, hence the reason I have been using OnBar().
Thank you
@charltonadams38
amusleh
06 Oct 2021, 09:04
Hi,
When a new bar opens all of its OHLC prices are same as its open price, but when new ticks are coming the high, low, and close will start to develop and change.
If you access the last bar OHLC values inside OnBar method it will be all same, because the OnBar method is called when a new bar opens and the new bar OHLC are all same.
Try this:
If you change the OnTick to OnBar you will see whenever a new bar opens the method will be called and all OHLC prices will be same.
@amusleh