Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

call indicator in strategy...

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

    call indicator in strategy...

    hi i see this error :

    Indicator 'MainTrendAnalisys': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    i see you the structure of my program

    MaintrendAnalisys indicator (OnStateChange)

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "MainTrendAnalisys";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;


    AddPlot(Brushes.Green, "ContaMtUp");
    AddPlot(Brushes.Red, "ContaMtDown");
    AddPlot(new Stroke(Brushes.Green, 1), PlotStyle.Bar, "Mt");

    AddPlot(new Stroke(Brushes.Transparent, 3), PlotStyle.Dot, "CicliWilliam");
    AddPlot(new Stroke(Brushes.Transparent, 4), PlotStyle.Dot, "CicliWilliamBreve");
    AddPlot(new Stroke(Brushes.Transparent, 5), PlotStyle.Dot, "CicliWilliamMedio");
    AddPlot(new Stroke(Brushes.Transparent, 6), PlotStyle.Dot, "CicliWilliamLungo");

    Plotfc = Fc.Nessuno;
    DrawBArExtreme = Fc.Nessuno;
    anticipoBarDur = 0;
    CountMt = false;

    }
    else if (State == State.Configure)
    {
    Mt = new MT(this);
    mtClass = new MT.MTClass();
    LPT = new proiezTempo(Mt);
    Mp = new Gestione_Mt_Profit(Mt);
    cicliLarry = new cicliLarryWilliam(Mt);
    Mt.Add(mtClass);
    zarranum = new List<double>();
    zarrapos = new List<double>();
    arranum = new List<double>();
    myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = dimFont, Bold = false }; //15
    myFont2 = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 9) { Size = 9, Bold = false };
    myFont3 = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 50, Bold = false };
    myFont4 = new NinjaTrader.Gui.Tools.SimpleFont("Verdana", 10) { Size = 11, Bold = false };
    Historical = State == State.Historical; //da cancellare..e' per uso interno
    textOffset = offset * Instrument.MasterInstrument.TickSize;

    }


    My Strategy

    public class Mt : Strategy
    {

    private MainTrendAnalisys main;
    ...
    ....


    else if (State == State.Configure)
    {

    main = MainTrendAnalisys(3);
    }
    }

    protected override void OnBarUpdate()
    {

    main.Update();
    ...
    ....
    i see the problem is : Error on calling 'OnStateChange' method of indicator MaintrendAnalisys
    Last edited by turbofib; 12-11-2017, 03:46 PM.

    #2
    Hello turbofib,

    Thank you for the post.

    These two lines could be causing the pointer reference error, I do not see an initialization of variable Fc.

    Code:
    Plotfc = Fc.Nessuno;
    DrawBArExtreme = Fc.Nessuno;
    You may use Visual Studio to set breakpoints in your code to check at what line the OnStateChange function fails.

    Here is the help guide link on setting up Visual Studio Debugging:
    https://ninjatrader.com/support/help..._debugging.htm

    Please let us know if this does not resolve the issue.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      fc is defined here (see pic)


      If i apply my indicator in a chart..it is ok....(see pic)



      if i write in my strategy :

      Code:
      	protected override void OnBarUpdate()
      		{
                  return;  
      ....

      i get the same error...

      the problem is in OnStateChange() of my strategy ..in this line

      main = MainTrendAnalisys(3);
      Attached Files
      Last edited by turbofib; 12-12-2017, 08:57 AM.

      Comment


        #4
        Hello turbofib,

        Thank you for the reply.

        The error could be coming from any one of these custom classes you are setting up in State.Configure of MaintrendAnalisys. You will have to use Visual Studio and set a breakpoint inside of State.Configure and look for the null reference. It is difficult to see where the error is coming from since I can not see the types.

        What is this line doing here? What is the type of variable Mt?
        Mt = new MT(this);

        This line and the one below it are likely the cause of the error. Could you detail what you are trying to do with this line?

        I look forward to your reply.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          mt (see pic) is a class of some method i've build


          i do a debug with visual studio 7 but it's different...


          i follow you step but there is a problem ..see pic
          Attached Files
          Last edited by turbofib; 12-12-2017, 01:27 PM.

          Comment


            #6
            Hello,

            Thank you for the reply.

            Did you attach the solution to the NinjaTrader process? You also then must run the NinjaScript object. This means applying the indicator/strategy to a chart. The OnBarUpdate function has a return statement right before your breakpoint. The breakpoint will never be reached.

            Please let me know if you have any questions.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              i do it but i receive this error

              i attach ninjatrader process but it need solution
              Attached Files

              Comment


                #8
                i used print to debug it


                i see the problem is


                textOffset = offset * Instrument.MasterInstrument.TickSize;
                i use it in MainTrendAnalisys Indicator in State.Configure

                How do I replace the one with a working code?
                Last edited by turbofib; 12-12-2017, 05:43 PM.

                Comment


                  #9
                  Hello,

                  Thank you for the follow-up.

                  Are you setting offset to a value before you use it? The error is coming from either "offset" or "textOffset" not being initialized properly.

                  I look forward to hearing of your results.
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    i 've initialized it correctly...look this

                    public class MainTrendAnalisys : Indicator
                    {...
                    private double offset = 2;
                    private double textOffset = 1;




                    Comment


                      #11
                      Hello,

                      Thank you for the reply.

                      I can not tell where the error is deriving without the code. There is certainly something that is null at the time this line is read.

                      I was not able to reproduce this error with the attached script. Could you please provide a simplified example of your script that omits the logic and only reproduces the issue that we see here?

                      For instructions on importing please click here:
                      https://ninjatrader.com/support/help...us/?import.htm

                      For instructions on exporting please click here:
                      https://ninjatrader.com/support/help...us/?export.htm

                      I look forward to hearing of your results.
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        ok...try it
                        Attached Files

                        Comment


                          #13
                          Are you see my code ?

                          Comment


                            #14
                            Hello,

                            Sorry for the delay. Reviewing now.
                            Chris L.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello,

                              Thank you for your patience.

                              I was able to avoid the object reference error by placing this line is State.DataLoaded.

                              Code:
                              else if (State == State.Configure)
                                 {
                              
                                            //main = MainSearchError();
                                          }
                                  else if (State == State.DataLoaded)
                                 {
                              
                                            main = MainSearchError();
                                          }
                              The support team typically does not debug code, but this is a viable solution.

                              The reason for the error:
                              Calling Instrument.MasterInstrument.TickSize from this indicator being used by the strategy will return a null reference. You must wait until data is loaded in the strategy to reference the tick size of the master instrument in the indicator. You can call MasterInstrument in the Configure state of the strategy though.

                              Please let me know if I may be of any further assistance.
                              Chris L.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by tgn55, Today, 09:51 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post tgn55
                              by tgn55
                               
                              Started by cxxazssx, Today, 09:45 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post cxxazssx  
                              Started by southpacific001, 02-26-2021, 09:25 PM
                              14 responses
                              64 views
                              0 likes
                              Last Post REI140205  
                              Started by punkiy2111, Today, 05:22 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post punkiy2111  
                              Started by secrettrader, Today, 03:36 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post secrettrader  
                              Working...
                              X