如何绘制水平线
我正在尝试绘制水平线为-8%,-15%,-21%和-35%的水平线。
我设法获得了最高的地块,但是我似乎无法通过Pinescript-V5
而不是V5的新复杂性绘制水平线,我将其更改为V3。我大致明白了,但我想将最高的浮点部代替,而不是系列,
这是我当前的脚本:
//@version=3
study(title="The Adam Khoo Magic", overlay=true)
//Input options
highlength = input(title="High Length", defval=20, type=integer)
//calculate values
highhighs = highest(high, length=highlength)
minuseight = highhighs*0.92
minusfifteen = highhighs*0.85
minustwentyone = highhighs*0.79
minusthirtyfive = highhighs*0.65
p8 = plot(minuseight, title="-8%", color=olive, linewidth=2, style=line)
p15 = plot(minusfifteen, title="-15%", color=purple, linewidth=2, style=line)
p21 = plot(minustwentyone, title="-21%", color=navy, linewidth=2, style=line)
p35 = plot(minusthirtyfive, title="-35%", color=black, linewidth=2, style=line)
fill(p8, p15, color=red)
fill(p15, p21, color=blue)
fill(p21, p35, color=green)
//plot values on the chart
plot(series=highhighs, color=green, linewidth=1)
plot(minuseight, title="-8%", color=olive, linewidth=2, style=line)
plot(minusfifteen, title="-15%", color=purple, linewidth=2, style=line)
plot(minustwentyone, title="-21%", color=navy, linewidth=2, style=line)
plot(minusthirtyfive, title="-35%", color=black, linewidth=2, style=line)
I am trying to draw horizontal lines where it's -8%, -15%, -21%, and -35% of the previous high.
I managed to get the highest plot, but I can't seem to get the horizontal lines drawn with the new complexity of pinescript-v5
Instead of V5, I've changed it to V3. I roughly got the idea but I would like to base the highest as float instead of a series
This is my current script:
//@version=3
study(title="The Adam Khoo Magic", overlay=true)
//Input options
highlength = input(title="High Length", defval=20, type=integer)
//calculate values
highhighs = highest(high, length=highlength)
minuseight = highhighs*0.92
minusfifteen = highhighs*0.85
minustwentyone = highhighs*0.79
minusthirtyfive = highhighs*0.65
p8 = plot(minuseight, title="-8%", color=olive, linewidth=2, style=line)
p15 = plot(minusfifteen, title="-15%", color=purple, linewidth=2, style=line)
p21 = plot(minustwentyone, title="-21%", color=navy, linewidth=2, style=line)
p35 = plot(minusthirtyfive, title="-35%", color=black, linewidth=2, style=line)
fill(p8, p15, color=red)
fill(p15, p21, color=blue)
fill(p21, p35, color=green)
//plot values on the chart
plot(series=highhighs, color=green, linewidth=1)
plot(minuseight, title="-8%", color=olive, linewidth=2, style=line)
plot(minusfifteen, title="-15%", color=purple, linewidth=2, style=line)
plot(minustwentyone, title="-21%", color=navy, linewidth=2, style=line)
plot(minusthirtyfive, title="-35%", color=black, linewidth=2, style=line)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题仅仅是Hline功能的性质。它不能从一系列数据中获取。第二个问题是,您不能以这种方式将系列转换为单个数据点,以解决Hline函数的问题。
但是,有一个解决方案,而是使用自定义
行
s。请注意,我正在使用Pinescript V5,因为我更熟悉它。
首先,我们绘制填充颜色,因为此功能能够使用一系列数据。
这将为您绘制填充颜色,但由于
display = display.none
参数,因此避免绘制该系列。现在更复杂的部分;在它们之间绘制水平线。为此,我们首先创建空行变量,重要的是,在
line
关键字之前,请使用var
关键字。如果没有
var
关键字,图表数据的每个更新都会以我们不需要的方式与我们的line
变量混乱。接下来,我们使用IF语句检查使用适当的位置数据来更新线变量的特定条件。
最后,我们每次关闭栏时都会删除行:
按照该顺序将所有内容放在一起,而您提出的代码将有效,并将包括您想要的动态水平线!
注意,我们使用该系列绘制填充颜色而不是动态水平线的原因是因为与您的原始问题相似的技术原因。填充函数不能将行变量用作输入。
The issue is simply the nature of the hline function. It cannot draw from a series of data. The second issue is that you cannot convert a series into a single data point in such a way to resolve the issue as far as the hline function goes.
There is however a solution to this, and it's to instead use custom
line
s.Note I am using pinescript v5 because I am more familiar with it.
First, we draw the fill color, since this function is able to use a series of data.
This will draw the fill colors for you but will avoid drawing the series because of the
display=display.none
parameter. Now the more complex part; drawing the horizontal lines between them.To do this, we start by creating empty line variables, importantly using the
var
keyword before theline
keyword.Without the
var
keyword, every update of the chart data will mess with ourline
variables in ways we don't want.Next, we check for the specific conditions in which we want to update the line variables with the appropriate position data, using if statements.
Lastly, we delete the lines every time a bar closes:
Put all that together in that order and the code you presented will work and will include the dynamic horizontal lines you wanted!
Note, the reason we use the series to draw the fill colors instead of the dynamic horizontal lines is because of similar technical reasons to your original issue; the fill function cannot use line variables as input.