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 revisionsNative editor check

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.

An early line that updates with every new extreme is more responsive but changes history. Name that behavior rather than hiding it.

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.

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 thinkorswim 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. thinkorswim remains the platform authority for parsing and chart behavior.