Currently I'm working on developing code that uses 2 timespans.
1) 8:30a - 9:30a
2) 9:30a - 1:00p
Within the first timespan, I'm tracking highest high and lowest low. These numbers are accurately being updated and printed throughout both timespans.
Within the second timespan, I'm trying to take a trade based on a close above or below either the highest high or lowest low. The trade should stay active until filled.
The issue I'm having is that with strategy analyzer and playback, no trades are being taken so it must be in my code.
Hoping to get some eyes on my code to see what might be causing the issue, please.
Establishing Timespans within OnBarUpdate:
TimeSpan sessionStartTime = new TimeSpan(8, 30, 30); TimeSpan sessionEndTime = new TimeSpan(9, 30, 0); TimeSpan tradeStartTime = new TimeSpan(9, 31, 0); TimeSpan tradeEndTime = new TimeSpan(13, 0, 0);
// Wait for the first bar after 8:30 AM
if (Time[0].TimeOfDay < tradeStartTime)
return;
// Wait for the second bar to close
if (CurrentBar < 2)
return;
// Update the pivotHighestHigh whenever a new highest high is found within the session time
if (High[0] > pivotHighestHigh)
{
pivotHighestHigh = High[0];
Print("New highest high: " + pivotHighestHigh + " at " + Time[0]);
}
// Update the pivotHighestHigh whenever a new lowest low is found within the session time
if (Low[0] < pivotLowestLow)
{
pivotLowestLow = Low[0];
Print("New lowest low: " + pivotLowestLow + " at " + Time[0]);
}
// Check if the current time is within the trade time range
if (Time[0].TimeOfDay >= tradeStartTime && Time[0].TimeOfDay <= tradeEndTime)
{
// Check if the current close is greater than pivotHighestHigh
if (Close[0] > pivotHighestHigh)
{
// Calculate the Long Limit order price 20 points below pivotHighestHigh
double limitPrice = pivotHighestHigh - 20 * TickSize;
// Place the Long Limit order
EnterLongLimit(0, true, 1, limitPrice, "LongTrade");
}
}
}
Thanks,
J

Comment