I want to log data between certain date and time. I want to set Start timestamp and End timestamp and log data between given hours in each day for example between 08:00 and 15:30.
This indicator works but is not logging every day even though I do not see problem with the conditions in my code. For example if I run this indicator on historical data which are from for example 25.9. 2024 until 12.10. 2024 and set my Start timestamp to 26.9. and End timestamp to 12.10. the indicator will start logging from 4.10. and stop logging after 3 days which is on 7.10.
Logging is done by writing into text file.
The Start timestamp and End timestamp are user input parameters which are set in SetDefaults state like this:
var now = DateTime.Now.ToUniversalTime();
StartTimestamp = new DateTime(now.Year, now.Month, now.Day, 7, 30, 0).ToUniversalTime();
EndTimestamp = new DateTime(now.Year, now.Month, now.Day, 15, 30, 0).ToUniversalTime();
My OnBarUpdate method is:
protected override void OnBarUpdate()
{
if (Count < 2)
return;
var timestamp = Time[0].ToUniversalTime();
if (timestamp >= StartTimestamp && timestamp <= EndTimestamp)
{
var start = timestamp.TimeOfDay >= StartTimestamp.TimeOfDay;
var end = timestamp.TimeOfDay <= EndTimestamp.TimeOfDay;
if (start && end)
{
// Write to textfile ommited
}
}
}
Thanks in advance
Kind Regards

Comment