要在将来的价格中添加新行吗?

问题描述 投票:0回答:1

[我花了一整天的时间试图弄清楚。.所以我在这里。

1。我想制作一个脚本来绘制线条和文字,如下所示:https://gyazo.com/250560130c661044d2c37106b9a367fe

我已经弄清了历史价格的线,但是对于将来,我开始认为用线不可能吗?我已经尝试了很多。

2。是否可以直接在line.new中将文本放在垂直线上?还是制作一个标签。新建并将其旋转90度?

3。我怎样才能使文本在条的上方/下方处于同一水平?现在我用低[30]

//@version=4
study("TEST nr 032",overlay=true)
fromHour = 00
t1 = timestamp("GMT-4", year, month, dayofmonth, fromHour, 00, 00)
t2 = t1
timeIsOk = (time >= t1) and (time <= t2)

if timeIsOk and dayofweek == dayofweek.monday
    line.new(bar_index, low * .9999, bar_index, high * 1.0001, xloc.bar_index, extend.both, color.blue, line.style_solid, 1)
    var label1 = label.new(bar_index, low[30], text="Monday", style=label.style_none)
    label.set_x(label1, 0)
    label.set_xloc(label1, time, xloc.bar_time)

if timeIsOk and dayofweek == dayofweek.tuesday
    line.new(bar_index, low * .9999, bar_index, high * 1.0001, xloc.bar_index, extend.both, color.blue, line.style_solid, 1)
    var label2 = label.new(bar_index, low[30], text="Tuesday", style=label.style_none)
    label.set_x(label2, 0)
    label.set_xloc(label2, time, xloc.bar_time)

if timeIsOk and dayofweek == dayofweek.wednesday
    line.new(bar_index, low * .9999, bar_index, high * 1.0001, xloc.bar_index, extend.both, color.blue, line.style_solid, 1)
    var label3 = label.new(bar_index, low[30], text="Wednesday", style=label.style_none)
    label.set_x(label3, 0)
    label.set_xloc(label3, time, xloc.bar_time)

if timeIsOk and dayofweek == dayofweek.thursday
    line.new(bar_index, low * .9999, bar_index, high * 1.0001, xloc.bar_index, extend.both, color.blue, line.style_solid, 1)
    var label4 = label.new(bar_index, low[30], text="Tursday", style=label.style_none)
    label.set_x(label4, 0)
    label.set_xloc(label4, time, xloc.bar_time)

if timeIsOk and dayofweek == dayofweek.friday
    line.new(bar_index, low * .9999, bar_index, high * 1.0001, xloc.bar_index, extend.both, color.blue, line.style_solid, 1)
    var label5 = label.new(bar_index, low[30], text="Friday", style=label.style_none)
    label.set_x(label5, 0)
    label.set_xloc(label5, time, xloc.bar_time)


fromHour2 = 18
t3 = timestamp("GMT-4", year, month, dayofmonth, fromHour2, 00, 00)
t4 = t3
timeIsOk2 = (time >= t3) and (time <= t4)

if timeIsOk2 and dayofweek == dayofweek.sunday
    line.new(bar_index, low * .9999, bar_index, high * 1.0001, xloc.bar_index, extend.both, color.red, line.style_solid, 1)
    var label7 = label.new(bar_index, low[30], text="Sunday", style=label.style_none)
    label.set_x(label7, 0)
    label.set_xloc(label7, time, xloc.bar_time)

非常感谢您的宝贵时间,我真的很满意。

pine-script
1个回答
0
投票

这应该可以帮助您。如果您对代码有疑问,请询问。

[我们正在做的是保留两组线条和图形:一组用于检测日常状况的酒吧,另一组用于未来一周的将来。

文本无法在Pine中旋转,因此我们需要每行打印一个字母。文本在行上方打印一格,但放大/缩小时,其位置将相对于行变化。对此无能为力。

//@version=4
study("TEST nr 032",overlay=true)
fromHour = 00
t1 = timestamp("GMT-4", year, month, dayofmonth, fromHour, 00, 00)
t2 = t1
timeIsOk = (time >= t1) and (time <= t2)

// ————— Calculates the chart's normal time between bars.
f_chartTimeInterval() =>
    var _timeDelta = 10e15
    // Maintain the smallest interbar time value in the dataset, which should correspond to the chart's interval.
    _timeDelta := min(time - nz(time[1]), _timeDelta)

// ————— Calculates a time offset (+/-) which is a multiple of the chart's interval for use with drawing functions.
f_timeAtIntervalMultiple(_mult) =>
    // _mult ("series int"): +/- number of time intervals in the future/past to be calculated.
    int(time + f_chartTimeInterval() * _mult)

// ————— Calculates a +/- time offset from the current bar's time.
f_timeFromBar(_qty, _units) =>
    // _qty   : the +/- number of units of offset required. A "series float" can be used but it will cast to a "series int".
    // _units : string containing one of the 6 allowed time units (the `f_chartTimeUnits()` can be used to supply the current chart's resolution).
    _year   = year        + (_units == "years"   ? int(_qty) : 0)
    _month  = month       + (_units == "months"  ? int(_qty) : 0)
    _day    = dayofmonth  + (_units == "days"    ? int(_qty) : 0)
    _hour   = hour        + (_units == "hours"   ? int(_qty) : 0)
    _minute = minute      + (_units == "minutes" ? int(_qty) : 0)
    _second = second      + (_units == "seconds" ? int(_qty) : 0)
    timestamp(_year, _month, _day, _hour, _minute, _second)

// ————— Draws a text label.
f_drawText(_label, _x, _y, _t, _c) =>
    if na(_label)
        label.new(_x, _y, text = _t, xloc = xloc.bar_time, textcolor = _c, style = label.style_none)
    else
        label.set_xy(_label, _x, _y)
        _label

// ————— Draws a line.
f_drawLine(_line, _x, _c) =>
    if na(_line)
        line.new(_x, low * .9999, _x, high * 1.0001, xloc.bar_time, extend.both, _c, line.style_solid, 1)
    else
        line.set_xy1(_line, _x, low * .9999)
        line.set_xy2(_line, _x, high * 1.0001)
        _line

// ————— Processes one day of lines and labels.
f_doOneDay(_y, _day, _txtColor, _lineColor) =>
    timeInOneWeek = f_timeFromBar(7, "days")
    var line _lineCurrent = f_drawLine(line(na), time, _lineColor)
    var line _lineFuture  = f_drawLine(line(na), time, _lineColor)
    _lineCurrent := f_drawLine(_lineCurrent, time, _lineColor)
    _lineFuture  := f_drawLine(_lineFuture, timeInOneWeek, _lineColor)
    var label _labelCurrent = f_drawText(label(na), time, _y, _day, _txtColor)
    var label _labelFuture  = f_drawText(label(na), time, _y, _day, _txtColor)
    _labelCurrent := f_drawText(_labelCurrent, int(time + f_chartTimeInterval()), _y, _day, _txtColor)
    _labelFuture  := f_drawText(_labelFuture, int(timeInOneWeek + f_chartTimeInterval()), _y, _day, _txtColor)

y         = highest(close, 500)[1]
textColor = color.gray
lineColor = color.blue
txtMon    = "M\no\nn\nd\na\ny"
txtTue    = "T\nu\ne\ns\nd\na\ny"
txtWed    = "W\ne\nd\nn\ne\ns\nd\na\ny"
txtThu    = "T\nh\nu\nr\ns\nd\na\ny"
txtFri    = "F\nr\ni\nd\na\ny"
txtSun    = "S\nu\nn\nd\na\ny"

if timeIsOk and dayofweek == dayofweek.monday
    f_doOneDay(y, txtMon, textColor, lineColor)
else if timeIsOk and dayofweek == dayofweek.tuesday
    f_doOneDay(y, txtTue, textColor, lineColor)
else if timeIsOk and dayofweek == dayofweek.wednesday
    f_doOneDay(y, txtWed, textColor, lineColor)
else if timeIsOk and dayofweek == dayofweek.thursday
    f_doOneDay(y, txtThu, textColor, lineColor)
else if timeIsOk and dayofweek == dayofweek.friday
    f_doOneDay(y, txtFri, textColor, lineColor)

fromHour2 = 18
t3 = timestamp("GMT-4", year, month, dayofmonth, fromHour2, 00, 00)
t4 = t3
timeIsOk2 = (time >= t3) and (time <= t4)

if timeIsOk2 and dayofweek == dayofweek.sunday
    f_doOneDay(y, txtSun, color.red, color.red)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.