rule-based trendline study

Trendline Indicator for thinkorswim

An automatic trendline requires rules for selecting anchor points. Without pivot strength, confirmation, replacement, and extension rules, the line is subjective and cannot be reproduced reliably.

Source review completed

Prompt brief

ThinkScript · one source file

Review in thinkorswim

Example request

Create a thinkorswim upper study that connects the two most recent confirmed pivot highs using three bars on each side, extends the line, and alerts once when a completed bar closes above it.

Editable sourceFocused revisionsCheck in native editor

Direct answer

A thinkorswim trendline indicator can connect confirmed swing highs or lows and extend the resulting slope. Define how many bars on each side confirm a pivot, which two pivots remain active, when a new pivot replaces an old one, and what counts as a break. A delayed confirmed pivot is more stable than an unconfirmed line but appears later.

What to know first

  • Pivot confirmation introduces a known delay.
  • Using future bars to confirm a pivot must not be presented as a real-time signal on the pivot bar.
  • Line-break logic needs a close, high-low, or tolerance rule.

Reference points

Keep the calculation explicit

Pivot strength
The number of bars used on each side to confirm a local high or low.
Anchor selection
The rule choosing which confirmed pivots define the active line.
Extension
Projects the slope from the two anchors onto later bars.
Break
A stated comparison using close or intrabar extremes, with an optional tolerance.

Confirmation and repainting are linked

A swing high cannot be confirmed until the required right-side bars exist. Plotting a confirmed marker back on the swing bar is useful visually, but the information became available later. Alerts and strategy rules should use the confirmation time.

A line based on an unconfirmed extreme can change its anchors while new bars arrive. Whether earlier plotted segments are redrawn depends on the implementation; document both anchor updates and historical drawing behavior.

Test geometry and edge cases

Verify the slope between two known anchors, then inspect equal highs, equal lows, gaps, and a new pivot that arrives before the previous line breaks. Decide whether upper and lower lines may coexist.

Pineify can encode the anchor and replacement rules in one study. Chart review is required because a parser cannot judge whether the selected pivots match the intended structure.

Check slope and information timing

For hypothetical confirmed highs of 110 at bar 10 and 106 at bar 14, slope is (106 - 110) / (14 - 10) = -1 price unit per bar. The extended line at bar 18 is 102. This geometry uses bar index, not elapsed clock time.

With three right-side confirmation bars, the high at bar 14 cannot be confirmed before bar 17 finishes. The two-anchor line therefore cannot support a real-time signal before that confirmation. If completed close is 103 at bar 18, it is above the projected 102 line; a new-cross rule must also check the prior bar's relationship.

Pineify thinkScript workflow

Turn the specification into editable thinkScript

Give the Coding Agent the formula, inputs, plots, alerts, and edge cases. It returns one editable study or strategy file and keeps focused revisions in the same code artifact.

Open the thinkScript agent

Sources and scope

Last verified:

Pineify provides information and code-generation assistance, not investment advice. Generated scripts, strategy reports, simulations, and historical examples cannot predict prices or guarantee returns. Review every script and test it in its target platform before relying on its output.

Frequently asked questions

Can thinkorswim draw automatic trendlines?

A custom thinkScript study can plot rule-based lines from selected pivots. The result depends on how pivots, anchors, extension, and replacement are defined.

Why does an automatic trendline repaint?

The script may be using unconfirmed pivots or revising anchors when new extremes appear. Confirmed pivots reduce revision but add delay.

Can Pineify add a trendline-break alert?

Yes. Define the active line, whether close or high-low triggers the break, the tolerance, bar-confirmation rule, and repetition behavior.

Continue in the thinkScript coding workspace

Generate one editable thinkScript study or strategy, inspect the source, request focused changes, and complete the final check in thinkorswim.

Pineify generates source code. Review its syntax and chart behavior in thinkorswim before use.