【发布时间】:2020-03-08 12:20:59
【问题描述】:
pine 脚本回测结果从 V2 到 V4 不同
我尝试将 Pine 脚本 V2 转换为 V4。我认为证券功能从 V2 到 V4 有很多变化。回测结果的变化。如果有人知道解决方案,请帮助我
这是V2 pine脚本策略
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © suryaobulareddy
//@version=2
strategy("Strategy1", overlay=true)
tim=input('50')
//160
isSession = input(defval = true, title = "Apply Trading Session", type = bool)
sess = input(defval = "0935-1500", title="Trading Session")
t = time(period, sess)
sessionOpen = isSession ? (na(t) ? false : true):false
startYear = input(defval = 2020, title = "From Year", type = integer)
startMonth = input(defval = 1, title = "From Month", type = integer )
startDay = input(defval = 1, title = "From Day", type = integer)
endYear = input(defval = 2112, title = "To Year", type = integer)
endMonth = input(defval = 1, title = "To Month", type = integer)
endDay = input(defval = 1, title = "To Day", type = integer)
showDate = input(defval = true, title = "Show Date Range", type = bool)
start = timestamp(startYear, startMonth, startDay, 00, 00) // backtest start window
finish = timestamp(endYear, endMonth, endDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"
out1 = security(tickerid, tim, open)
out2 = security(tickerid, tim, close)
//plot(out1,color=color.red)
//plot(out2,color=color.green)
longCondition = (crossover(security(tickerid, tim, close),security(tickerid, tim, open)) and sessionOpen and window())
shortCondition = (crossunder(security(tickerid, tim, close),security(tickerid, tim, open)) and sessionOpen and window())
val = 0
if (longCondition)
val := 1
strategy.entry("long", strategy.long)
if (shortCondition)
val := -1
strategy.entry("short", strategy.short)
if(not sessionOpen)
val := -3
strategy.close_all(when = not sessionOpen)
plot_stoploss_short= plot(val, title="type", color=red)
这是V4 pine脚本策略
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © suryaobulareddy
//@version=4
strategy("Strategy1", overlay=true)
tim=input('50')
timopen=input('50')
//160
isSession = input(defval = true, title = "Apply Trading Session", type = input.bool)
sess = input(defval = "0935-1500", title="Trading Session")
t = time(timeframe.period, sess)
sessionOpen = isSession ? (na(t) ? false : true):false
startYear = input(defval = 2020, title = "From Year", type = input.integer)
startMonth = input(defval = 1, title = "From Month", type = input.integer )
startDay = input(defval = 1, title = "From Day", type = input.integer)
endYear = input(defval = 2112, title = "To Year", type = input.integer)
endMonth = input(defval = 1, title = "To Month", type = input.integer)
endDay = input(defval = 1, title = "To Day", type = input.integer)
showDate = input(defval = true, title = "Show Date Range", type = input.bool)
start = timestamp(startYear, startMonth, startDay, 00, 00) // backtest start window
finish = timestamp(endYear, endMonth, endDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"
out1 = security(syminfo.tickerid, tim, open)
out2 = security(syminfo.tickerid, tim, close)
longCondition = (crossover(security(syminfo.tickerid, tim, close),security(syminfo.tickerid, timopen, open)) and sessionOpen and window())
shortCondition = (crossunder(security(syminfo.tickerid, tim, close),security(syminfo.tickerid, timopen, open)) and sessionOpen and window())
val = 0
if (longCondition)
val := 1
strategy.entry("long", strategy.long)
if (shortCondition)
val := -1
strategy.entry("short", strategy.short)
if(not sessionOpen)
val := -3
strategy.close_all(when = not sessionOpen)
plot_stoploss_short= plot(val, title="type", color=color.red)
【问题讨论】:
-
您解决了这个问题吗?你能看到我的新问题Change from V2 to V3, a question about security function
标签: pine-script