In building a utility, I am having difficulty assigning the DateTime value of the bar where conditions were met to a variable. Perhaps someone with more experience could provide the correct syntax to use in Sets to assign the value. I believe the variable is declared correctly and the Print statement is correct since it compiles.
The purpose is simply to identify, record and print the time of day when the high or low price occurred. (Historical data only). Assigning a time window then a bool ensures only one High & one Low price (with their corresponding date and time values) are printed for each day.
In the file: SampleDateTimeFunctions_NT8.zip located here: https://ninjatrader.com/support/help...lating_datetim e_objects.htm
the programmer demonstrates various DateTime functions and output options. Unfortunately, I don't see a reference to capturing specific bar times to a variable.
In this utility the DateTime variable is declared as "TimeStamp":
public class HighLowTimeCapture : Strategy
{
private bool PeriodEnd;
private double PriceHigh;
private double PriceLow;
private DateTime TimeStamp;
The Print Statement looks like this:
Print(@"High:" + Convert.ToString(PriceHigh) + " " + Convert.ToString(TimeStamp) + @" Low:" + Convert.ToString(PriceLow) + " " + Convert.ToString(TimeStamp));
The above will compile, however once the DateTime value of bar [0] is assigned to the variable, it will not compile.
Example: In the Set where High price conditions are met, the time of the current bar in the historical data must be saved to the user variable "TimeStamp" declared above.
// Set 3
if ((High[0] > PriceHigh)
&& (Times[0][0].TimeOfDay >= TimeStart.TimeOfDay)
&& (Times[0][0].TimeOfDay <= TimeStop.TimeOfDay))
{
PriceHigh = High[0];
TimeStamp = DateTime[0];
PeriodEnd = true;
}
Attempting to compile this syntax posts the error: 'System.DateTime' is a 'type' but is used like a 'variable'. It doesn't seem logical for "system" time to be relevant to historical bar data.
How can the historical date and time of the bar when conditions were met be saved to the variable TimeStamp?
Thanks for all replies.
culpepper

Comment