在未来价格中添加 new.line?
Adding new.line in future price?
我花了一整天的时间想弄明白这个问题。所以我来了。
1.
我想制作一个脚本来绘制这样的线条和文本:
https://gyazo.com/250560130c661044d2c37106b9a367fe
我弄清楚了历史价格的线,但对于未来,我开始认为线是不可能的?我已经尝试了很多。
2.
line.new 中是否可以直接在竖线上放置文字?或者做一个label.new然后旋转90度?
3.
我怎样才能让文本与条形图处于同一水平 above/below?现在我使用 low[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)
非常感谢您的宝贵时间,我真的很亲切。
这应该可以让您上路。如果您对代码有疑问,请提出。
我们正在做的是保留 2 组线条和绘图:一组用于检测每日状况的柱,另一组用于未来,提前一周。
文本不能在Pine中旋转,所以我们需要每行打印一个字母。文本打印在该行后一格,但是当您缩放 in/out 时,它的位置将相对于该行发生变化。对此无能为力。
//@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)
我花了一整天的时间想弄明白这个问题。所以我来了。
1. 我想制作一个脚本来绘制这样的线条和文本: https://gyazo.com/250560130c661044d2c37106b9a367fe
我弄清楚了历史价格的线,但对于未来,我开始认为线是不可能的?我已经尝试了很多。
2. line.new 中是否可以直接在竖线上放置文字?或者做一个label.new然后旋转90度?
3. 我怎样才能让文本与条形图处于同一水平 above/below?现在我使用 low[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)
非常感谢您的宝贵时间,我真的很亲切。
这应该可以让您上路。如果您对代码有疑问,请提出。
我们正在做的是保留 2 组线条和绘图:一组用于检测每日状况的柱,另一组用于未来,提前一周。
文本不能在Pine中旋转,所以我们需要每行打印一个字母。文本打印在该行后一格,但是当您缩放 in/out 时,它的位置将相对于该行发生变化。对此无能为力。
//@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)