Bar Status of Open not set at every bar open

Questions about MultiCharts .NET and user contributed studies.
MidKnight
Posts: 343
Joined: 12 Aug 2012
Has thanked: 123 times
Been thanked: 56 times

Bar Status of Open not set at every bar open

Postby MidKnight » 15 Sep 2014

When running an indicator in real-time and trying to detect the bar open. It is quite frequently never in an open state. This seems like a serious issue.

Indicator code:

Code: Select all

if (Bars.LastBarOnChart)
{
if (Bars.Status == EBarState.Open)
{
Output.WriteLine("new bar: {0}", Bars.Time[0].TimeOfDay);
}
}
Output

Code: Select all

new bar: 13:22:06
new bar: 13:23:57
new bar: 13:24:51
Attachments
MK_2014-09-15_173055.png
(20.49 KiB) Downloaded 1707 times

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Bar Status of Open not set at every bar open

Postby JoshM » 15 Sep 2014

When running an indicator in real-time and trying to detect the bar open. It is quite frequently never in an open state. This seems like a serious issue.
This is with the Release Candidate version of MC 9, right? I'm asking because it does not seem to be happening with MultiCharts .NET64 Version 8.8 Release (Build 8365):

Code: Select all

#3760 - Time: 11:33:54
#3761 - Time: 11:34:01
#3762 - Time: 11:34:23
#3763 - Time: 11:34:42
#3764 - Time: 11:35:02
#3765 - Time: 11:35:22
#3766 - Time: 11:35:53
#3767 - Time: 11:36:20
#3768 - Time: 11:36:26
#3769 - Time: 11:36:37
#3770 - Time: 11:36:49
#3771 - Time: 11:36:57
#3772 - Time: 11:37:23
#3773 - Time: 11:37:31
#3774 - Time: 11:38:04
#3775 - Time: 11:38:55
#3776 - Time: 11:39:23
#3777 - Time: 11:39:52
#3778 - Time: 11:40:24
#3779 - Time: 11:40:33
#3780 - Time: 11:40:57
#3781 - Time: 11:41:24
#3782 - Time: 11:41:43
#3783 - Time: 11:42:45
#3784 - Time: 11:43:35
#3785 - Time: 11:44:06
#3786 - Time: 11:44:35
#3787 - Time: 11:45:19

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
public class Forum_BarStatus : IndicatorObject
{
public Forum_BarStatus(object _ctx) : base(_ctx) { }

protected override void CalcBar()
{
if (Bars.Status == EBarState.Open)
{
Output.WriteLine("#{0} - Time: {1}",
Bars.CurrentBar,
Bars.Time[0].ToString("HH:mm:ss"));
}
}
}
}

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Bar Status of Open not set at every bar open

Postby JoshM » 15 Sep 2014

I'm asking because it does not seem to be happening with MultiCharts .NET64 Version 8.8 Release (Build 8365):
I was too soon in responding; the issue also occurs with MC 8.8, but the issue is not with `Bars.Status` but with the `Bars.LastBarOnChart` property (at least, that's the case in the version I use; don't know if this also affects MidKnight).

According to the chm help file, this property:
Indicates whether current bar is the last bar on the chart.
But on tick charts (as MidKnight showed) this is not the case, because the property is always false even though the bar is the last bar on the chart:

Code: Select all

#3814 - LastBarNum: 3814 - LastBarOnChart? False
#3814 - LastBarNum: 3814 - LastBarOnChart? False
#3814 - LastBarNum: 3814 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3815 - LastBarNum: 3815 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3816 - LastBarNum: 3816 - LastBarOnChart? False
#3817 - LastBarNum: 3817 - LastBarOnChart? False
#3817 - LastBarNum: 3817 - LastBarOnChart? False
#3817 - LastBarNum: 3817 - LastBarOnChart? False
#3817 - LastBarNum: 3817 - LastBarOnChart? False
#3817 - LastBarNum: 3817 - LastBarOnChart? False
#3817 - LastBarNum: 3817 - LastBarOnChart? False
#3817 - LastBarNum: 3817 - LastBarOnChart? False
#3817 - LastBarNum: 3817 - LastBarOnChart? False
#3818 - LastBarNum: 3818 - LastBarOnChart? False

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
public class Forum_BarStatus : IndicatorObject
{
public Forum_BarStatus(object _ctx) : base(_ctx) { }

protected override void StartCalc()
{
Output.Clear();
}

protected override void CalcBar()
{
Output.WriteLine("#{0} - LastBarNum: {1} - LastBarOnChart? {2}",
Bars.CurrentBar,
Bars.FullSymbolData.Count,
Bars.LastBarOnChart);
}
}
}
Edit: MidKnight, as a workaround you can use the `Environment.IsRealTimeCalc` property as a substitute for `Bars.LastBarOnChart` if this issue also affects you. That would give the same behaviour (only executing the code block on the last bar), but does not lead to skipping Bar Status == Open situations (in my case).

