在两个先前计算的指标之间找到最高的 bar_index

如何解决在两个先前计算的指标之间找到最高的 bar_index

我正在尝试实施分形来寻找支撑位和阻力位。我可以使用以下代码找到“支持”分形:

//@version=4
study("Fractals v1",overlay=true,max_bars_back=300)

var offset = input(defval=2,title='depth',type=input.integer,minval=2,maxval=3)

add_to_array(arr,val) =>
    array.shift(arr)
    array.push(arr,val)

//======================= Support levels =========================================================================================================================================================================

var previous_lows = array.new_int(3)

support_at_depth_2() =>
    a = low[0]
    b = low[1]
    c = low[2] // mid point - we are checking if this low is the lowest in the set 0-4
    d = low[3] 
    e = low[4]
    
    leftSide = c <= b and c <= a ? true : false
    rightSide = c <= d and c <= e ? true : false
    result = leftSide and rightSide
    add_to_array(previous_lows,bar_index[2])
    result


support_at_depth_3() =>
    a = low[0]
    b = low[1]
    c = low[2]
    d = low[3] // mid point - we are checking if this low is the lowest in the set 0-6
    e = low[4]
    f = low[5]
    g = low[6]
    leftSide = d <= c and d <= b and d <= a ? true : false
    rightSide = d <= e and d <= f and d <= g ? true : false
    result = leftSide and rightSide
    add_to_array(previous_lows,bar_index[3])
    result // return bool


support = offset == 2 ? support_at_depth_2() : support_at_depth_3()

plotshape(support,style=shape.triangleup,location=location.belowbar,color=color.olive,size = size.small,offset=-offset)

绘制在交易视图图表上:

enter image description here


我已经为“阻力”分形实现了相同的逻辑,但这有时会产生我不想要的结果 - 例如两个“阻力分形”并排出现。

我想要实现的是一种模式

  • “高、低、高、低、高、低……”

...而不是:

  • “高、低、高、高、低、高、低……”

所以添加的代码是:

var previous_highs = array.new_int(3)

resistance_at_depth_2() =>
    a = high[0]
    b = high[1]
    c = high[2] // mid point - we are checking if this low is the lowest in the set 0-4
    d = high[3] 
    e = high[4]
    
    leftSide = c >= b and c >= a ? true : false
    rightSide = c >= d and c >= e ? true : false
    result = leftSide and rightSide
    add_to_array(previous_highs,bar_index[2])
    result


resistance_at_depth_3() =>
    a = high[0]
    b = high[1]
    c = high[2]
    d = high[3] // mid point - we are checking if this low is the lowest in the set 0-6
    e = high[4]
    f = high[5]
    g = high[6]
    leftSide = d >= c and d >= b and d >= a ? true : false
    rightSide = d >= e and d >= f and d >= g ? true : false
    result = leftSide and rightSide
    add_to_array(previous_highs,bar_index[3])
    result // return bool


resistance = offset == 2 ? resistance_at_depth_2() : resistance_at_depth_3()

plotshape(resistance,style=shape.triangledown,location=location.abovebar,color=color.red,offset=-offset)

正如我所说,这有时会导致我正在寻找的错误模式,如下图所示:

enter image description here


我对如何解决这个模式问题的想法是简单地在 bar_index 处找到两个“支撑”分形(绿色向上箭头)和 plotshape() 之间的最高点。我曾尝试(但收效甚微)实现与我的想法类似的东西,但尚未成功。

?- 我能否抓住当前支撑位和前一个支撑位之间的时间段并循环遍历该范围内的柱线,然后尝试抓住最高的 high 并且它是 bar_index

我是 pine 脚本和其他编程语言 (Python/JavaScript) 的新手,我会将条形图的详细信息保存到 dict/object 中,然后将它们推送到数组中。然后我将遍历数组找到每个支持级别(使用上述分形方法)并在适用时向每个字典/对象添加 support = true,然后我可以再次遍历列表/数组以填充每个支持之间的最高高度 = = 真的。对于 pine 脚本,我觉得这些选项(目前)有点有限,我必须找到 pine 脚本的“细微差别”和解决方法。

我感谢任何关于此的指针或帮助(以及一般的 pine 脚本),或者即使这可以使用 pine 脚本中更简单的方法来实现。

提前致谢。

解决方法

我认为您需要使用额外的浮点数组来存储枢轴价格以及柱线索引,并使用 var bool 来跟踪发生的最后一个枢轴是“阻力”还是“支撑”。

例如,如果您获得连续的阻力支点,则可以将添加到阵列的最后一个阻力与新的阻力支点进行比较,如果新阻力支点更高,则使用 array.set 修改最近的阵列元素而不是向数组添加一个新的枢轴。

如果新的阻力支点较低,则不会向阵列添加任何内容,仅保留先前的支点。

如果之前的事件是支撑支点,则无论之前存储的阻力值如何,您都会向阻力阵列添加一个新的阻力支点。

您还需要使用标签数组而不是 plotshape(),以便您可以删除或移动之前的阻力轴心标记标签,当旧阻力轴心之后是连续的更高轴心时。

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

相关推荐


使用本地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-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res