// Define constants
MARKET_OPEN_HOUR = 010000 // Market opens at 9 AM local time (adjust for DST)
MARKET_CLOSE_HOUR = 070000 // Market closes at 4 PM local time (adjust for DST)
TRADE_SIZE = 1 // One contract
// Function to determine if DST is in effect. This is a simplified version.
FUNCTION IsDST()
// This is a very basic approximation. For USA:
// DST starts on the second Sunday in March and ends on the first Sunday in November
month = MONTHOFYEAR
dayOfWeek = DAYOFWEEK
dayOfMonth = DAYOFMONTH
IF month > 3 AND month < 11 THEN
RETURN TRUE // DST from April to October
ELSEIF month = 3 THEN
RETURN dayOfWeek = 0 AND dayOfMonth >= 8 AND dayOfMonth - dayOfWeek <= 14 // Second Sunday in March
ELSEIF month = 11 THEN
RETURN dayOfWeek = 0 AND dayOfMonth < 7 // First Sunday in November
ELSE
RETURN FALSE
END
END
// Adjust market hours for DST
IF IsDST() THEN
MARKET_OPEN_HOUR = MARKET_OPEN_HOUR + 1
MARKET_CLOSE_HOUR = MARKET_CLOSE_HOUR + 1
END
// Trading logic
IF DAYOFWEEK != 6 AND DAYOFWEEK != 0 THEN // Avoid trading on weekend (Saturday=6, Sunday=0)
IF HOUR = MARKET_OPEN_HOUR AND MINUTE = 0 THEN
// Wait for one hour after market open
DELAY(3600) // Delay for one hour in seconds
IF CLOSE[1] > OPEN[1] THEN // Check if the first hourly candle (after delay) closed positive
// Using the new 'TRADE' keyword introduced in v12 for trading operations
TRADE("BUY", TRADE_SIZE, CLOSE)
END
END
// Close position at market close
IF HOUR = MARKET_CLOSE_HOUR AND MINUTE = 0 THEN
// Using the new 'TRADE' keyword for closing positions
TRADE("SELL", TRADE_SIZE, CLOSE)
END
END