A Complete Beginner’s Guide to Static Visual Markers.

After learning about Plots, which dynamically update on every bar, it’s time to explore a simpler but powerful tool in NinjaTrader: Lines.

Lines are static, horizontal markers that you can add to your indicators.
They don’t change bar-by-bar — they stay exactly where you place them, providing clear and consistent reference points on your chart.

In plain English:
Lines are like horizontal strips of tape you stick across your chart to highlight important levels — and they stay put unless you move them.

In this guide, you’ll learn:

  • How NinjaTrader organizes and manages Lines
  • Key settings that control how Lines appear and behave
  • How to add Lines properly in your indicator code
  • Common mistakes traders make when using Lines

Whether you’re building simple tools or highlighting oversold/overbought zones, understanding Lines will add an important visual layer to your NinjaScript skills.

👉 Save this official NinjaTrader Help Guide link:


If you’re new here, make sure you check out the earlier posts too:


📏 What Are Lines?

In NinjaTrader, Lines are simple, static horizontal markers that you can add to your indicators.

Unlike Plots, Lines do not update bar-by-bar. They are placed once — at a specific price level — and they stay there until you change them.

In plain English:
A Line is like a piece of colored tape stretched across your chart at a set price.

You might use Lines to highlight:

  • Support and resistance zones
  • Risk management thresholds (like a stop loss marker)
  • Key psychological levels (like 4000 on the S&P 500)
  • (Most common use) Overbought/oversold zones on oscillators (like RSI)

Important:
Lines do not track price.
They do not change automatically.
They are purely visual reference points.


🆚 Lines vs. Plots: What’s the Difference?

Feature Plot Line
Behavior Changes dynamically bar-by-bar Static and unchanging
Backed by Series? Yes (via Values[]) No (independent object)
Common Usage Moving averages, indicators, dynamic signals Static levels, zones, visual thresholds
Updated in OnBarUpdate()? Yes No (only manually if you want)

Key Takeaway:

  • Plot = Dynamic (data-driven, changing every bar)
  • Line = Static (set once, stays put)

🔥 Why Lines Matter

Even though they are simple, Lines are incredibly useful because they give your indicators extra visual power without introducing extra calculations.

✅ Common use cases:

  • Marking overbought/oversold areas on an oscillator
  • Drawing a fixed risk zone for a trading strategy
  • Showing a static moving average threshold (e.g., plot 50 SMA once for context)
  • Creating visual separation zones (like between two trading bands)

Think of Lines as the “rulers” or “boundary markers” of your trading indicators.


🎛️ Important Line Settings Explained

When working with Lines in NinjaTrader, there’s really only one major setting that matters for how users interact with them:

🛠️ AreLinesConfigurable

What It Controls:

  • Whether the Lines you add can be edited by a user through the indicator settings window.

Why It Matters:

  • If AreLinesConfigurable = true, users can manually adjust Line values like color, width, and price inside the UI without editing code.
  • If false, the Line remains locked based on how you coded it — no UI changes allowed.

Example:

protected override void OnStateChange()
{
    if (State == State.SetDefaults)
    {
        Name = "MyStaticLineExample";
        AreLinesConfigurable = true;  // Allow users to manually adjust line properties
    }
}

Plain English:
Can someone change the appearance or price of this Line without touching the code?

Best Practice Tip:
If your Lines are meant to be flexible for different charts or preferences, set AreLinesConfigurable = true.

📚 Deep Dive: Understanding the Line Class

Every Line you add inside NinjaTrader isn’t just a simple number at a price level — it’s a full object with several properties you can control.

Plain English:
A Line is more than just a fixed price — it has a color, style, thickness, and name you can set and change.

Each Line you create through AddLine() lives inside the Lines[] collection and gives you access to:

Property What It Does Why It Matters
Value Sets the price level of the Line Controls where the Line is drawn
Brush Sets the color of the Line Helps visually distinguish different lines
DashStyleHelper Sets the line style (solid, dashed, dotted, etc.) Provides visual meaning (e.g., dashed for zones)
Width Sets how thick the Line is in pixels Thicker lines stand out more
Name Internal label for the Line Helpful when using the Data Box or debugging

🛠️ Properties of the Line Class Explained

🏷️ Value

  • What it is:
    The price level where the line appears.
  • Why it matters:
    If you change .Value, the line moves to a new price.

✅ Example:

Lines[0].Value = 80; // Overbought level in an oscillator
Lines[1].Value = 20; // Oversold level in an oscillator

🎨 Brush

  • What it is:
    The color (and optionally fill type) of the line.
  • Why it matters:
    Different colors help you easily identify what the line represents.

✅ Example:

Lines[0].Brush = Brushes.Red;    // Overbought (Red)
Lines[1].Brush = Brushes.Green;  // Oversold (Green)

✅ Tip:
You can dynamically change the Brush if you want to highlight special conditions, like extreme volatility.


🖋️ DashStyleHelper

  • What it is:
    The pattern style of the line (solid, dashed, dotted, etc.).
  • Why it matters:
    Different styles can signal different meanings (solid = firm level, dashed = flexible zone).

✅ Example:

Lines[0].DashStyleHelper = DashStyleHelper.Dash; // Make it dashed

✅ Common Styles:

  • DashStyleHelper.Solid
  • DashStyleHelper.Dash
  • DashStyleHelper.Dot
  • DashStyleHelper.DashDot
  • DashStyleHelper.DashDotDot

🧵 Width

  • What it is:
    The thickness of the line (in units).
  • Why it matters:
    Important levels stand out more with thicker lines.

✅ Example:

Lines[0].Width = 2; // 2 units thick

✅ Tip:
Use thicker lines for more important thresholds, thinner lines for minor zones.


🏷️ Name

  • What it is:
    A label that shows up in the NinjaTrader Data Box.
  • Why it matters:
    Helps you and your users identify lines easily during debugging or analysis.

✅ Example:

Print(Lines[0].Name); // Prints "OverboughtLine" if that was the label you set

✅ Important:
You set the Name when you call AddLine().


🧪 Example: Setting Lines for a Custom Oscillator

Here’s an example of adding two static Lines for Overbought and Oversold thresholds:

protected override void OnStateChange()
{
    if (State == State.SetDefaults)
    {
        Name = "MyOscillatorWithZones";

        // Add Overbought Line at 80
        AddLine(new Stroke(Brushes.Red, DashStyleHelper.Dash, 2), 80, "OverboughtLine");

        // Add Oversold Line at 20
        AddLine(new Stroke(Brushes.Green, DashStyleHelper.Dash, 2), 20, "OversoldLine");
    }
}

✅ Here’s what this does:

  • Adds two dashed Lines, one at 80 and one at 20.
  • Red for overbought, green for oversold.
  • Each line is 2 units thick.

🔥 Bonus Example: Dynamically Adjusting Lines During Trading

Sometimes, you might want to move a Line or change its color based on certain conditions — like rising volatility.

✅ Example:

protected override void OnBarUpdate()
{
    if (CurrentBar < 20)
        return;

    // Dynamically move lines based on ATR (volatility)
    double atr = ATR(14)[0];

    if (atr > 10)
    {
        // Market very volatile: widen the bands
        Lines[0].Value = 85; // Push Overbought higher
        Lines[1].Value = 15; // Push Oversold lower

        // Change colors to alert user
        Lines[0].Brush = Brushes.Orange;
        Lines[1].Brush = Brushes.Orange;
    }
    else
    {
        // Normal conditions
        Lines[0].Value = 80;
        Lines[1].Value = 20;

        Lines[0].Brush = Brushes.Red;
        Lines[1].Brush = Brushes.Green;
    }
}

✅ This dynamic behavior:

  • Moves Lines dynamically based on ATR volatility.
  • Adjusts Line colors to alert the trader.

🎯 Key Takeaways About the Line Class

✅ Lines aren’t just simple static lines — they are full objects with properties you can configure:

  • .Value to move it
  • .Brush to color it
  • .DashStyleHelper to style it
  • .Width to adjust thickness
  • .Name for internal organization

✅ You can adjust Lines manually when needed — but remember:

  • Best Practice: Use Lines mainly for fixed, static reference points inside custom oscillators.
  • If you need constantly moving visual elements: Prefer Plots or Draw.Line() instead.

🛠️ How to Add Lines with AddLine()

Now that you understand what Lines are and what properties you can control, let’s talk about how to properly add Lines to your NinjaScript indicator.

Plain English:
AddLine() creates a static horizontal line at a price level that you can later style or adjust.


✍️ AddLine() Syntax Explained

There are two ways you can call AddLine() depending on how much control you want over the Line’s appearance.

Syntax Type What It Looks Like When to Use
Basic AddLine(Brush, double value, string name); Simple color and level only
Advanced (with Stroke) AddLine(Stroke, double value, string name); Full control over color, dash style, and width

📚 Breakdown of Each Parameter

Parameter Meaning Example
Brush Color of the Line Brushes.Red
Stroke Color + dash style + thickness new Stroke(Brushes.Blue, DashStyleHelper.Dash, 2)
Value The price level to draw the Line 80
Name Label for internal reference "OverboughtLine"

✅ Tip:

  • Use Brush for simple solid lines.
  • Use Stroke if you want dashed lines, thicker widths, etc.

🧪 Example: Add Simple Static Lines

Here’s how to add a basic solid line for an oscillator:

