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 doesnt plot in data window but plots in strategy builder

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

    indicator doesnt plot in data window but plots in strategy builder

    I have a supp and resistance indicator that i am seeing plots in strategy builder but it doenst plot in data window. What could it be?


    Click image for larger version

Name:	image.png
Views:	138
Size:	1.16 MB
ID:	1262151

    #2
    Hello tkaboris,

    Thank you for your post.

    Which data window are you referring to? If you add this indicator to a strategy in strategy builder with the "Plot on chart" box checked, then enable the strategy on a chart, do you see the plots on the chart? If not, do you see any errors on the Log tab of the Control Center?

    I look forward to your reply.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Well i didnt know that.
      So if indicator doesnt plot values I wont see it in data window. But if i use same indicator in strategy i am able to get it to plot if i use it in strategy?

      Comment


        #4
        Hello tkaboris,

        Thank you for your reply.

        I was not providing information to you about plotting values from the indicator vs. in a strategy. I am asking questions to clarify your inquiry. What is the "data window" that you are referring to? Can you please send me a screenshot of the data window?
        • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
        • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.
        ​I am also curious - when you check the Log tab of the Control Center when trying to load the indicator, do you see any errors? If so, what do the errors report? For the moment, I would like to focus on these questions rather than testing the behavior if you add the indicator to a strategy in the Strategy Builder. This way I can better understand what is happening with the "data window" and identify the next steps to resolve your inquiry.

        I look forward to your reply.
        Emily C.NinjaTrader Customer Service

        Comment


          #5
          Hi I was just referring to regular data box window

          Comment


            #6
            Originally posted by tkaboris View Post
            Hi I was just referring to regular data box window
            For an indicator's plots to show in the data box, the indicator must have DisplayInDataBox set to true in either State.SetDefaults or State.Configure:


            Please let us know if we may be of further assistance.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Hi i used strategy builder to include indicator to the strategy and it did, but when I enable it i get error
              Indicator 'SupDemZones': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object. Can you please help?
              Thank you

              Code:
              #region Using declarations
              using System;
              using System.Collections.Generic;
              using System.ComponentModel;
              using System.ComponentModel.DataAnnotations;
              using System.Linq;
              using System.Text;
              using System.Threading.Tasks;
              using System.Windows;
              using System.Windows.Input;
              using System.Windows.Media;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Gui;
              using NinjaTrader.Gui.Chart;
              using NinjaTrader.Gui.SuperDom;
              using NinjaTrader.Gui.Tools;
              using NinjaTrader.Data;
              using NinjaTrader.NinjaScript;
              using NinjaTrader.Core.FloatingPoint;
              using NinjaTrader.NinjaScript.Indicators;
              using NinjaTrader.NinjaScript.DrawingTools;
              #endregion
              
              //This namespace holds Strategies in this folder and is required. Do not change it.
              namespace NinjaTrader.NinjaScript.Strategies
              {
                  public class MyCustomStrategy10 : Strategy
                  {
                      private SupDemZones SupDemZones1;
                      private SMA SMA1;
              
                      protected override void OnStateChange()
                      {
                          if (State == State.SetDefaults)
                          {
                              Description                                    = @"Enter the description for your new custom Strategy here.";
                              Name                                        = "MyCustomStrategy10";
                              Calculate                                    = Calculate.OnBarClose;
                              EntriesPerDirection                            = 1;
                              EntryHandling                                = EntryHandling.AllEntries;
                              IsExitOnSessionCloseStrategy                = true;
                              ExitOnSessionCloseSeconds                    = 30;
                              IsFillLimitOnTouch                            = false;
                              MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                              OrderFillResolution                            = OrderFillResolution.Standard;
                              Slippage                                    = 0;
                              StartBehavior                                = StartBehavior.WaitUntilFlat;
                              TimeInForce                                    = TimeInForce.Gtc;
                              TraceOrders                                    = false;
                              RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                              StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                              BarsRequiredToTrade                            = 20;
                              // Disable this property for performance gains in Strategy Analyzer optimizations
                              // See the Help Guide for additional information
                              IsInstantiatedOnEachOptimizationIteration    = true;
                          }
                          else if (State == State.Configure)
                          {
                          }
                          else if (State == State.DataLoaded)
                          {                
                              SupDemZones1                = SupDemZones(Close, true, barTypes.Minute, 15, Brushes.YellowGreen, Brushes.Tomato, 0.3f, 0.15f, 0.1f, 0.05f, 1, false, false, true, @"1.2 | Dec. 2016");
              //                SMA1                = SMA(Close, 14);
                              SupDemZones1.Plots[0].Brush = Brushes.YellowGreen;
                              SupDemZones1.Plots[1].Brush = Brushes.Tomato;
                              AddChartIndicator(SupDemZones1);
                          }
                      }
              
                      protected override void OnBarUpdate()
                      {
                          if (BarsInProgress != 0)
                              return;
              
                          if (CurrentBars[0] < 1)
                              return;
              
                           // Set 1
              //            if (CrossBelow(SupDemZones1, SMA1, 1))
              //            {
              //            }
              
                      }
                  }
              }
              ​

              Comment


                #8
                Hello tkaboris,

                Thank you for your reply.

                Is SupDemZones an indicator you developed or was it imported from a third party? The error "Object reference not set to an instance of an object" could have a few potential causes. It is a very common error that happens when an object value is referenced, but that value is null. We have a tip page in the help guide about checking for null references here:


                It sounds like the error needs to be addressed within the indicator script itself and is not something you are doing in the Strategy Builder. If you developed the indicator, we could guide you through the debugging process of adding prints and figuring out what object is resulting in the null reference. Otherwise, if it was imported from a third party, you may need to reach out to the developer to let them know about the error and/or see if they have an updated version of the script that has logic in place to prevent this error.

                Please let me know if I may be of further assistance.
                Emily C.NinjaTrader Customer Service

                Comment


                  #9
                  hi supdemzones is indicator from third party and there is no developer for this. Indicator compiles and is working alright. I thought if indicator compiles and working then it should work in strategy.
                  too.

                  Comment


                    #10
                    Hello tkaboris,

                    Thank you for your reply.

                    Although the indicator compiles, that alone does not prevent it from getting errors when running the script or calling the indicator from another script, such as a strategy.

                    Do you see errors if you try to add just the indicator (not the strategy) to a chart? I am curious about the results if you try to add the indicator with the same settings you tried in your strategy:
                    SupDemZones(Close, true, barTypes.Minute, 15, Brushes.YellowGreen, Brushes.Tomato, 0.3f, 0.15f, 0.1f, 0.05f, 1, false, false, true, @"1.2 | Dec. 2016")

                    I look forward to your reply with the results.
                    Emily C.NinjaTrader Customer Service

                    Comment


                      #11
                      hi, no idicator errors when loading just an indicator. However when loading strategy, i had to cast to floats 4 settings. in order to compile. maybe thats why?

                      Comment


                        #12
                        Hello tkaboris,

                        Thank you for your reply.

                        I suggest adding prints to debug your script. This will help you to narrow down which part of your strategy is causing the error. There are suggestions for debugging your scripts here:


                        Since you are working with the Strategy Builder, you could even add prints from the strategy builder as demonstrated in the following post and video:The prints can help you to understand the values being used, such as the floats, as well as which line might be causing errors. The last print to show before the error can help to narrow down what line of code is causing the errors.

                        I would be glad to test the strategy on my end and see if it also results in errors. Then, I can get a better idea of what might be the next step in the debugging process. Please export the strategy by going to Control Center > Tools > Export > NinjaScript AddOn. Select your strategy and the indicator. Once the export is successful, you may attach the .zip file that is generated to your reply here in the forum.

                        I look forward to assisting you further.
                        Emily C.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi ,
                          please find an attached strategy and indicator
                          I appriciate your help
                          Attached Files

                          Comment


                            #14
                            Hello tkaboris,

                            Thank you for your reply.

                            When I tried to apply SupDemZones to a chart with the default settings, I got the same error you were getting with the strategy:
                            • Indicator 'SupDemZones': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.
                            You said you get no errors when loading the indicator to a chart; have you recompiled with your changes, then removed the indicator from a chart and added it again?

                            Since the error is coming from OnStateChange, I added prints throughout OnStateChange with the line number. What are the results if you add these prints to the script then try to add it to a chart?
                            Code:
                                    protected override void OnStateChange()
                                    {
                                        if(State == State.SetDefaults)
                                        {
                                            Description                    = @"";
                                            Print("95");
                                            Name                        = "SupDemZonesWithPrints";
                                            Calculate                    = Calculate.OnBarClose;
                                            IsOverlay                    = true;
                                            IsAutoScale                 = false;
                                            DrawOnPricePanel            = true;
                                            PaintPriceMarkers            = false;
                                            IsSuspendedWhileInactive    = false;
                                            ScaleJustification            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                                            IsSuspendedWhileInactive    = true;
                                            Print("105");
                                            AddPlot(Brushes.YellowGreen, "zl");
                                            AddPlot(Brushes.Tomato, "zr");                                                
                            
                            
                                            useMTF                = false;
                                            barType                = barTypes.Minute;
                                            barPeriod             = 30;
                                            demandColor            = Brushes.YellowGreen;
                                            supplyColor            = Brushes.Tomato;
                                            Print("115");
                                            activeLineOpacity    = 0.30f;
                                            activeAreaOpacity    = 0.15f;
                                            brokenLineOpacity    = 0.10f;
                                            brokenAreaOpacity    = 0.05f;
                                            Print("120");
                                            lineWidth            = 1;
                                            extendZones            = false;
                                            hideActiveZones     = false;
                                            hideBrokenZones     = true;
                                            indicatorVersion    = "1.2 | Dec. 2016";
                                            Print("126");
                            
                                        }
                                        else if(State == State.Configure)
                                        {
                                            if(useMTF)
                                            {
                                                barIndex = 1;
                                                AddDataSeries((BarsPeriodType)barType, barPeriod);
                                            }
                                            Print("136");
                                            ZOrder = ChartBars.ZOrder - 7;
                                            Print("138");
                                            if(!initOne)
                                            {
                                                menuSepa       = new Separator();
                                                menuItem       = new MenuItem { Header = "Zones" };
                                                menuItemActive = new MenuItem { Header = (hideActiveZones) ? "Show Active Zones" : "Hide Active Zones" };
                                                menuItemBroken = new MenuItem { Header = (hideBrokenZones) ? "Show Broken Zones" : "Hide Broken Zones" };
                                                Print("145");
                                                menuItemActive.Click += toggleActiveZones;
                                                menuItemBroken.Click += toggleBrokenZones;
                                                Print("148");
                                                menuItem.Items.Add(menuItemActive);
                                                menuItem.Items.Add(menuItemBroken);
                                                Print("151");
                                                initOne = true;
                                            }
                                        }
                            ​
                            What is the last print you see in the NinjaScript Output window prior to getting an error? This will help to determine what line is causing the error.

                            I look forward to your reply.
                            Emily C.NinjaTrader Customer Service

                            Comment


                              #15
                              I see these

                              95
                              105
                              126
                              136
                              138
                              95
                              105
                              126
                              136
                              138​

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by burtoninlondon, Today, 12:38 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post burtoninlondon  
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              0 responses
                              14 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Yesterday, 08:42 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Yesterday, 07:51 PM
                              0 responses
                              13 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,983 views
                              3 likes
                              Last Post jhudas88  
                              Working...
                              X