简体   繁体   English

Pine Script 策略回测结果从 V2 到 V4 不一样

[英]Pine Script strategy back test results are varing from V2 to V4

pine script back test results are varied from V2 to V4松脚本回测结果从V2到V4不一样

I tried converting Pine script V2 to V4.我尝试将 Pine 脚本 V2 转换为 V4。 I think there is lot of changes in securities function from V2 to V4.我认为从 V2 到 V4,证券功能有很多变化。 changes in back test results.回测结果的变化。 If any one know the solution please do help me如果有人知道解决方案,请帮助我

This is V2 pine script strategy这是 V2 松脚本策略

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

This is V4 pine script strategy这是 V4 松脚本策略

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

Yes there were important changes in how security() behaves starting with v3 .是的, 从 v3 开始, security()行为方式发生了重要变化 It used future lookahead before v3 and the default setting doesn't anymore.它在 v3 之前使用了 future lookahead,默认设置不再使用。

The results you are getting with the v4 backtest will thus be more reliable.因此,您通过 v4 回测获得的结果将更加可靠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM