• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pivot error

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

    Pivot error

    Hi All,

    I have a strategy which within its OnBarUpdate function calls an indicator. The function in the indicator calls this and I get an error.

    Any ideas,
    Cleo



    Error:
    Error on calling 'OnBarUpdate' method for strategy 'PivotInputTester/be07f09df7bf4629a696f604496067ba': Object reference not set to an instance of an object.

    Code:
    if (Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).PP.ContainsValue(0)){
    // Prints the current pivot point value
    double value = Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).PP[0];
    Print("The current Pivots' pivot value is " + value.ToString());
    } else {
    Print("Not Valid Pivot");
    }

    #2
    Try adding the following check at the start of your OnBarUpdate() to ensure enough bars have been loaded.

    // Checks to make sure we have at least 20 or more bars (use more bars if needed)
    if (CurrentBar < 20)
    return;

    http://www.ninjatrader.com/support/h...currentbar.htm

    Let me know if I can be of further assistance.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Originally posted by cleo4343 View Post
      Hi All,

      I have a strategy which within its OnBarUpdate function calls an indicator. The function in the indicator calls this and I get an error.

      Any ideas,
      Cleo



      Error:
      Error on calling 'OnBarUpdate' method for strategy 'PivotInputTester/be07f09df7bf4629a696f604496067ba': Object reference not set to an instance of an object.

      Code:
      if (Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).PP.ContainsValue(0)){
      // Prints the current pivot point value
      double value = Pivots(PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20).PP[0];
      Print("The current Pivots' pivot value is " + value.ToString());
      } else {
      Print("Not Valid Pivot");
      }
      Are you sure that you have loaded enough data to be able to calculate a pivot in the first place? Remember that pivots are calculated from data off of the previous day.

      Comment


        #4
        Thanks for the replies but I think my problem is more related to the calling the pivots within an indicator from a strategy. I believe this because if I call the Pivot function within the OnBarUpdate function of my custom indicator it works as expected. If I call the Pivot function within OnBarUpdate of my strategy it also works as expected.

        The problem occurs only when within the OnBarUpdate function of my strategy I load a custom indicator and call a custom function which in turn calls the Pivot function. Surprisingly adding the sanity check if (CurrentBar < 20) also causes an error.

        What I am trying to accomplish is moving most of my calculation logic outside of the strategy as the class gets very big fast.

        Any suggestions,
        Cleo

        Comment


          #5
          You may need to load more than just 20 bars beforehand as Koganam states. Do you still get this error if you load enough bars to encompass the prior days trading as well?

          If you have could you please post the .cs files that replicate this error.
          They are located in (MY)Documents\NinjaTrader 7\bin\Custom\Indicator (or strategy)
          LanceNinjaTrader Customer Service

          Comment


            #6
            Thanks you very much. Please let me know what I'm doing wrong.

            Cheers,
            Cleo

            PivotInputTester.cs

            IsPivotInZone.cs

            Comment


              #7
              In your strategy use the following to create an instance of the indicator and call the method.

              Change

              Code:
              IsPivotInZone isPivotInZone = new IsPivotInZone();
              isPivotInZone.debugPrint();
              to

              Code:
              IsPivotInZone(true, 1, 2).debugPrint();// where true, 1 , 2 are your custom inputs
              Let me know if I can be of further assistance.
              LanceNinjaTrader Customer Service

              Comment


                #8
                Thanks that was the problem.

                I noticed that the Pivot function accessing PP is 0 for the first 5 requests in the strategy then it updates to the correct value while in the Indicator its 0 for 20 requests then it updates. Is there something I can do about this?

                Cheers,
                Cleo

                Comment


                  #9
                  Hello Cleo,

                  Thank you for your response.


                  The indicator and strategy load the bars required and then calculates. So for the first bars the value is 0 (zero) as it has not calculated.

                  You have set your check of the bars, correct? Similar to if (CurrentBar < 20) return;?

                  Please let me know if I may be of further assistance.
                  Last edited by NinjaTrader_PatrickH; 03-21-2013, 06:26 AM.
                  Patrick H.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks you for looking into my problems.

                    I am still having issues calling Pivot functions from my custom Indicator within a strategy.


                    If I call
                    PivotLevelInZone(
                    1).printOneZone(); It prints a Pivot value of 0 and I'm not sure exectly how to load the bars.

                    If I call the PrintAll Pivots it simple prints 0 for all the values comes back to the onBarUpdate functions, but the onBarUpdate function is never called again.

                    Cheers,
                    Cleo
                    Attached Files

                    Comment


                      #11
                      Hello Cleo,

                      Thank you for your response.

                      The indicator has nothing called or plotted in the OnBarUpdate() method, therefore there is no output from the indicator.
                      Code:
                              protected override void OnBarUpdate()
                              {
                                  // Use this method for calculating your indicator values. Assign a value to each
                                  // plot below by replacing 'Close[0]' with your own formula.
                                //  Plot0.Set(Close[0]);
                              }
                      If there is a value to be set or variable you need to do so in the OnBarUpdate() method or another method that is called more than once so that the values update.

                      Please let me know if I may be of further assistance.
                      Patrick H.NinjaTrader Customer Service

                      Comment


                        #12
                        Maybe I'm not doing this the correct way or clearly explaining what I'm trying to accomplish.

                        I want my Pivot logic to exist in its own file and have my strategy call it. (I thought I could do it in an Indicator but I am agnostic on how this could be done) How can this be accomplished? I do not want the logic in the strategy code.

                        Thanks,
                        Cleo

                        Comment


                          #13
                          Hello Cleo,

                          Thank you for your response.

                          If you wish to call the Indicator in your Strategy you can do so, but you must make sure there are values to be accessed.

                          You can set the values you plan to access in the OnBarUpdate() method of the Indicator to ensure they update on each bar update. If you wish to create your own custom event handler then please visit the following link for example of doing this within an indicator: http://www.ninjatrader.com/support/f...ead.php?t=5965

                          Please let me know if you have any questions.
                          Patrick H.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi and thanks for the response.

                            Is there a way I could get the IDataSeries from the strategy then pass it via the constructor to the Indicator? Would this give the Indicator the correct data?

                            When I try to load it from the "OnBarUpdate" function within the Indicator the Pivot load correctly the first time, then it turns to a value of 0.

                            Thanks,
                            Cleo

                            Comment


                              #15
                              Hello Cleo,

                              Thank you for your response.

                              You will not be able to pass the information from the strategy to the indicator.

                              Please provide a code snippet of the OnBarUpdate() where you call the Pivot so I may investigate this matter further.

                              I look forward to your response.
                              Patrick H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by guvenators, Today, 05:18 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by LANwarr1or, Today, 03:00 PM
                              2 responses
                              8 views
                              0 likes
                              Last Post LANwarr1or  
                              Started by Newtrader101, Today, 02:53 PM
                              2 responses
                              10 views
                              0 likes
                              Last Post Newtrader101  
                              Started by JuanPabloQuevedo, Today, 02:53 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post JuanPabloQuevedo  
                              Started by samir, Today, 03:16 PM
                              2 responses
                              14 views
                              0 likes
                              Last Post samir
                              by samir
                               
                              Working...
                              X