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

Errors on Multi-colored plots

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

    Errors on Multi-colored plots

    Trying to plot 2 EMA's with multi colors - Rising and falling colors. Getting CS0103, CS1502 and CS1503 errors on the following code:

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.SkyBlue), PlotStyle.Line, "LittleMo"));
    Add(new Plot(Color.FromKnownColor(KnownColor.SkyBlue), PlotStyle.Line, "BigMo"));

    EMA(LittleMoPeriod).Plots[0].Pen.Color = Color.Orange;
    EMA(BigMoPeriod).Plots[1].Pen.Color = Color.Blue;

    Plots[0].Pen.Width = 2;
    Plots[1].Pen.Width = 2;

    Plots[0].PlotStyle = PlotStyle.Line;
    PLots[1].PlotStyle = PlotStyle.Line;

    Add(EMA(LittleMoPeriod));
    Add(EMA(BigMoPeriod));

    CalculateOnBarClose = true;
    }

    Can you help?

    #2
    Hello,

    If you are working with an indicator, Adding a plot will be a big different than an Indicator. You should be setting the EMA values in the OnBarUpdate section. In addition, the arguments for the Add() method will be different.

    Please see our Reference Sample on Plotting from within a NinjaScript Strategy

    When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability
    MatthewNinjaTrader Product Management

    Comment


      #3
      I am developing a Strategy. I now have corrected the problem I was referring to above. But the plots only plot in 1 color. Here is my code:

      if (Rising(EMA(LittleMoPeriod)))
      {
      EMA(LittleMoPeriod).Plots[0].Pen.Color = Color.Blue;
      }
      else if (Falling(EMA(LittleMoPeriod)))
      {
      EMA(LittleMoPeriod).Plots[0].Pen.Color = Color.Red;
      }
      else
      {
      EMA(LittleMoPeriod).Plots[0].Pen.Color = EMA(LittleMoPeriod).Plots[1].Pen.Color;
      }

      if (Rising(EMA(BigMoPeriod)))
      {
      EMA(BigMoPeriod).Plots[0].Pen.Color = Color.Lime;
      }
      else if (Falling(EMA(BigMoPeriod)))
      {
      EMA(BigMoPeriod).Plots[0].Pen.Color = Color.Black;
      }
      else
      {
      EMA(BigMoPeriod).Plots[0].Pen.Color = EMA(BigMoPeriod).Plots[1].Pen.Color;
      }

      How can I get it to plot the rising and falling colors?
      Thanks

      Comment


        #4
        Hello,

        All of the .Plots[] you are using refer to only Plot[0]. which is the first plot

        To assign plot values to this, you would need to specify which plot specificly you would like to change, Plot[1], Plot[2], etc.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Not sure what the different plots refer to. Would there be 4 plots since I have 2 colors and 2 EMA's?

          Comment


            #6
            the right code will be

            Code:
            EMA(LittleMoPeriod).PlotColors[0][0] = Color.LightGreen

            Comment


              #7
              Thanks.While I was making that change to my Strategy something went wrong with my mouse. Now when I try to run this Strategy It won't bring up the Properties window.
              How do I fix that?

              Comment


                #8
                Hello,

                Specifically what mouse click doesn't work or doesn't display?

                Comment


                  #9
                  The sequence I use is: File->New->Strategy Analyzer-> click on Instrument -> Right Click on Backtest
                  Then I click on the strategy I'm interested in running in the Backtest window

                  Now the correct Parameter window does not display.
                  Also I can not access the Out Put Window. Nothing happens when i click on it.
                  Do I need to start over with this Strategy?

                  Comment


                    #10
                    Hello,

                    Yea looks like you have a strategy error or compile issue in the code.

                    Can you try temporary deleting it (Save a copy of the code in word first.

                    Does the problem go away?

                    I look forward to assisting you further.

                    Comment


                      #11
                      I have created a new Strategy and I am still getting the wrong Properties window when I run a backtest. Is there a way I can send it to you?


                      I might have found and error. After I compile I get a message in the Output window "**NT** Failed to call method 'Initialize' for strategy SpitFire2..... Index was outside the bounds of the array.' Here is code:

                      protected override void Initialize()
                      {
                      CalculateOnBarClose = true;

                      ClearOutputWindow();

                      EMA(LittleMoPeriod).Plots[0].Pen.Color = Color.Blue;
                      EMA(BigMoPeriod).Plots[1].Pen.Color = Color.Lime;

                      EMA(LittleMoPeriod).Plots[0].Pen.Width = 2;
                      EMA(BigMoPeriod).Plots[1].Pen.Width = 2;

                      EMA(LittleMoPeriod).Plots[0].PlotStyle = PlotStyle.Line;
                      EMA(BigMoPeriod).Plots[1].PlotStyle = PlotStyle.Line;

                      Add(EMA(LittleMoPeriod));
                      Add(EMA(BigMoPeriod));


                      }
                      Last edited by freeway; 10-26-2011, 12:32 PM.

                      Comment


                        #12
                        Hello,

                        Sure please email me at support at ninjatrader dot com and reference this forum post. We will further assist and check it out and even test it on our side if needed.

                        I look forward to assisting you further.

                        Comment


                          #13
                          Originally posted by freeway View Post
                          I have created a new Strategy and I am still getting the wrong Properties window when I run a backtest. Is there a way I can send it to you?


                          I might have found and error. After I compile I get a message in the Output window "**NT** Failed to call method 'Initialize' for strategy SpitFire2..... Index was outside the bounds of the array.' Here is code:

                          protected override void Initialize()
                          {
                          CalculateOnBarClose = true;

                          ClearOutputWindow();

                          EMA(LittleMoPeriod).Plots[0].Pen.Color = Color.Blue;
                          EMA(BigMoPeriod).Plots[1].Pen.Color = Color.Lime;

                          EMA(LittleMoPeriod).Plots[0].Pen.Width = 2;
                          EMA(BigMoPeriod).Plots[1].Pen.Width = 2;

                          EMA(LittleMoPeriod).Plots[0].PlotStyle = PlotStyle.Line;
                          EMA(BigMoPeriod).Plots[1].PlotStyle = PlotStyle.Line;

                          Add(EMA(LittleMoPeriod));
                          Add(EMA(BigMoPeriod));


                          }
                          You are using a fully qualified classpath to EMA. EMA() has only one plot, so you cannot reference Plots[1].

                          Comment


                            #14
                            I have the following code in the OnBarUpdate() method:

                            if (Rising(EMA(LittleMoPeriod)))
                            {
                            EMA(LittleMoPeriod).Plots[0].Pen.Color = Color.Blue;
                            EMA(LittleMoPeriod).Plots[0].Pen.Width = 2;
                            }
                            else if (Falling(EMA(LittleMoPeriod)))
                            {
                            EMA(LittleMoPeriod).Plots[0].Pen.Color = Color.Red;
                            EMA(LittleMoPeriod).Plots[0].Pen.Width = 4;
                            }
                            else
                            {
                            EMA(LittleMoPeriod).Plots[0].Pen.Color = EMA(LittleMoPeriod).PlotColors[0][1];
                            }

                            if (Rising(EMA(BigMoPeriod)))
                            {
                            EMA(BigMoPeriod).Plots[0].Pen.Color = Color.Lime;
                            EMA(BigMoPeriod).Plots[0].Pen.Width = 2;
                            }
                            else if (Falling(EMA(BigMoPeriod)))
                            {
                            EMA(BigMoPeriod).Plots[0].Pen.Color = Color.Black;
                            EMA(BigMoPeriod).Plots[0].Pen.Width = 2;
                            }
                            else
                            {
                            EMA(BigMoPeriod).PlotColors[1][0] = EMA(BigMoPeriod).PlotColors[1][1];
                            }

                            It plots the EMA's OK but they are plotted only with the Rising color. It is as if the Falling code is ignored.

                            You say EMA has only 1 Plot. Does that mean I can only reference 1 plot in a Strategy?

                            Comment


                              #15
                              freeway,

                              Try doing it like this:

                              Code:
                                protected override void Initialize()
                                          {
                                          CalculateOnBarClose     = true;
                              
                                          ClearOutputWindow();
                              
                                          Add(EMA(LittleMoPeriod));
                                          Add(EMA(BigMoPeriod));
                                          }
                              Code:
                              protected override void OnBarUpdate()
                                      {
                                          
                                          if (Rising(EMA(LittleMoPeriod)))
                                          {
                                          EMA(LittleMoPeriod).PlotColors[0][0] = Color.Blue;
                                          EMA(BigMoPeriod).Plots[0].Pen.Width = 2;
                                          }
                                          else if (Falling(EMA(LittleMoPeriod)))
                                          {
                                          EMA(LittleMoPeriod).PlotColors[0][0] = Color.Red;
                                          EMA(LittleMoPeriod).Plots[0].Pen.Width = 4;
                                  
                                          }
                                          else
                                          {
                                          EMA(LittleMoPeriod).Plots[0].Pen.Color = EMA(LittleMoPeriod).PlotColors[0][0];
                                          }
                              
                                          if (Rising(EMA(BigMoPeriod)))
                                          {
                                          EMA(BigMoPeriod).PlotColors[0][0] = Color.Lime;
                                          EMA(BigMoPeriod).Plots[0].Pen.Width = 2;
                                          
                                          }
                                          else if (Falling(EMA(BigMoPeriod)))
                                          {
                                              
                                          EMA(BigMoPeriod).PlotColors[0][0] = Color.Black;
                                          EMA(BigMoPeriod).Plots[0].Pen.Width = 2;
                                          
                                          }
                                          else
                                          {
                                          EMA(BigMoPeriod).PlotColors[1][0] = EMA(BigMoPeriod).PlotColors[1][0];
                                          } 
                              
                                      }
                              Please let me know if you have any questions on this. If that does not work, try completely removing the strategy from the chart and adding it back in and re-enabling it.
                              MatthewNinjaTrader Product Management

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by dcriador, Today, 12:06 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post dcriador  
                              Started by dcriador, Today, 12:04 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post dcriador  
                              Started by cutzpr, Today, 08:54 AM
                              0 responses
                              11 views
                              0 likes
                              Last Post cutzpr
                              by cutzpr
                               
                              Started by benmarkal, Today, 08:44 AM
                              0 responses
                              16 views
                              0 likes
                              Last Post benmarkal  
                              Started by Tin34, Today, 03:30 AM
                              2 responses
                              28 views
                              0 likes
                              Last Post Tin34
                              by Tin34
                               
                              Working...
                              X