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

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 Pattontje, Yesterday, 02:10 PM
                  2 responses
                  14 views
                  0 likes
                  Last Post Pattontje  
                  Started by flybuzz, 04-21-2024, 04:07 PM
                  17 responses
                  229 views
                  0 likes
                  Last Post TradingLoss  
                  Started by agclub, 04-21-2024, 08:57 PM
                  3 responses
                  17 views
                  0 likes
                  Last Post TradingLoss  
                  Started by TradingLoss, 04-21-2024, 04:32 PM
                  4 responses
                  43 views
                  2 likes
                  Last Post TradingLoss  
                  Started by cre8able, 04-17-2024, 04:16 PM
                  6 responses
                  56 views
                  0 likes
                  Last Post cre8able  
                  Working...
                  X