如何根据特定收盘蜡烛图和时间范围绘制水平线 [英] How to plot a horizontal line based off a specific closing candle and timeframe

查看:58
本文介绍了如何根据特定收盘蜡烛图和时间范围绘制水平线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望根据特定时间和特定时间范围在交易视图(松树脚本)中绘制一条水平线.因此,例如,我想在 1600(美国东部标准时间下午 4 点)时间范围内在 500 万根蜡烛线收盘时绘制一条高线.

I am looking to plot a horizontal line in tradingview (pine script) based on a specific time and on a specific time frame. So for example I want to plot a hline on the close of the 5m candle at the 1600 (4pm EST) timeframe.

我尝试了很多,但似乎无法弄清楚如何在松树脚本中获得历史价值.这意味着您希望从下午 4 点开始绘制一条线,并将其显示在当天剩余时间和第二天开始的图表上.使用 PS 中的函数 show_last = 1 很容易做到这一点.但我不知道如何计算下午 4 点的 5m 收盘蜡烛?

Ive tried a lot but cant seem to figure out how to a historic value within pine script. Meaning you are looking to plot a line from 4pm and have it show on your charts for the rest of that day and the beginning of the next day. It simple to do this with the function show_last = 1 within PS. but I cant figure out how to calculate the 5m closing candle at 4pm?

我的一些代码不能完全工作

Some of my code that doesnt work fully

//@version=3
study("4pm_Line")

highTimeFrame = input("5", type = resolution)
sessSpec = input("1600-0930", type = session)

is_newbar(res, sess) =>
    t = time(res, sess)
    na(t[1]) and not na(t) or t[1] < t

newbar = is_newbar("5", sessSpec)
s2 = na
s2 := newbar ? close : nz(s2[1])

plot(s2, style=line, linewidth=1, color=lime, trackprice = true, 
     show_last = 1)

绘制的线已关闭,我不知道它是如何获得其值的.

The line that plots is off and i have no idea how its getting its values.

推荐答案

其实很简单.我为你创建了一个脚本

its pretty easy actually. I created a script for you

//@version=4
//@author=lucemanb
study("Closing Time", overlay=true)

period  = input("5", "Period", input.resolution)
session = input("1500-1600", "Session", input.session)

float data = na
data := data[1]
getData() =>
    float d = na
    inSession = time(period, session)
    if not inSession and inSession[1]
        d := close[1]
    d
d = security(syminfo.tickerid, period, getData())
if not na(d)
    data := d

plot(data, "Line", color.yellow, 2, plot.style_line, true, show_last=1)

我们基本上将找到的值存储在我们在每根蜡烛上访问的变量中我希望这有帮助.享受

We basically store the value we found in a variable that we access on each candle I hope this helps. Enjoy

这篇关于如何根据特定收盘蜡烛图和时间范围绘制水平线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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