protected override void OnStateChange()
{
    if (State == State.SetDefaults)
    {
        Name = "SimpleOscillatorWithLines";

        AddLine(Brushes.Red, 80, "Overbought");
        AddLine(Brushes.Green, 20, "Oversold");
    }
}

What this does:

  • Creates Lines[0] at price 80 (Red).
  • Creates Lines[1] at price 20 (Green).
  • Both will show up on the chart as static, solid-colored lines.

🧪 Example: Add Styled Lines with Stroke

If you want dashed lines that are thicker or more stylized, use the advanced form:

protected override void OnStateChange()
{
    if (State == State.SetDefaults)
    {
        Name = "FancyOscillatorWithDashedLines";

        AddLine(new Stroke(Brushes.Red, DashStyleHelper.Dash, 2), 80, "OverboughtDashed");
        AddLine(new Stroke(Brushes.Green, DashStyleHelper.Dash, 2), 20, "OversoldDashed");
    }
}

Here’s what changes:

  • Lines are now dashed instead of solid.
  • Width is 2 units instead of default thin.
  • Adds better visual distinction for zones.

⚠️ Important: When to Call AddLine()

Always add your Lines during this state:

if (State == State.SetDefaults)

Why?

  • This ensures that NinjaTrader initializes them correctly for the chart and Indicator settings window.
  • NinjaTrader expects static display elements (like Lines) to be added during setup.

Bonus Tip: Even though you add them once in SetDefaults, you can modify their Value or appearance later during OnBarUpdate() if needed.


🎯 Quick Takeaways for Adding Lines

✅ Use simple Brush syntax for clean, solid lines.

✅ Use Stroke syntax when you want full style control (color, width, dash type).

✅ Always add Lines in State.SetDefaults.

✅ Best use case: Setting fixed zones like Overbought/Oversold or Risk Limits.

✅ Lines are static reference tools — don’t abuse them for dynamic visualizations (use Plots or Draw methods for that instead).

🚫 Common Beginner Mistakes with Lines

Even though Lines are simple compared to Plots, beginners often run into the same few mistakes when adding or using them.

Here’s what you need to watch out for:

❌ Trying to Use Lines Dynamically Like Plots

Lines are designed for static zones — not dynamic, constantly changing levels!

While you technically can modify a Line’s .Value dynamically inside OnBarUpdate(), this is NOT best practice for anything highly dynamic (like moving averages or trailing stops).

✅ Use Lines for:

  • Overbought/oversold levels.
  • Fixed threshold levels.

✅ If you need something dynamic:

  • Use Draw.Line(), Draw.HorizontalLine(), or a custom Series<double> + Plot instead.

❌ Not Exposing Line Settings Correctly

If you want users to edit your Lines in the Indicator Settings window (such as changing Overbought/Oversold levels without touching code), you need to make sure:

AreLinesConfigurable = true;

✅ You’ve added the Lines properly during State.SetDefaults.

Otherwise, your Lines will be “locked” and users won’t be able to adjust them easily.


❌ Misunderstanding Lines[]

Remember:

  • Lines[0] = your first Line
  • Lines[1] = your second Line
  • and so on.

✅ Always reference the correct index if you plan to update or style a Line dynamically.

Example Pitfall:
Setting Lines[1].Value thinking it’s your Overbought line, when really it’s your Oversold — causing confusing chart behavior!


❌ Forgetting to Style Lines Properly

If you don’t style Lines carefully:

  • They can look too thin to see.
  • Or all Lines look the same and clutter the chart.

✅ Set:

  • Different colors (Brushes).
  • Different dash styles (Dashed for zones, solid for hard stops).
  • Wider widths (2–3 width) for important lines.

✅ Good example:

AddLine(new Stroke(Brushes.Red, DashStyleHelper.Dash, 2), 80, "Overbought");
AddLine(new Stroke(Brushes.Green, DashStyleHelper.Solid, 3), 20, "Oversold");

🧠 Final Thoughts

Lines are one of the simplest but a very effective tool you can add to your NinjaScript indicators.

✅ They are static visual markers — best used for highlighting important, unchanging levels like:

  • Overbought and oversold zones
  • Key support and resistance levels
  • Risk thresholds or psychological price levels

✅ Unlike Plots, they don’t update bar-by-bar — they stay put until you manually modify them.

Behind the scenes, NinjaTrader manages your Lines neatly inside the Lines[] collection, making it easy to reference or update them by index.

Best practices include:

  • Waiting for enough bars before referencing dynamic data.
  • Using Lines for fixed levels (not rapidly updating levels).
  • Carefully styling your Lines (color, dash style, width) to make your charts clear and readable.

🎉 Prop Trading Discounts

💥91% off at Bulenox.com with the code MDT91

Categorized in:

Learn NinjaScript,

Tagged in: