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 change Color

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

    Dynamically change Color

    I tried the example in the help screen to dynamically change color of a plot. However, only the last change is active throughout the plot so I get only one change rather than a change for different bars.
    Example from help:
    // Dynamically change the primary plot's color based on the indicator value
    protected override void OnBarUpdate()
    {
    if (Values[0] > 100)
    Plots[0].Pen = new Pen(Color.Blue);
    else
    Plots[0].Pen = new Pen(Color.Red);
    }


    My code:
    if(piSignal[0] == 1)
    {Plots[2].Pen = new Pen(Color.Green,3); else if (piSignal[0] == -1)
    {Plots[2].Pen = new Pen(Color.Red,3);
    else
    {Plots[2].Pen = new Pen(Color.Yellow,3);

    #2
    Correct, your code does exactly that. If you want to have different plotted colors check out this sample.

    RayNinjaTrader Customer Service

    Comment


      #3
      Question about dynamically changing Plot colors

      Hello Ray.

      I am taking a look at the example you posted on dynamically changing Plot colors.

      Question. I'm not sure how 'RisingPlot.Set(1, SMA(Period)[1]);' is working.

      I have ..

      Add(new Plot(Color.Green, PlotStyle.Dot, "Upper"));
      Add(new Plot(Color.Red, PlotStyle.Dot, "Lower"));
      Add(new Plot(Color.Yellow, PlotStyle.Dot, "Middle"));

      But when I get to ..

      UpperPlot.Set(1, MACD(fastLen, slowLen, smooth)[1]);
      UpperPlot.Set(MACD(fastLen, slowLen, smooth)[0]);

      The compiler tells me 'The name 'UpperPlot' does not exist in the current context'.

      What am I missing ?

      Why does the compiler recognize 'RisingPlot.Set' and not 'UpperPlot.Set' ?

      Regards,
      R. C. Singleton

      Comment


        #4
        Hi rcsingleton,

        The plot names are defined in the collapsed "Properties" section of your code.

        Code:
        // Adds three DataSeries to store the values of the three plots added in Initialize()
        [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
        [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
        public DataSeries [COLOR=Red]RisingPlot[/COLOR]
        {
            get { return Values[0]; }
        }
        The index on Values corresponds to the Add() method you had above.
        Code:
        Add(new Plot(Color.Green, PlotStyle.Dot, "Upper"));
        Add(new Plot(Color.Red, PlotStyle.Dot, "Lower"));
        Add(new Plot(Color.Yellow, PlotStyle.Dot, "Middle"));
        Index of 0 corresponds with "Upper", index=1="Lower", index=2="Middle".
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thank You

          Thank you Josh.

          That did the trick. Will remember to look at 'Properties' section in the future.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by inanazsocial, Today, 01:15 AM
          0 responses
          2 views
          0 likes
          Last Post inanazsocial  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          5 responses
          22 views
          0 likes
          Last Post trilliantrader  
          Started by Davidtowleii, Today, 12:15 AM
          0 responses
          3 views
          0 likes
          Last Post Davidtowleii  
          Started by guillembm, Yesterday, 11:25 AM
          2 responses
          9 views
          0 likes
          Last Post guillembm  
          Started by junkone, 04-21-2024, 07:17 AM
          9 responses
          70 views
          0 likes
          Last Post jeronymite  
          Working...
          X