Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to create a plot for the line color of an indicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to create a plot for the line color of an indicator

    I've been using the Trend Magic indicator available on Ninja Trader lately. However, There is no plot for when the lines switch colors (green for long, red for short.) Im not good at all the coding stuff yet so I was wondering.. Would it be possible to add a plot into the code for when the lines change color?

    #2
    Hello tannermcelvany34,

    Thanks for your post.

    NinjaTrader does not come with an indicator called 'Trend Magic' by default. So I may accurately assist, are you referring to the 'Trend Magic' indicator from the Ecosystem User App Share page linked below?

    The Trend Magic indicator is an ATR-based trend line that uses CCI to control its upward and downward movement. It was once a popular indicator in the Forex trading world. When the CCI is greater than zero the line is only able to move upwards, and conversely, when the CCI is less than or equal […]


    If so, AddPlot() can be used in OnStateChange() when the State == State.SetDefaults to add a plot to the indicator script.

    A value could be assigned to that plot depending on if the current plot in the script named TrendMagic uses the BullBrush or BearBrush by creating an 'if else if' condition that checks if PlotBrushes[0][0] is equal to the BullBrush or BearBrush. An example of printing to the NinjaScript Output window when PlotBrushes equals BullBrush or BearBrush could be seen below.

    Code:
    if (PlotBrushes[0][0] == BullBrush)
        Print("BullBrush used");
    else if (PlotBrushes[0][0] == BearBrush)
        Print("BearBrush used");​


    Instead of using a Print statement, you would assign a value to your plot.

    See this help guide page for information about using the AddPlot() method and assigning a value to the plot: https://ninjatrader.com/support/help...t8/addplot.htm

    This help guide page contains information about PlotBrushes for you to view: https://ninjatrader.com/support/help...lotbrushes.htm

    I am also linking you to the Educational Resources section of the Help Guide to help you get started with NinjaScript:
    https://ninjatrader.com/support/help..._resources.htm

    If you are new to C#, to get a basic foundation for the concepts and syntax used in NinjaScript I would recommend this section of articles in our help guide first:
    https://ninjatrader.com/support/help...g_concepts.htm

    Please let me know if I may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    595 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    554 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X