0

我正在尝试在交易视图中的 Pinescript 上运行此脚本。但是,当我尝试添加时间戳时,它不起作用。有人可以帮忙吗?

//@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)
4

1 回答 1

0

给你:

//@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)
于 2021-06-21T15:40:43.083 回答