MidKnight
Posts: 343
Joined: 12 Aug 2012
Has thanked: 123 times
Been thanked: 56 times

Re: Bar Status of Open not set at every bar open

Postby MidKnight » 15 Sep 2014

OK, I didn't even try my code without lastbaronchart but in my case on MC.net64 9.0 RC1 with tick charts it is sometimes firing and sometimes not. There is a real problem there somewhere. I'll try your suggestion tomorrow - thank you.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Bar Status of Open not set at every bar open

Postby JoshM » 15 Sep 2014

There is a real problem there somewhere.
I agree. Henry (or someone else), can you explain how Bars.Status works in conjunction with Bars.LastBarOnChart?

For example, when I use both in my code, drawings do not get created:

Code: Select all

if (Bars.LastBarOnChart)
{
if (Bars.Status == EBarState.Open)
{
DrawTriangle();
}
}
But if I use only one, for example:

Code: Select all

if (Bars.Status == EBarState.Open)
{
DrawTriangle();
}
..it works.

Intuitively, it seems that a real-time tick that is the open of the bar (`Bars.Status == EBarState.Open`) has to be the last bar on the chart (`Bars.LastBarOnChart == true`). Otherwise, it wouldn't be a real-time tick (right?). But that does not always seems to be the case.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Bar Status of Open not set at every bar open

Postby Henry MultiСharts » 15 Sep 2014

I'm asking because it does not seem to be happening with MultiCharts .NET64 Version 8.8 Release (Build 8365):
I was too soon in responding; the issue also occurs with MC 8.8, but the issue is not with `Bars.Status` but with the `Bars.LastBarOnChart` property (at least, that's the case in the version I use; don't know if this also affects MidKnight).
That is a known issue that has been resolved in MultiCharts .NET 9.0 Beta1.


As for your last post - the following code works ok on our end using MultiCharts .NET64 Version 9.0 Release Candidate (Build 9880):

Code: Select all

protected override void CalcBar()
{
if (Bars.LastBarOnChart)
{
if (Bars.Status == EBarState.Open)
{
Output.WriteLine("new bar: {0}", Bars.Time[0].TimeOfDay);
plot1.Set(Bars.OpenValue);
}
}
}
Image
Attachments
2014-09-15_154756_pp.png
(25.65 KiB) Downloaded 1775 times

MidKnight
Posts: 343
Joined: 12 Aug 2012
Has thanked: 123 times
Been thanked: 56 times

Re: Bar Status of Open not set at every bar open

Postby MidKnight » 16 Sep 2014

Well, it is not resolved on my 9.0 RC Build 9913 that you had me download today, Henry. Using LastBarOnChart consistently gives inconsistent results. I didn't even have to wait long to get these missing plots, imagine how many one would get on an entire day if using this code in a small timeframe chart. Using Environment.IsRealTimeCalc always seems to work (thanks for the idea JoshM).

Code:

Code: Select all

protected override void CalcBar()
{
if (Bars.LastBarOnChart)
{
if (Bars.Status == EBarState.Open)
{
Output.WriteLine("new bar: {0}", Bars.Time[0].TimeOfDay);
plot1.Set(Bars.Open[0]);
}
}
}
Attachments
MK_2014-09-16_181358.png
(8 KiB) Downloaded 1644 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Bar Status of Open not set at every bar open

Postby Henry MultiСharts » 16 Sep 2014

This issue will be resolved in MultiCharts .NET 9.0 Release.


Return to “MultiCharts .NET”