Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing Line color

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

    Changing Line color

    I have added an SMA to my chart and I would like to change the color of it based on the direction of the movement.

    I have added it using:
    TrendLine = SMA(33);
    TrendLine.Plots[0].Brush = Brushes.Red;
    AddChartIndicator(TrendLine);

    When I set it as above it is always Red.

    If I try to set is OnBarUpdate() as below it does not work.
    TrendLine.Plots[0].Brush = Brushes.Green;

    What is the Proper way to set the color during OnBarUpdate()?
    I've seen this done, but all my testing and searching hasn't helped.

    Thanks.

    #2
    Hello ATMtrader0001,

    Thanks for your post.

    PlotBrushes could be used to determine the color of a plot when certain conditions become true.

    See the attached example script demonstrating how to change the color of a plot in a strategy when certain conditions become true. In the example script, we add the SMA indicator on the chart using AddChartIndicator(). Then, when we have an up bar, we use PlotBrushes to change the plot color to blue. When we have a down bar, we use PlotBrushes to change the plot color to pink.

    Also, see this help guide page for more information: https://ninjatrader.com/support/help...lotbrushes.htm

    Let us know if we may assist further.
    Attached Files
    <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
      Thanks. That was it.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      66 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X