37 lines of AI-generated code for swing trading SP500 on the daily timeframe. Long only. Please remember to run in test before starting it. I also suggest adding a stoploss.
The code
defparam cumulateorders = false
// Define RSI parameters
RSIPeriod = 2
RSIOversold = 15
RSIOverbought = 20
// Calculate RSI
RSIValue = rsi[RSIPeriod]
//Day-of-the-week filter
DayOfWeekFilter = dayofweek
FilterDay = 5 // Friday
// Monthly filter
if month = 0 or month = 1 or month = 2 or month = 3 or month = 4 or month = 10 or month = 11 or month = 12 then
LongMonths = 1
else
LongMonths = 0
endif
if month = 5 or month = 6 or month = 7 or month = 8 or month = 9 then
AvoidMonths = 1
else
AvoidMonths = 0
endif
// Entry condition
if RSIValue crosses under RSIOversold and DayOfWeekFilter = FilterDay and Longmonths then
buy at market
endif
if RSIValue crosses over RSIOverbought and DayOFweekFilter = Filterday and not AvoidMonths then
sell at market
endif
Credit to quantifiedstrategies.com for the initial idea
Comentários