Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamically Coloring an indicator accoding to the value of a secondary parameter

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

    Dynamically Coloring an indicator accoding to the value of a secondary parameter

    Very simply, I'd like to have the color of an indicator curve change as it's being plotted according to the value of a secondary parameter.

    For example, suppose I plot the SMA of Close, SMA(Close,10) and I also calculate the momentum of this SMA, Momentum(SMA(Close,10), 5). I want to plot the portions of the SMA curve green where the momentum is above a "long threshold" value, and plot the curve red when it is below a "short threshold" value and plot it white if the momentum falls between the two threshold values:

    Schematically:

    if ( Momentum(SMA(Close,10), 5)[0] > LongThreshold)

    plot SMA(Close,10) green;

    else if ( Momentum(SMA(Close,10), 5)[0] < ShortThreshold)

    plot SMA(Close,10) red;

    else

    plot SMA(Close,10) white;

    How would I do this formally?

    Can I insert an appropriate "if statement" into the argument of the AddPlot statement so that it would look something like this:

    AddPlot(Brushes.{if(....)...}, "SMAPlot");

    Would this continually update the color as the curve is plotted?

    Thank you for your advice.

    #2
    Hello Dr Kerry,

    Thanks for your post.

    To change the color of a plot when a certain condition occurs you could use the PlotBrushes property.

    Here is a help guide page about the PlotBrushes property and sample code: https://ninjatrader.com/support/help...lotbrushes.htm

    Please let us know if we 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


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello Dr Kerry,

      Thanks for your post.

      To change the color of a plot when a certain condition occurs you could use the PlotBrushes property.

      Here is a help guide page about the PlotBrushes property and sample code: https://ninjatrader.com/support/help...lotbrushes.htm

      Please let us know if we may assist further.

      Brandon,

      Thank you very much. I think that the example given in the Help Guide link that you provided is exactly on target.

      Regards,

      Kerry

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      577 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      553 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X