Announcement

Collapse
No announcement yet.

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.

    http://www.ninjatrader-support.com/v...ead.php?t=3227
    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 RisingPlot
        {
            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 vibrationketousa, Today, 12:26 AM
          0 responses
          1 view
          0 likes
          Last Post vibrationketousa  
          Started by vibrationketousa, Today, 12:24 AM
          0 responses
          2 views
          0 likes
          Last Post vibrationketousa  
          Started by hdge4u, Yesterday, 09:09 PM
          0 responses
          17 views
          0 likes
          Last Post hdge4u
          by hdge4u
           
          Started by hdge4u, Yesterday, 09:02 PM
          0 responses
          8 views
          0 likes
          Last Post hdge4u
          by hdge4u
           
          Started by stormcloudseven, Yesterday, 08:41 PM
          1 response
          9 views
          0 likes
          Last Post DavidTrades  
          Working...
          X