Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Coloring Bars of a custom indicator

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

    Coloring Bars of a custom indicator

    Hi everyone

    I built a custom indicator and want to color positive bars green and nehative bars red.

    I wrote the following after Initialize():
    Add(new Plot(new Pen(Color.LimeGreen, 5), PlotStyle.Bar, "Up"));
    Add(
    new Plot(new Pen(Color.Red, 5), PlotStyle.Bar, "Down"));

    And after OnBarUpdate():

    if( Value[0] > 0 )
    BarColor = Color.LimeGreen;
    elseif( Value[0] < 0 )
    BarColor = Color.Red;

    My plot though is always green, also for negative values. Why?

    Thank you for help

    #2
    - You don't need to add plots
    - You want to check something like:

    if (Close[0] > Open[0])
    BarColor = Color.LimeGreen;
    else
    BarColor = Color.Red;
    RayNinjaTrader Customer Service

    Comment


      #3
      I took out the two lines of code to add plots, but in this way I get just a yellow line plotted (the default, I think).

      Comment


        #4
        See this tutorial for a similar concept.

        RayNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        42 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        25 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        162 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        98 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        157 views
        2 likes
        Last Post CaptainJack  
        Working...
        X