Tradingview pine script 策略故障排除 -> 研究转换

如何解决Tradingview pine script 策略故障排除 -> 研究转换

我一直在将 pine 脚本中的 Tradingview 策略 转换为 研究,但我收到了额外的买入和卖出信号,我不知道为什么。我相信该脚本不会重绘,并且可以改编为机器人的盈利触发器。

这是一张图片,其中向上或向下三角形显示触发器(在警报之前一个条)。尽管正确的触发器也存在,但您可以从策略中看到许多额外的三角形与空头和多头订单。 screenshot of chart with strategy short/long versus alerts as triangles

我的问题可能与我如何替换策略跟踪未结订单和止盈的方式有关。

在原始脚本中,长条目由 up7up8 信号指示,但 up8 使用 strategy.position_avg_price,这些数据在研究中不可用。

strategy.entry 还使用了一些 if/else 语句 (? :),我不确定我是否 100% 确定我正确适应。

这是原始脚本:

//Noro
//2018

//@version=2
strategy("Noro's Bands Scalper Strategy v1.6",shorttitle = "Scalper str 1.6",overlay = true,default_qty_type = strategy.percent_of_equity,default_qty_value = 100.0,pyramiding = 0)

//Settings
needlong = input(true,defval = true,title = "Long")
needshort = input(true,title = "Short")
takepercent = input(0,defval = 0,minval = 0,maxval = 1000,title = "take,%")
needbe = input(true,title = "Bands Entry")
needct = input(false,defval = false,title = "Counter-trend entry")
bodylen = input(10,defval = 10,maxval = 50,title = "Body length")
trb = input(1,defval = 1,minval = 1,maxval = 5,title = "Trend bars")
len = input(20,defval = 20,minval = 2,maxval = 200,title = "Period")
needbb = input(true,title = "Show Bands")
needbg = input(true,title = "Show Background")
fromyear = input(1900,defval = 1900,minval = 1900,maxval = 2100,title = "From Year")
toyear = input(2100,defval = 2100,title = "To Year")
frommonth = input(01,defval = 01,minval = 01,maxval = 12,title = "From Month")
tomonth = input(12,defval = 12,title = "To Month")
src = close

//PriceChannel 1
lasthigh = highest(src,len)
lastlow = lowest(src,len)
center = (lasthigh + lastlow) / 2

//Distance
dist = abs(src - center)
distsma = sma(dist,len)
hd = center + distsma
ld = center - distsma
hd2 = center + distsma * 2
ld2 = center - distsma * 2

//Trend
chd = close > hd
cld = close < ld
uptrend = trb == 1 and chd ? 1 : trb == 2 and chd and chd[1] ? 1 : trb == 3 and chd and chd[1] and chd[2] ? 1 : trb == 4 and chd and chd[1] and chd[2] and chd[3] ? 1 : trb == 5 and chd and chd[1] and chd[2] and chd[3] and chd[4] ? 1 : 0
dntrend = trb == 1 and cld ? 1 : trb == 2 and cld and cld[1] ? 1 : trb == 3 and cld and cld[1] and cld[2] ? 1 : trb == 4 and cld and cld[1] and cld[2] and cld[3] ? 1 : trb == 5 and cld and cld[1] and cld[2] and cld[3] and cld[4] ? 1 : 0
trend = dntrend == 1 and high < center ? -1 : uptrend == 1 and low > center ? 1 : trend[1]

//trend = close < ld and high < center ? -1 : close > hd and low > center ? 1 : trend[1]

//Lines
colo = needbb == false ? na : black
plot(hd2,color = colo,linewidth = 1,transp = 0,title = "High band 2")
plot(hd,title = "High band 1")
plot(center,title = "center")
plot(ld,title = "Low band 1")
plot(ld2,title = "Low band 2")

//Background
col = needbg == false ? na : trend == 1 ? lime : red
bgcolor(col,transp = 80)

//Body
body = abs(close - open)
smabody = ema(body,30) / 10 * bodylen

//Signals
bar = close > open ? 1 : close < open ? -1 : 0
up7 = trend == 1 and ((bar == -1 and bar[1] == -1) or (body > smabody and bar == -1)) ? 1 : 0
dn7 = trend == 1 and ((bar == 1 and bar[1] == 1) or (close > hd and needbe == true)) and close > strategy.position_avg_price * (100 + takepercent) / 100 ? 1 : 0
up8 = trend == -1 and ((bar == -1 and bar[1] == -1) or (close < ld2 and needbe == true)) and close < strategy.position_avg_price * (100 - takepercent) / 100 ? 1 : 0
dn8 = trend == -1 and ((bar == 1 and bar[1] == 1) or (body > smabody and bar == 1)) ? 1 : 0

if up7 == 1 or up8 == 1 
    strategy.entry("Long",strategy.long,needlong == false ? 0 : trend == -1 and needct == false ? 0 : na,when=(time > timestamp(fromyear,frommonth,01,00,00) and time < timestamp(toyear,tomonth,31,00)))

if dn7 == 1 or dn8 == 1
    strategy.entry("Short",strategy.short,needshort == false ? 0 : trend == 1 and needct == false ? 0 : na,00)))
    
if time > timestamp(toyear,00)
    strategy.close_all()

这是我的版本,仅在 //Signals 部分之后进行了更改。它使用 lastLonglastShort 作为本来是 strategy_position_avg_price 的占位符。 (我的版本还绘制了买入和卖出信号的形状以与策略进行比较)

//@version=2
study("RSTU-Noro's Bands Scalper",shorttitle = "RSTUD Scalper 1.6",overlay = true)

//Settings
needlong = input(true,defval = 19,defval = 4,30) / 10 * bodylen

//Signals
lastLong = 0
lastShort = 0

bar = close > open ? 1 : close < open ? -1 : 0
up7 = trend == 1 and ((bar == -1 and bar[1] == -1) or (body > smabody and bar == -1)) ? 1 : 0
dn7 = trend == 1 and ((bar == 1 and bar[1] == 1) or (close > hd and needbe == true)) and close > lastShort * (100 + takepercent) / 100 ? 1 : 0
up8 = trend == -1 and ((bar == -1 and bar[1] == -1) or (close < ld2 and needbe == true)) and close < lastLong * (100 - takepercent) / 100 ? 1 : 0
dn8 = trend == -1 and ((bar == 1 and bar[1] == 1) or (body > smabody and bar == 1)) ? 1 : 0

longEntry = up7 == 1 or up8 == 1 and needlong == true and needct == true
alertcondition(longEntry and trend == -1,title="Long",message="Long")
plotshape(longEntry,style=shape.triangleup,location=location.belowbar,color=green)
if longEntry and trend == -1
    lastLong = open
    
shortEntry = dn8 == 1 or dn7 == 1 and needshort == true and needct == true
alertcondition(shortEntry and trend == 1,title="Short",message="Short")
plotshape(shortEntry,style=shape.triangledown,location=location.abovebar,color=red)
if shortEntry and trend == 1
    lastShort = open
    

任何帮助使其正常工作都会很棒。 ?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-