Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Brandon H.NinjaTrader Customer Service

    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 burtoninlondon, Today, 12:38 AM
      0 responses
      10 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      14 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      14 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,983 views
      3 likes
      Last Post jhudas88  
      Working...
      X