Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
In C# how do I compare the current bar's time with a hardcoded 14:30:00?
Now I'm getting some odd results. Maybe you can easily see what's going on here:
// This Block of code records the first closing price after 14:30.
if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute >= 30 && m_MyBarFlag == 0)
{
Output.WriteLine("Hour: {0} Minute: {1} Data1 Close: {2} Data2 Close: {3} Settlement Price: {4} Bar Flag {5}",
Bars.TimeValue.Hour, Bars.TimeValue.Minute, Bars.CloseValue, BarsOfData(2).CloseValue, Bars.Close.Value, m_MyBarFlag);
m_settlementPrice.Value = (Bars.CloseValue - BarsOfData(2).CloseValue);
m_MyBarFlag = 1; // This marks that a value was recorded already.
}
if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute < 20) m_MyBarFlag = 0; // This resets the flag for the next day.
The Output of that code on 30 days worth of tick data:
Hour: 14 Minute: 30 Data1 Close: 93.96 Data2 Close: 93.39 Settlement Price: 93.96 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.61 Data2 Close: 93.15 Settlement Price: 93.61 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.35 Data2 Close: 92.88 Settlement Price: 93.35 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.84 Data2 Close: 93.35 Settlement Price: 93.84 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.88 Data2 Close: 93.35 Settlement Price: 93.88 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 94.51 Data2 Close: 93.79 Settlement Price: 94.51 Bar Flag: 0
Why would there not be 30 lines written to output, and why is the settlement price not being calculated?
The reason for this behavior is due to the fact that on certain days there is no bar between , 14:00 and 14:20 that resets the flag. I have modified the code to reset the flag once we are passed midnight, that way the first bar after 14:30 will be captured and trigger the logic.
// This Block of code records the first closing price after 14:30.
if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute >= 30 && m_MyBarFlag == 0)
{
Output.WriteLine("Hour: {0} Minute: {1} Data1 Close: {2} Data2 Close: {3} Settlement Price: {4} Bar Flag {5}",
Bars.TimeValue.Hour, Bars.TimeValue.Minute, Bars.CloseValue, BarsOfData(2).CloseValue, Bars.Close.Value, m_MyBarFlag);