0

I am trying to run this script on Pinescript in Trading View. However, when I try to add in timestamp, it does not work. Can someone help with this?

//@version=4
strategy("My Strategy", overlay=true)

start = timestamp(2007, 1, 1, 0, 0)
end = timestamp(2009, 3, 31, 0, 0)

// Indicators
SMA50 = sma(close, 50)
SMA100 = sma(close, 100)
rsi = rsi(close, 14)
atr = atr(14)

// Crossover conditions 
longCondition = crossover(SMA50, SMA100)

if (longCondition)
    stopLoss = low - atr * 2
    takeProfit = high + atr * 6
    strategy.entry("long", strategy.long, 100, when = rsi > 30)
    strategy.exit ("exit", "long", stop=stopLoss, limit=takeProfit)
    
    
// Plotting SMAs in the chart.
plot(SMA50)
plot(SMA100,color=color.black)
Bjorn Mistiaen
  • 6,459
  • 3
  • 18
  • 42
oaker
  • 27
  • 1
  • 8

1 Answers1

0

Here you are:

//@version=4
strategy("My Strategy", overlay=true)

start = input(timestamp("2007-01-01T00:00"), type = input.time)
end = input(timestamp("2009-03-31T00:00"), type = input.time)

// Indicators
SMA50 = sma(close, 50)
SMA100 = sma(close, 100)
rsi = rsi(close, 14)
atr = atr(14)

// Crossover conditions 
longCondition = crossover(SMA50, SMA100)

if (longCondition and time >= start and time <= end)
    stopLoss = low - atr * 2
    takeProfit = high + atr * 6
    strategy.entry("long", strategy.long, 100, when = rsi > 30)
    strategy.exit ("exit", "long", stop=stopLoss, limit=takeProfit)
    
    
// Plotting SMAs in the chart.
plot(SMA50)
plot(SMA100,color=color.black)
Andrey D
  • 1,534
  • 1
  • 5
  • 7
  • This doesn't work :( The trade should start on January 1, 2007 and end on March 31, 2009 but it made no changes to the chart. Is there something wrong? – oaker Jun 21 '21 at 23:19
  • I've thought that you want to specify backtesting time interval for your strategy. If it is not true, please clarify your needs. – Andrey D Jun 22 '21 at 14:44