交易视图上时间戳的 Pine 脚本代码不会过滤我希望它查看的日期我该如何调整?

问题描述

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

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

start = timestamp(2007,1,0)
end = timestamp(2009,3,31,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)

解决方法

给你:

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