Skip to content

Commit c8c1390

Browse files
committed
fix: retroactively redraw trendlines when slope changes
In PineScript, line.set_xy2() redraws the entire line from the anchor point. Our per-bar output was recording the initial flat phase (slope=0) and only applying the slope going forward. This left 63-83% of trendline bars with zero slope showing horizontal lines. Fix: when the slope is first set or updated, retroactively recompute tl_value and tl_slope for all bars from the anchor (tl_x1) forward, matching PineScript's visual behavior. Now 97-100% of trendline bars have correct diagonal values.
1 parent d2ded75 commit c8c1390

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

analysis/indicators/trendline_breakout_navigator.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pyindicators/indicators/trendline_breakout_navigator.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ def _compute_single_timeframe(
256256
tl_slope_set = True
257257
else:
258258
tl_cur_slope = slope
259+
260+
# Retroactively redraw trendline
261+
# from anchor (like PineScript
262+
# line.set_xy2)
263+
for b in range(tl_x1, bar + 1):
264+
tl_value[b] = (
265+
tl_y1 + tl_cur_slope
266+
* (b - tl_x1)
267+
)
268+
tl_slope[b] = tl_cur_slope
259269
else:
260270
# Close breaks trendline at swing
261271
tl_active = False
@@ -323,6 +333,16 @@ def _compute_single_timeframe(
323333
tl_slope_set = True
324334
else:
325335
tl_cur_slope = slope
336+
337+
# Retroactively redraw trendline
338+
# from anchor (like PineScript
339+
# line.set_xy2)
340+
for b in range(tl_x1, bar + 1):
341+
tl_value[b] = (
342+
tl_y1 + tl_cur_slope
343+
* (b - tl_x1)
344+
)
345+
tl_slope[b] = tl_cur_slope
326346
else:
327347
tl_active = False
328348

8.9 KB
Loading

0 commit comments

Comments
 (0)