如何在 TradingView pine 脚本中绘制一条垂直线? [英] How to draw a vertical line in TradingView pine script?

查看:89
本文介绍了如何在 TradingView pine 脚本中绘制一条垂直线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用基于网络的

(2)plot()style=histogram 参数一起使用时效果更好:

//@version=3Study(title="vbar2", overlay = true)//scale=scale.none 仅用于overlay=truevlinecol = #000000//黑色cond = barstate.islastbh = 10*high//使用 10 x vbar 顶部的窗口最大价格高度(或使用 1e20)bo = -10//设置距最后一根柱线的偏移量plot(cond ? bh : na, color=vlinecol, linewidth=2, offset=bo, style = histogram, transp=0)

结果如下:

解决方案

如果有人有兴趣使用新的 v4 line.new() 功能:

注意:根据需要调整LineLengthMult.

//此源代码受 https://mozilla.org/MPL/2.0/上 Mozilla Public License 2.0 的条款约束//© 市场脚本//@版本=4研究(我的脚本",overlay=true)LineLengthMult = 10LineLength = atr(100) * LineLengthMultdrawVerticalLine(offset) =>line.new(bar_index[offset], low-LineLength, bar_index[offset], high+LineLength, color=color.new(color.yellow, 50), width=3)如果 bar_index % 21 == 0drawVerticalLine(0)

使用自动缩放垂直线的代码更新了答案.

I'm trying to use the web based TradingView platform to make my own custom scripts to display various financial market properties. This is possible through its pine scripting engine/interpreter.

At the moment I'm trying to simply display a vertical line on either the main chart or on an indicator chart. However, it doesn't seem that their scripting engine is supporting vertical lines, except by using the plot's histogram or column types. Either way, I am not able to get any satisfactory lines.


SOME TESTS

(1) I've had some minor success with using bgcolor() like this:

//@version=3
study(title="vbar1", overlay = false)
trange(res, sess) => not na(time(res, sess))
vlinecol = #000000 // black
plot(n, color = na) // check last value from plot but don't display
vline =  (n < 5710) ? na : trange("1", "0700-0701") ? vlinecol : na
bgcolor(vline, transp=0)

This results in:

(2) A much better result when using plot() with the style=histogram argument:

//@version=3
study(title="vbar2", overlay = true) // scale=scale.none only for overlay=true
vlinecol = #000000 // black
cond = barstate.islast
bh = 10*high   // Use 10 x the window max price height for top of vbar (or use 1e20)
bo = -10       // Set offset from last bar
plot(cond ? bh : na, color=vlinecol, linewidth=2, offset=bo, style = histogram, transp=0)

with the following result:

解决方案

If anyone is interested in using the new v4 line.new() function:

Note: Adjust LineLengthMult as desired.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © marketscripters

//@version=4
study("My Script", overlay=true)
LineLengthMult = 10
LineLength = atr(100) * LineLengthMult

drawVerticalLine(offset) =>
    line.new(bar_index[offset], low-LineLength, bar_index[offset], high+LineLength, color=color.new(color.yellow, 50), width=3)

if bar_index % 21 == 0
    drawVerticalLine(0)

EDIT: Answer updated with code that auto-scales the vertical lines.

这篇关于如何在 TradingView pine 脚本中绘制一条垂直线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