I’m new to pinescript (and coding) and trying to code a very basic strategy: buy and sell on alternative dates.
It works when i have two dates, but as soon as I try and create a list, things start to go wrong.
I keep getting a syntax error message after
Any help would be appreciated! Hello! I’m new to pinescript (and coding) and trying to code a very basic strategy: buy and sell on alternative dates.
It works when i have two dates, but as soon as I try and create a list, things start to go wrong.
I keep getting a syntax error message after "buy_dates =", before the "[".
Any help would be appreciated!
``//@version=5`
strategy("Alternate Buy Sell Strategy", overlay=true)
// Define the dates on which you want to buy or sell
**buy_dates = [**
timestamp("2003-09-09"), timestamp("2003-11-04"), timestamp("2004-03-16")
]
// Loop through historical dates
for i = 0 to (len(buy_dates) - 1)
// Check if the current bar's timestamp matches a buy date
if year == year(buy_dates[i]) and month == month(buy_dates[i]) and dayofmonth ==
dayofmonth(buy_dates[i])
// If it's an even index, buy, otherwise sell
if i % 2 == 0
strategy.entry("Buy", strategy.long)
else
strategy.entry("Sell", strategy.short)`
`
New contributor