How to get current unclosed bar open price in BarOpened event
How to get current unclosed bar open price in BarOpened event
08 Dec 2022, 15:57
Hi
I'm getting the current bar open price as the previous bar open price. Excepted price is 1784.38 as shown in the below image.
2022-12-08 20:06:01.005 +08:00 [DBG] Bars_BarOpened LastBar 8/12/2022 12:06:00 pm 1784.1139453125 1784.79 1784.1139453125 1784.79
2022-12-08 20:06:01.005 +08:00 [DBG] Bars_BarOpened Time 8/12/2022 12:06:00 pm Bid:1784.79 Ask:1784.96
2022-12-08 20:06:01.005 +08:00 [DBG] Bars_BarOpened Last(1) 8/12/2022 12:04:00 pm 1784.1139453125 1784.85 1784.1139453125 1784.65
2022-12-08 20:06:01.006 +08:00 [DBG] Bars_BarOpened Last(0) 8/12/2022 12:06:00 pm 1784.1139453125 1784.79 1784.1139453125 1784.79
2022-12-08 20:06:01.006 +08:00 [DBG] OnBar 8/12/2022 12:04:00 pm 1784.1139453125 1784.85 1784.1139453125 1784.65
private void Bars_BarOpened(BarOpenedEventArgs obj)
{
Print("BarOpened called at {0}", Server.Time);
var ohlc = obj.Bars.LastBar;
var ohlc1 = Bars.Last(1);
var ohlc2 = Bars.Last(0);
logger.LogDebug($"Bars_BarOpened LastBar \t {ohlc.OpenTime.ToString()}\t{ohlc.Open}\t{ohlc.High}\t{ohlc.Low}\t{ohlc.Close}");
logger.LogDebug($"Bars_BarOpened Time\t {this.Time.ToString()}\t Bid:{this.Bid}\t Ask:{this.Ask}");
logger.LogDebug($"Bars_BarOpened Last(1) {ohlc1.OpenTime.ToString()}\t{ohlc1.Open}\t{ohlc1.High}\t{ohlc1.Low}\t{ohlc1.Close}");
logger.LogDebug($"Bars_BarOpened Last(0) {ohlc2.OpenTime.ToString()}\t{ohlc2.Open}\t{ohlc2.High}\t{ohlc2.Low}\t{ohlc2.Close}");
}
protected override async void OnBar()
{
var ohlc = Bars.Last(1);
logger.LogDebug($"OnBar {ohlc.OpenTime.ToString()}\t{ohlc.Open}\t{ohlc.High}\t{ohlc.Low}\t{ohlc.Close}");
}
r.stipriaan
12 Dec 2022, 22:42
hi,
maybe u can use bid or ask istead of Bars.Last() ?
@r.stipriaan