admin管理员组文章数量:1123791
I am trying to create a pine script that draws a horizontal ray for the current monthly high and adds the text "CMH" on the right side of the screen (at the end of the extended line) (see screenshot). CMH
For the life of me, I can't seem to find a simple way to do this as an argument of the line.new() function. And the label.new() function doesn't seem to give me the same result.
Any help is appreciated!
//@version=5
indicator(title="Current Month High", overlay=true)
// Initialize variable to hold the current month's high
var float currentMonthHigh = na
var int currentMonthBarIndex = na
// Update the current month's high and bar index
if (month(time) != month(time[1]))
// If it's a new month, reset the high and store the current bar index
currentMonthHigh := high
currentMonthBarIndex := bar_index
else
// If still in the same month, update the maximum high and bar index
currentMonthHigh := math.max(currentMonthHigh, high)
currentMonthBarIndex := bar_index
// Draw the high line only when we are at the last bar of the month
if (month(time) != month(time[1]) and bar_index == last_bar_index)
// Use the current month's high directly for the line's starting point
line.new(currentMonthBarIndex, currentMonthHigh, currentMonthBarIndex + 1, currentMonthHigh, color=color.aqua, width=1, extend=extend.right)
I am trying to create a pine script that draws a horizontal ray for the current monthly high and adds the text "CMH" on the right side of the screen (at the end of the extended line) (see screenshot). CMH
For the life of me, I can't seem to find a simple way to do this as an argument of the line.new() function. And the label.new() function doesn't seem to give me the same result.
Any help is appreciated!
//@version=5
indicator(title="Current Month High", overlay=true)
// Initialize variable to hold the current month's high
var float currentMonthHigh = na
var int currentMonthBarIndex = na
// Update the current month's high and bar index
if (month(time) != month(time[1]))
// If it's a new month, reset the high and store the current bar index
currentMonthHigh := high
currentMonthBarIndex := bar_index
else
// If still in the same month, update the maximum high and bar index
currentMonthHigh := math.max(currentMonthHigh, high)
currentMonthBarIndex := bar_index
// Draw the high line only when we are at the last bar of the month
if (month(time) != month(time[1]) and bar_index == last_bar_index)
// Use the current month's high directly for the line's starting point
line.new(currentMonthBarIndex, currentMonthHigh, currentMonthBarIndex + 1, currentMonthHigh, color=color.aqua, width=1, extend=extend.right)
Share
Improve this question
asked yesterday
Alex MunteanuAlex Munteanu
1
New contributor
Alex Munteanu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
- Your code has "hallucinations". AI-generated code is inconsistent, buggy, and unreliable. Artificial Intelligence is very useful in many aspects, but it encodes Pinescript very poorly (for now...). – Gu5tavo71 Commented 16 hours ago
1 Answer
Reset to default 0the last if is not necessary
try this:
//@version=5
indicator(title="Current Month High", overlay=true)
// Initialize variable to hold the current month's high
var float currentMonthHigh = na
var int currentMonthBarIndex = na
var line lineMonthHigh = line.new(na, na, na, na)
// Update the current month's high and bar index
if (month(time) != month(time[1]))
// If it's a new month, reset the high and store the current bar index
currentMonthHigh := high
currentMonthBarIndex := bar_index
line.delete(lineMonthHigh)
lineMonthHigh := line.new(currentMonthBarIndex, currentMonthHigh, bar_index, currentMonthHigh, extend = extend.right)
else
// If still in the same month, update the maximum high and bar index
currentMonthHigh := math.max(currentMonthHigh, high)
line.set_xy1(lineMonthHigh, currentMonthBarIndex, currentMonthHigh)
line.set_xy2(lineMonthHigh, bar_index, currentMonthHigh)
本文标签: tradingview apiPine Script to create horizontal rays with textStack Overflow
版权声明:本文标题:tradingview api - Pine Script to create horizontal rays with text - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736596124a1945151.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论