0

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.

enter image description here 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

1 Answer 1

1

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 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. In the first line of code you wrote, how can we indicate the high of that time in the past? high[not bar index?]
The line.new() example was to illustrate setting the parameters for using time instead of bar_index. It really depends on what the condition is for recording it. But usually you would use var declared variables (eg var int myX1 = na, var float myY1 = na), and assign a value when that condition occurred (eg myX1 := time, myY1 := high). For example all time high, you could use an if statement like if high > myY1 and assign the values.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.