'How to mine the "1min" Intrabar Close
This question refers to Pine Script V5
Part 1: I'm trying to draw a horizontal line at each close of the 1 minute intra bar within a larger resolution. So if I'm on a 15 minute chart, there will be 15 horizontal lines plotted for every 15 minute bar. (The number of lines actually being drawn will be greatly reduced later based on condition, however it's important to be able to draw all 15 for now to make sure the function is working)
I realize there is no way to look for the close of an intra bar within the current resolution so we will need to mine the relative close based on time elapsed = 1 minute.
Part 2: Once these lines are drawn, I want to set x2 to the current bar indefinitely until price crosses their path. However, given there are so many lines being drawn, it's impossible to name each line individually. So it needs to be a blanket command that applies to all instances of lines drawn.
I found that I can set x2 of a line correctly if it is the very last instance of a line being drawn. The command to stop extending that line based on a cross of current price works. But all the other instances that price crosses a line from much further back, are hit or miss. Some work, some don't
// Binary switch to trigger new Intra Bar Line
float intra_trigger = na
intra_trigger:= ta.change(time("1min")) ? 1 : 0
//Draw line when triggered and reset x2 to last bar
var line intra_line = na
if intra_trigger == 1 //(and condition to be added later)
intra_line := line.new(bar_index + 1, last_bar_index, bar_index + 2, last_bar_index)
line.set_x2(intra_line, last_bar_index)
// Stop extending line if price crosses line
if ta.cross(close, line.get_y2(intra_line) )
line.set_x2(intra_line, bar_index[1])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
