首页 > 解决方案 > pine escript tradingview 谁能帮帮我?

问题描述

我想看看谁能帮助我编写一个我无法让它按我想要的方式工作的代码。我不是程序员,但我一直在看教程,但我没有得到我想要的东西。我会附上一些图片,这样你就可以直观地知道我想要做什么。 我目前拥有的

现在我附上一张图片,我在其中指出我在寻找什么

我需要做的修改

现在解释第二张图片:正如您在图片1中看到的那样,背景颜色和高线或低线没有像第二张图片那样填充..我的想法是背景颜色是一个盒子的形式,而不是就像在图 1 中看到的那样,如果不是像图 2 中所示的那样 .. 就像高线和低线与背景颜色匹配一样,假设在我使用的时间范围是 07:00 到 17:00 我将离开我应该使用的配置代码希望有人能帮助我谢谢!

 //@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/


study("High & Low Of Custom Session", shorttitle="High/Low Of Custom Session",overlay=true)

// Inputs
my_session = input("0700-1700", type=input.session, title='Custom Session')
Lines = input(true, title="Show High/Low Lines?")
FILL = input(true, title="Show Session BGcolor?")

// Determine if we are in a session
in_session = time(timeframe.period, my_session)
is_new_session(res, sess) =>
    t = time(res, sess)
    na(t[1]) and not na(t) or t[1] < t

new_session = is_new_session("0600", my_session)

// Start of Session
is_newbar(res,sess) =>
    t = time(res,sess)
    not na(t) and (na(t[1]) or t > t[1])
new = (is_newbar("0600", my_session) ? 1 : 0)

// Plot Start Of Session
col_Start_of_Session = new_session and new==1? color.aqua:na

    

// In Session High/Low Calculations
var float _low = low
var float _high = high

_low := new_session? low : in_session ? min(low, _low[1]) : na
_high := new_session  ? high : in_session ? max(high, _high[1]) : na

col_low = _low == low? na: Lines?color.red:na
col_high = _high== high? na:Lines? color.green:na

// Plot High/Low Line
Low=plot(_low, style=plot.style_line, linewidth=1, color=col_low)
High=plot(_high, style=plot.style_line, linewidth=1, color=col_high)

// BG Color
Fill_col = FILL ? color.aqua:na
fill(Low,High, color=Fill_col)
//

// End of Session
start_of_session_value = valuewhen((new==1),high,0)
end_session_condition = start_of_session_value !=start_of_session_value[1]?0: in_session?1:0 
end_session = (end_session_condition == 0) and (end_session_condition[1]==1)? color.orange:na

标签: pine-script

解决方案


您所要求的无法在 Pine 中完成。
但是,您可以使用对象使线条从同一条开始line
一个简单的例子是这样的:

var l1 = line.new(na, na, na, na, color=color.yellow)
var l2 = line.new(na, na, na, na, color=color.yellow)

if barstate.islast
    line.set_xy1(l1, bar_index-10, 1880)
    line.set_xy2(l1, bar_index,    1880)

    line.set_xy1(l2, bar_index-10, 1890)
    line.set_xy2(l2, bar_index,    1890)

不幸的是,您不能使用line对象来创建fill().

您无法让行与 a 同时开始的原因plot()是,high/low事先不知道,而plot()过去则不能。您可以通过使用带有参数
的函数来解决对历史会话的限制。这将检索“未来”值。 但是对于今天的会话,您不能这样做,因为该会话的 直到会话结束时才知道。security()lookahead=barmerge.lookahead_on
high/low

因此,总而言之,您必须在以下选项中做出选择:

  1. 使用plot()并有fill()背景,但线条不会同时开始。
  2. 使用line对象并同时开始线条,但没有背景颜色fill()

编辑:要玩的代码
这将绘制您想要的内容,但是当出现新的高点/低点时,它不会在实时会话中画一条直线。尽管所有历史会话都将具有直线。

//@version=4
study("Lookahead", overlay=true)

var float   daily_high  = na
var float   daily_low   = na

newSession = change(time("D"))

[hi,lo] = security(syminfo.ticker, "D", [high,low], lookahead=barmerge.lookahead_on)

plot_color  = newSession ? na : color.green
fill_color  = newSession ? na : color.gray

plot_hi = plot(hi, "High", color=plot_color)
plot_lo = plot(lo, "Low",  color=plot_color)

fill(plot_lo, plot_hi, fill_color, 60)

产生这个输出

输出

编辑:代码可配置为仅在开始时间和结束时间之间绘制。

//@version=4
study("Lookahead", overlay=true)

var         session_info    = input("0700-1700", "Plot between these hours", input.session)

var float   daily_high      = na
var float   daily_low       = na


newSession  = change(time("D"))
inSession   = time(timeframe.period, session_info)

[hi,lo]     = security(syminfo.ticker, "D", [high,low], lookahead=barmerge.lookahead_on)

plot_color  = newSession ? na : color.green
fill_color  = newSession ? na : color.gray

plot_hi     = plot(inSession ? hi : na, "High", plot_color, style=plot.style_linebr)
plot_lo     = plot(inSession ? lo : na, "Low",  plot_color, style=plot.style_linebr)

fill(plot_lo, plot_hi, fill_color, 60)

推荐阅读