Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator line multi-coloring for up/down

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

    Indicator line multi-coloring for up/down

    I wanted to color SMA line green when going up and red when down. I copied SMA code into a new indicator with Save-As and only added the following code at the end of OnBarUpdate method:
    Code:
    if (CurrentBar > 0)
    {
    	if (Value[0]>Value[1])
    		this.Plots[0].Pen.Color = Color.Green ;
    	else if (Value[0]<Value[1])
    		this.Plots[0].Pen.Color = Color.Red ;
    	else
    		this.Plots[0].Pen.Color = Color.Gray ;
    }
    It compiles fine, but it doesn't work - it apears that whatever was the first pair of bars coloring situation, it uses that color for all segments afterwards.

    Thanks in advance.

    #2
    Please see this sample: http://www.ninjatrader-support.com/v...ead.php?t=3227

    Comment


      #3
      Thanks Dierk, my understanding of the sample is that I have to have as many plots as colors - correct? If yes, that's very unfortunate for it complicates coding of NT indicators a great deal.

      In my previous thread http://www.ninjatrader-support.com/v...ad.php?p=43715, I inquired about creating a heatmap and Josh referred me to the same article as you, and now I don't know how to go about it for a heatmap can have hundreds of colors there. Thoughts?

      Comment


        #4
        You then would need to override the Plot() method and custom code the rendering routines (see CustomPlotSample indicator). Unfortunately this is beyond the level what we can provide support for.

        Comment


          #5
          Thanks. I'll take a look. Please consider adding an easier way to multicolor a single plot in NT v7. Ultimately, it should be as easy as setting an indicator value in OnBarUpdate - meaning that my intial code sample I tried should work in v7.

          Comment


            #6
            Thanks for your suggestion. We'll add it to the list of future considerations.

            Comment


              #7
              Trouble with the neutral plot

              I'm having trouble with the code in the sample indicator, I've modified it slightly to use an EMA instead of an SMA, everything works great until I put in the code at the end...
              else
              {
              //Neutral.Set(1,EMA(Period)[1]);
              Neutral.Set(EMA(Period)[0]);
              }
              if I uncomment the code above the whole indicator quits working and no lines are plotted, if I leave it like you see above, it works but of course leaves gaps when it is neutral. Anyone else having this problem??

              Comment


                #8
                Originally posted by goobtrader View Post
                I'm having trouble with the code in the sample indicator, I've modified it slightly to use an EMA instead of an SMA, everything works great until I put in the code at the end...
                else
                {
                //Neutral.Set(1,EMA(Period)[1]);
                Neutral.Set(EMA(Period)[0]);
                }
                if I uncomment the code above the whole indicator quits working and no lines are plotted, if I leave it like you see above, it works but of course leaves gaps when it is neutral. Anyone else having this problem??
                You can find the code to fill the gaps in indicators like T3Average.
                RJay
                NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

                Comment


                  #9
                  I think I figured it out, thanks for your reply

                  Originally posted by rt6176 View Post
                  You can find the code to fill the gaps in indicators like T3Average.
                  I didn't have this part of the code in there
                  if (CurrentBar < 1)
                  return;
                  and the indicator was failing without it.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  571 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  330 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
                  549 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  549 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X