I’m trying to use Grok AI to generate basic strategies.
The prompt is: ”
write me an algo that opens a trade 1 hour after market open. if the first hourly candle closes positive, open a long trade of one contract. close the position at market close of the day.”
I’m getting an error on Line 1.
It’s returned this, does anyone know what needs to be added to remediate the error?
// 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
line 7 functions or calls to functions do not exist with PRT
Your prompt did not refer to PRT, try again and state strategy to run on ProRealTime Platform.
Your code above contains several errors (will not work on PRT) so best solution is to do above.
Hi!
Currently, the AI is not capable of creating good code for Probuilder. For python it works very well, but not for Prorealtime.
The only option to have some “luck” with the results is to give the AI a coding example. Even then, it will still give errors.
good luck 🙂