pine-script - 随机指标低时的最低图表低点
问题描述
当随机指标 K 低于 55 时,我想在图表上画出最低点。
到目前为止,我的代码是:
//@version=4
study(title="Lows", shorttitle="Low of low", overlay=true)
periodK = input(14, title="K", minval=1)
smoothK = input(3, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
lowestInCycle(series) =>
min=101.0
if series < 55
if series < min
min := series
else
min:=na
min != 101.0
plotshape(lowestInCycle(k), title="Test", location=location.belowbar, color=color.red, transp=0, style=shape.triangleup, text="L")
我还修改了随机指标,使其在低于 55 时显示交叉,并且在 K 上越来越低。这仅供参考。
我只想标记每个“低于 55 的随机集群”中的最低价格。
如何才能做到这一点?任何帮助表示赞赏。
PS。不用说我是初学者。自从我写了这篇文章以来,只要玩一下,我就可以让代码变得更好。
提前致谢
解决方案
这使用标签来标识 55 岁以下周期中的最低 k,因此您只能看到最后 500 个周期的标签。当指标实时运行时,k 值最低的柱可以变化,直到 55 以下周期完成。最低 k 值的值与标签一起打印:
//@version=4
study(title="Lows", shorttitle="Low of low", overlay=true, max_labels_count = 500)
periodK = input(14, title="K", minval=1)
smoothK = input(3, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
lowestInCycle(series) =>
_xDn = crossunder(series, 55)
_xUp = crossover(series, 55)
var label _label = na
var float _min = na
if _xDn
// We enter a cycle; create a new label (each cycle has its own label).
_min := series
_label := label.new(bar_index, close, tostring(_min, "#.##"), yloc = yloc.belowbar, color = color.red, textcolor = color.red, style = label.style_arrowup)
// This is just so that all `if` blocks return a float, otherwise compiler complains.
float(na)
else if _xUp
// We exit a cycle.
_min := na
else if not na(_min)
// We are in a cycle; get new minimal value if there is one.
_min := min(_min, series)
if change(_min) < 0
// We are in a cycle and a new minimum was found; update the cycle's label.
label.set_x(_label, bar_index)
label.set_text(_label, tostring(_min, "#.##"))
lowestInCycle(k)
// We need to plot something, otherwise compiler complains.
plot(na)
这显示了正在运行的代码,下面的 Stoch 显示了带有红色背景的循环:
推荐阅读
- swiftui - UIViewControllerRepresentable 奇怪的释放
- windows - 重命名文件夹后如何使用 Perforce P4V 客户端完全删除文件夹?
- ios - 如何为 iOS 14 设置 SwiftUI 应用程序,但如果 iOS 13 仍默认为 AppDelegate?
- hazelcast - IMap.lock() 是否需要 CP 子系统?
- javascript - Javascript 有选择地过滤响应
- html - 如果父容器是块级的,为什么父容器的行高会被其子元素的行高覆盖,但如果它是内联的则不会?
- fortran - Fortran中的增量值?
- python - 使用 min() 函数时忽略字符串
- python-3.x - Python3迁移xml写入问题
- node.js - 将方法重构为单独的文件时,Node.js找不到模块