if ((String.Compare(Time[0].ToString("yyyyddMM"),"20140309") < 0) ||
(String.Compare(Time[0].ToString("yyyyddMM"), "20140330") >0))
{
// do what you want to do...
}
if ((String.Compare(Time[0].ToString("HHmmss"),"143000") < 0) ||
(String.Compare(Time[0].ToString("HHmmss"), "144500") >0))
{
// do what you want to do...
// do nothing between 14:30:00 and 14:45:00
}
but i'm also creating class libraries/trading strategies that run outside of NT
and then a more standard c# approach is better
but if you stay withing NT and don't run the code outside NT,
then the solution of @shodson is cleaner... and preferable
Thanks for the responses! The Multicharts.Net version I came up with is this:
However, now I have another question: How do I get that code to run only once if I am using tick data? The other problem is that by using seconds, I sometimes get no result for that day, because no ticks happened right at the 0th second. Any suggestions?
i was just going to say.... with that if, it will only trigger if exactly on that time there is a bar,
if there is 5 second silence, then your code would not be triggered
therefore you would more likely do something like this :
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?
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?
i think it has to do, where that code is
i don't see any errors right away
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);