Reputation: 15
When we draw lines in TradingView we can set on daily time frames and after finishing drawings we can go to lower time to reach more precision. What I need to do is drawing on higher time frame and keep them in lower time frame by coding. There are 2 problem:
1- when I set max_bars_back=5000 in my study and max_bars_back(time, 4000) in my code the code gives error in lower time frame. 2- I have to swipe right a lot to go back in time and wait for TradingView to draw what it's supposed to.
For instance, Imagine these to lines mentioned in the attached picture and we wish to see the lines at the last candle (present time) in lower time frame like 5-minute.
Any solution in Pine script please
Upvotes: 0
Views: 1282
Reputation: 3833
Using time
instead of bar_index
is one way to set the origin of a line beyond the 5000 bar limit. eg
line.new(x1 = time[1], y1 = high, x2 = time, y2 = high, xloc = xloc.bar_time)
However, TV charts load in chunks. If your line's origin is located on an historical chunk that hasn't been loaded yet, the line won't be rendered. This is why your line doesn't appear until you scroll back far enough.
You can partially work around this by only drawing a segment of the line within the first chunk. Using normal variables to track your (x,y) coordinates, you can then calculate two sets coordinates closer to the realtime bar and use these new coordinates to draw your line. This formula will only work with non log charts though.
f_y_given_x(_x1, _y1, _x2, _y2, _new_x) =>
_m = (_y2 - _y1) / (_x2 - _x1)
_b = _y1 - _m * _x1
_new_y = _m * _new_x + _b
_new_y
Upvotes: 1