I'm working on a strategy to enter a trade just before typical economic news at 10amEST, which would be 7amPST for my time zone. So ideally it would enter long in this case at 6:59:45am.
I think I've got the correct code, but when I run the strategy, I see my buy orders are filled(see the Data Box>Execution>Time) at exactly 7am.
Am I doing something wrong or should I test this in again using real-time data? I've pasted my code below.
Thank you!
protected override void OnBarUpdate()
{
// Define your target entry time (e.g., 09:59:45)
DateTime targetEntryTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 6, 59, 45);
// Debug // Print the Target Entry Time
print targetEntryTime;
// Debug
// Get the current time in the exchange's timezone
DateTime currentTime = Time[0].AddMinutes(BarsPeriod.Value * (BarsInProgress + 1)).AddSeconds(-15); // Adjusting for a 5-minute bar, entering 15 seconds before the bar closes
// Debug // Print the current time
print currentTime;
// Debug
// Check if it's time to enter the position
if (currentTime >= targetEntryTime && currentTime < targetEntryTime.AddSeconds(30)) // 30-second window to act
{
// Conditions to enter a long position, e.g., EnterLong();
EnterLong();
}
}

Comment