如何在 Pinescript 中绘制特定时间的最高点和最低点的水平线?

发布于 2025-01-16 23:39:20 字数 363 浏览 0 评论 0原文

我的问题实际上是两个部分。

  1. 如何绘制一条从交易时间之外的特定时间开始的水平线(向右延伸,但不向左延伸)。我实际上想绘制两条水平线,一条位于 10 分钟图表上午 8 点蜡烛的最高点,另一条位于最低点。我希望它也能被历史地绘制。

  2. 如何才能使绘制的线条仅向右延伸,直到新的柱形成更高的高点或更低的低点。 我在图表上手动绘制的高点水平线示例

我什至都不知道从哪里开始呢。我有一些用 Pinescript 写作的经验,但没有按照我想要的方式绘制线条。任何帮助将不胜感激。

My question is really two parts.

  1. How do I plot a horizontal line (that extends to the right but not the left) starting at a specific time of the day, outside of trading hours. I want to plot two horizontal lines actually, one on the high and one on the low of the 8am candle of a 10 minute chart. I would like for it to be plotted historically as well.

  2. How do I make it so that the lines that get plotted only extend to the right until a new bar makes a higher high or a lower low. example horizontal line on the high that I manually drew on the chart

I don't really even know where to start with this. I have some experience writing in Pinescript but not with drawing lines in the way I want. Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听闻余生 2025-01-23 23:39:20
  • 找出新会话
  • 将高值保存在 var
  • 开始绘图,直到出现新的高值
  • 在新会话时重置所有内容

以下是 high 的示例:

//@version=5
indicator("My script", overlay=true, max_lines_count=500)
h = input.int(9, "Hour", minval=0, maxval=59)
m = input.int(30, "Hour", minval=0, maxval=59)

var float first_high = na
var bool can_draw = false
var line l = na

is_new_session = (hour == h) and (minute == m)
bgcolor(is_new_session ? color.new(color.green, 85) : na)

if (is_new_session)     // New session
    first_high := high  // Reset session high
    can_draw := true    // We are allowed to draw a line
    l := line.new(bar_index, first_high, bar_index, first_high, color=color.red)    // Get new line id
else
    if (can_draw)
        if (high > first_high)  // New high is made
            can_draw := false   // Stop drawing
        else
            line.set_x2(l, bar_index)   // Update x2 position of the line (move it to the right)

< a href="https://i.sstatic.net/ASSUa.png" rel="nofollow noreferrer">输入图像描述这里

  • Find out new session
  • Save the high value in a var
  • Start drawing until there is a new high
  • Reset everything when it is a new session

Here is an example for the high:

//@version=5
indicator("My script", overlay=true, max_lines_count=500)
h = input.int(9, "Hour", minval=0, maxval=59)
m = input.int(30, "Hour", minval=0, maxval=59)

var float first_high = na
var bool can_draw = false
var line l = na

is_new_session = (hour == h) and (minute == m)
bgcolor(is_new_session ? color.new(color.green, 85) : na)

if (is_new_session)     // New session
    first_high := high  // Reset session high
    can_draw := true    // We are allowed to draw a line
    l := line.new(bar_index, first_high, bar_index, first_high, color=color.red)    // Get new line id
else
    if (can_draw)
        if (high > first_high)  // New high is made
            can_draw := false   // Stop drawing
        else
            line.set_x2(l, bar_index)   // Update x2 position of the line (move it to the right)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文