【问题标题】:PineScript - How to plot a line in upper graph (MA) or lower graph (RSI)PineScript - 如何在上图 (MA) 或下图 (RSI) 中绘制一条线
【发布时间】:2021-08-28 18:56:55
【问题描述】:

是否有不同的方式在上图(如 MA 指标)或下图(如 RSI 指标)中绘制一条线,因为我看不出代码中有任何差异。

是否可以有一个指标来绘制两个图表(向上和向下)?

上图类似 MA

//@version=4
study(title="Moving Average", shorttitle="MA", overlay=true, resolution="")
len = input(9, minval=1, title="Length")
src = input(close, title="Source")
offset = input(title="Offset", type=input.integer, defval=0, minval=-500, maxval=500)
out = sma(src, len)
plot(out, color=color.blue, title="MA", offset=offset)

类似RSI的下图

//@version=4
study(title="Relative Strength Index", shorttitle="RSI", format=format.price, precision=2, resolution="")
len = input(14, minval=1, title="Length")
src = input(close, "Source", type = input.source)
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=#7E57C2)
band1 = hline(70, "Upper Band", color=#787B86)
bandm = hline(50, "Middle Band", color=color.new(#787B86, 50))
band0 = hline(30, "Lower Band", color=#787B86)
fill(band1, band0, color=color.rgb(126, 87, 194, 90), title="Background")

【问题讨论】:

    标签: pine-script tradingview-api


    【解决方案1】:

    在study() 中有overlay 参数。使用 overlay = true 将指标放置在主窗格中,overlay = false 放置在类似 RSI 的子窗格中。

    您只能将指标/脚本分配给单个窗格,所以不,您不能同时绘制。

    【讨论】:

      【解决方案2】:

      您也可以使用 hline 函数来绘制水平线 line.new。如果要在顶部和底部屏幕上绘图,则需要在顶部和底部添加代码。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-11-09
        • 1970-01-01
        • 2021-03-26
        • 1970-01-01
        • 2013-10-04
        • 1970-01-01
        • 2014-04-11
        • 1970-01-01
        相关资源
        最近更新 更多