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

Object reference not set to an instance of an object.

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

    Object reference not set to an instance of an object.

    Dear Team,
    This is surely some total basic question, but I am also total basic in Ninjascript. Your help would be appreciated.
    I found in the resources that one should test for 0 after OnBarUpdate().
    So I did with all variables like so:

    if (CloseSetBear==0)
    {
    CloseSetBear=1;
    }
    else if (CloseSetBear!= 0)
    return;

    Still I get the same error message over again. Did I miss something, or is the code I use above wrong?

    I checked all double variables you see in the code:

    public class RSXDivergenceMarker : Indicator
    {
    private bool DIVBear;
    private double CloseSetBear;
    private double RSXSetBear;
    private bool DIV2Bear;
    private double CloseD_Bear;
    private double RSXD_Bear;
    private bool DIVBull;
    private double CloseSetBull;
    private double RSXSetBull;
    private bool DIV2Bull;
    private double CloseD_Bull;
    private double RSXD_Bull;

    private NinjaTrader.NinjaScript.Indicators.Jurik_Research. JRC_RSX JRC_RSX1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Uses RSX to mark momentum divergences on chart,";
    Name = "RSXDivergenceMarker";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    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;
    RSX_Length = 15;
    Over = 30;
    OverD = 30;
    OverD2 = 30;
    Under = -30;
    UnderD = -30;
    UnderD2 = -30;
    MarkerOffset = 5;
    MarkerOffsetD2 = 5;
    BarsLookback = 40;
    MarkerOffsetNegative = -5;
    MarkerOffsetNegativeD2 = -5;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {

    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 2)
    return;




    // Set 1
    if ((JRC_RSX1[2] < JRC_RSX1[1])
    && (JRC_RSX1[1] > JRC_RSX1[0])
    && (JRC_RSX1[0] > Over))
    {
    DIVBear = true;
    CloseSetBear = Close[0];
    RSXSetBear = JRC_RSX1[0];
    Draw.ArrowDown(this, @"RSXDivergence Arrow down_1", true, 0, (High[0] + (MarkerOffset * TickSize)) , Brushes.Red);
    }

    // Set 2
    if ((JRC_RSX1[2] < JRC_RSX1[1])
    && (JRC_RSX1[1] > JRC_RSX1[0])
    && (JRC_RSX1[0] > OverD)
    && (DIVBear == true)
    && (Close[0] > CloseSetBear)
    && (JRC_RSX1[0] < RSXSetBear))
    {
    CloseD_Bear = Close[0];
    RSXD_Bear = JRC_RSX1[0];
    Draw.Diamond(this, @"RSXDivergence Diamond_1", true, 0, (High[0] + (MarkerOffset * TickSize)) , Brushes.Red);
    DIV2Bear = true;
    Alert(@"RSXDivergence_1", Priority.Medium, @"Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.GreenYellow, Brushes.Black);
    }

    // Set 3
    if ((JRC_RSX1[2] < JRC_RSX1[1])
    && (JRC_RSX1[1] > JRC_RSX1[0])
    && (JRC_RSX1[0] > OverD2)
    && (DIV2Bear == true)
    && (Close[0] > CloseD_Bear)
    && (JRC_RSX1[0] < RSXD_Bear))
    {
    Draw.Diamond(this, @"RSXDivergence Diamond_1", true, 0, (High[0] + (MarkerOffsetD2 * TickSize)) , Brushes.Gold);
    Alert(@"RSXDivergence_1", Priority.High, @"Double Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.Red, Brushes.Black);
    Draw.Diamond(this, @"RSXDivergence Diamond_1", true, 0, (High[0] + (MarkerOffset * TickSize)) , Brushes.Red);
    }

    // Set 4
    if ((JRC_RSX1[2] > JRC_RSX1[1])
    && (JRC_RSX1[1] < JRC_RSX1[0])
    && (JRC_RSX1[0] < Under))
    {
    DIVBull = true;
    CloseSetBull = Close[0];
    RSXSetBull = JRC_RSX1[0];
    Draw.ArrowUp(this, @"RSXDivergence Arrow up_1", true, 0, (Low[0] + (MarkerOffsetNegative * TickSize)) , Brushes.Lime);
    }

    // Set 5
    if ((JRC_RSX1[2] > JRC_RSX1[1])
    && (JRC_RSX1[1] < JRC_RSX1[0])
    && (JRC_RSX1[0] < UnderD)
    && (DIVBull == true)
    && (Close[0] < CloseSetBull)
    && (JRC_RSX1[0] > RSXSetBull))
    {
    DIV2Bull = true;
    CloseD_Bull = Close[0];
    RSXD_Bull = JRC_RSX1[0];
    Draw.Diamond(this, @"RSXDivergence Diamond_4", false, 0, (Low[0] + (MarkerOffsetNegative * TickSize)) , Brushes.Lime);
    Alert(@"RSXDivergence_1", Priority.Medium, @"Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.GreenYellow, Brushes.Black);
    }

    // Set 6
    if ((JRC_RSX1[2] > JRC_RSX1[1])
    && (JRC_RSX1[1] < JRC_RSX1[0])
    && (JRC_RSX1[0] < UnderD2)
    && (DIV2Bull == true)
    && (Close[0] < CloseD_Bull)
    && (JRC_RSX1[0] > RSXD_Bull))
    {
    Draw.Diamond(this, @"RSXDivergence Diamond_4", false, 0, (Low[0] + (MarkerOffsetNegative * TickSize)) , Brushes.Lime);
    Draw.Diamond(this, @"RSXDivergence Diamond_4", false, 0, (Low[0] + (MarkerOffsetNegativeD2 * TickSize)) , Brushes.Gold);
    Alert(@"RSXDivergence_1", Priority.High, @"Double Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.Red, Brushes.Black);
    }

    #2
    Hello Balage0922,

    The error you provided:

    Code:
    Object reference not set to an instance of an object.
    Specifically means something being used is null, this shouldn't be the double variables as those cannot be null.

    I am not able to see what would be null from what you have provided, this can likely be diagnosed by commenting out the syntax you have used to further identify which line is throwing the error.

    For this, I would suggest trying the following.
    • Starting at the bottom of the OnBarUpdate logic, comment out each of the conditions you have defined. You have some comments for the Set's, this would include commenting out sets 2 - 6, or others beyond 6 if they were not shown,
    • Compile the script and re-run it to check for the error.
    • If you still get the error, that would mean the code causing the problem is part of set 1 or before it.
    • You can do this test for each set or until you find where the problem is happening.
    Once you find the general area of the problem, we can look at the code used there to see what may be null.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse,
      I have so far found that setting variables like below does not produce results, this might be related to the issue:
      CloseSetBear = Close[0];
      RSXSetBear = JRC_RSX1[0];

      Example:

      // Set 1
      if ((JRC_RSX1[2] < JRC_RSX1[1])
      && (JRC_RSX1[1] > JRC_RSX1[0])
      && (JRC_RSX1[0] > Over))
      {
      DIVBear = true;
      CloseSetBear = Close[0];
      RSXSetBear = JRC_RSX1[0];
      Draw.ArrowDown(this, @"RSXDivergence Arrow down_1", true, 0, (High[0] + (MarkerOffset * TickSize)) , Brushes.Red);
      }

      What is want to achieve here is to have the variables set to the exact Closing price and RSX oscillator value when the event occurs so I can later compare these values to another event to find and plot divergences. However I suspect that the variable keeps being changed or not set at all.
      Am I right? If so how do I avoid this? I would like to have these variables to be static so that only certain events change them.

      Thanks in advance!

      Comment


        #4
        Hello Balage0922,

        The variable may or may not be set depending on if the condition becomes true, so that is correct. I wouldn't necessarily expect that to cause the error you posted, however, something down the line might be affected. The double variable has a default value of 0, so even if you don't set it the variable contains a value.

        Is the //set 1 example the set generating the error currently, or this specific code? Were you able to try commenting out portions of your logic to further isolate what is causing the error? Seeing the specific line/s of code that generates the error would be more helpful than observing the whole syntax for this question.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          I have commented out every variable and I still receive the error: "Indicator 'RSXDivergenceMarker': Error on calling 'OnBarUpdate' method on bar 2: Object reference not set to an instance of an object."

          The code I left in (Set1) should work like this.




          public class RSXDivergenceMarker : Indicator
          {
          //private bool DIVBear;
          //private double CloseSetBear;
          //private double RSXSetBear;
          //private bool DIV2Bear;
          //private double CloseD_Bear;
          //private double RSXD_Bear;
          //private bool DIVBull;
          //private double CloseSetBull;
          //private double RSXSetBull;
          //private bool DIV2Bull;
          //private double CloseD_Bull;
          //private double RSXD_Bull;

          private NinjaTrader.NinjaScript.Indicators.Jurik_Research. JRC_RSX JRC_RSX1;


          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"Uses RSX to mark momentum divergences on chart,";
          Name = "RSXDivergenceMarker";
          Calculate = Calculate.OnBarClose;
          IsOverlay = true;
          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;
          RSX_Length = 15;
          Over = 30;
          OverD = 30;
          OverD2 = 30;
          Under = -30;
          UnderD = -30;
          UnderD2 = -30;
          MarkerOffset = 5;
          MarkerOffsetD2 = 5;
          BarsLookback = 40;
          MarkerOffsetNegative = -5;
          MarkerOffsetNegativeD2 = -5;
          }
          else if (State == State.Configure)
          {
          }
          }

          protected override void OnBarUpdate()
          {

          if (BarsInProgress != 0)
          return;

          if (CurrentBars[0] < 2)
          return;


          // Set 1
          if ((JRC_RSX1[2] < JRC_RSX1[1])
          && (JRC_RSX1[1] > JRC_RSX1[0])
          && (JRC_RSX1[0] > Over))

          {
          //DIVBear = true;
          //CloseSetBear = Close[0];
          //RSXSetBear = JRC_RSX1[0];
          Draw.ArrowDown(this, @"RSXDivergence Arrow down_1"+CurrentBar, true, 0, (High[0] + (MarkerOffset * TickSize)) , Brushes.Red);
          }

          // Set 2
          // if ((JRC_RSX1[2] < JRC_RSX1[1])
          // && (JRC_RSX1[1] > JRC_RSX1[0])
          // && (JRC_RSX1[0] > OverD)
          // && (DIVBear == true)
          // && (Close[0] > CloseSetBear)
          // && (JRC_RSX1[0] < RSXSetBear))
          // {
          // CloseD_Bear = Close[0];
          // RSXD_Bear = JRC_RSX1[0];
          // Draw.Diamond(this, @"RSXDivergence Diamond_1"+CurrentBar, true, 0, (High[0] + (MarkerOffset * TickSize)) , Brushes.Red);
          // DIV2Bear = true;
          // Alert(@"RSXDivergence_1", Priority.Medium, @"Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.GreenYellow, Brushes.Black);
          //}

          // Set 3
          // if ((JRC_RSX1[2] < JRC_RSX1[1])
          // && (JRC_RSX1[1] > JRC_RSX1[0])
          // && (JRC_RSX1[0] > OverD2)
          // && (DIV2Bear == true)
          // && (Close[0] > CloseD_Bear)
          // && (JRC_RSX1[0] < RSXD_Bear))
          // {
          // Draw.Diamond(this, @"RSXDivergence Diamond_1"+CurrentBar, true, 0, (High[0] + (MarkerOffsetD2 * TickSize)) , Brushes.Gold);
          // Alert(@"RSXDivergence_1", Priority.High, @"Double Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.Red, Brushes.Black);
          // Draw.Diamond(this, @"RSXDivergence Diamond_1"+CurrentBar, true, 0, (High[0] + (MarkerOffset * TickSize)) , Brushes.Red);
          // }

          // Set 4
          // if ((JRC_RSX1[2] > JRC_RSX1[1])
          // && (JRC_RSX1[1] < JRC_RSX1[0])
          // && (JRC_RSX1[0] < Under))
          // {
          // DIVBull = true;
          // CloseSetBull = Close[0];
          // RSXSetBull = JRC_RSX1[0];
          // Draw.ArrowUp(this, @"RSXDivergence Arrow up_1"+CurrentBar, true, 0, (Low[0] + (MarkerOffsetNegative * TickSize)) , Brushes.Lime);
          // }

          // Set 5
          // if ((JRC_RSX1[2] > JRC_RSX1[1])
          // && (JRC_RSX1[1] < JRC_RSX1[0])
          // && (JRC_RSX1[0] < UnderD)
          // && (DIVBull == true)
          // && (Close[0] < CloseSetBull)
          // && (JRC_RSX1[0] > RSXSetBull))
          // {
          //DIV2Bull = true;
          //CloseD_Bull = Close[0];
          //RSXD_Bull = JRC_RSX1[0];
          //Draw.Diamond(this, @"RSXDivergence Diamond_4"+CurrentBar, false, 0, (Low[0] + (MarkerOffsetNegative * TickSize)) , Brushes.Lime);
          //Alert(@"RSXDivergence_1", Priority.Medium, @"Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.GreenYellow, Brushes.Black);
          //}

          // Set 6
          //if ((JRC_RSX1[2] > JRC_RSX1[1])
          // && (JRC_RSX1[1] < JRC_RSX1[0])
          // && (JRC_RSX1[0] < UnderD2)
          // && (DIV2Bull == true)
          // && (Close[0] < CloseD_Bull)
          // && (JRC_RSX1[0] > RSXD_Bull))
          //{
          //Draw.Diamond(this, @"RSXDivergence Diamond_4"+CurrentBar, false, 0, (Low[0] + (MarkerOffsetNegative * TickSize)) , Brushes.Lime);
          //Draw.Diamond(this, @"RSXDivergence Diamond_4"+CurrentBar, false, 0, (Low[0] + (MarkerOffsetNegativeD2 * TickSize)) , Brushes.Gold);
          //Alert(@"RSXDivergence_1", Priority.High, @"Double Divergence", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.Red, Brushes.Black);
          //}
          }

          #region Properties
          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="RSX_Length", Order=1, GroupName="Parameters")]
          public int RSX_Length
          { get; set; }

          [NinjaScriptProperty]
          [Range(-1000, int.MaxValue)]
          [Display(Name="Over", Order=2, GroupName="Parameters")]
          public int Over
          { get; set; }

          [NinjaScriptProperty]
          [Range(-1000, int.MaxValue)]
          [Display(Name="OverD", Order=3, GroupName="Parameters")]
          public int OverD
          { get; set; }

          [NinjaScriptProperty]
          [Range(-1000, int.MaxValue)]
          [Display(Name="OverD2", Order=4, GroupName="Parameters")]
          public int OverD2
          { get; set; }

          [NinjaScriptProperty]
          [Range(-1000, int.MaxValue)]
          [Display(Name="Under", Order=5, GroupName="Parameters")]
          public int Under
          { get; set; }

          [NinjaScriptProperty]
          [Range(-1000, int.MaxValue)]
          [Display(Name="UnderD", Order=6, GroupName="Parameters")]
          public int UnderD
          { get; set; }

          [NinjaScriptProperty]
          [Range(-1000, int.MaxValue)]
          [Display(Name="UnderD2", Order=7, GroupName="Parameters")]
          public int UnderD2
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="MarkerOffset", Order=8, GroupName="Parameters")]
          public int MarkerOffset
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="MarkerOffsetD2", Order=9, GroupName="Parameters")]
          public int MarkerOffsetD2
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="BarsLookback", Order=10, GroupName="Parameters")]
          public int BarsLookback
          { get; set; }

          [NinjaScriptProperty]
          [Range(-1000, int.MaxValue)]
          [Display(Name="MarkerOffsetNegative", Order=11, GroupName="Parameters")]
          public int MarkerOffsetNegative
          { get; set; }

          [NinjaScriptProperty]
          [Range(-1000, int.MaxValue)]
          [Display(Name="MarkerOffsetNegativeD2", Order=12, GroupName="Parameters")]
          public int MarkerOffsetNegativeD2
          { get; set; }
          #endregion

          Comment


            #6
            Hello Balage0922,

            Thank you for your reply.

            Looking over the code again it looks like you never initialize the indicators you use:

            private NinjaTrader.NinjaScript.Indicators.Jurik_Research. JRC_RSX JRC_RSX1;

            You have used these in OnBarUpdate, but never assign an indicator to the variable. You would need to create the indicator in State.DataLoaded and assign it to the variable.

            I do not have the Jurik indicators imported so that I could provide the syntax for this, you would need to do something similar to the following:


            Code:
            private SMA mySma;
            
            protected override void OnStateChange()
            {
                else if (State == State.DataLoaded)
                {
                     mySma = SMA(12);
                }
            }

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Ahh, thanks a lot!!! Now the error message is gone. Functions are not perfect yet but hopefully I can manage hits.
              Thanks again!
              B.

              Comment


                #8
                Hi Jesse,
                I have a similar problem but his time the error message points to the OnStateChange method. This is a different indicator but the error appears to be similar, yet I cant figure out why.
                I am trying to create a variable of an indicator value (CFB) that I am using as an input for another (RSX). I receive the "Object reference not set to an instance of an object" error message, until I ad a default variable to OnStateChange(). In this case however the indicator does not calculate the variable dynamically and uses only the default setting. What do I have to do differently?


                public class DynaRSXMarker : Indicator
                {
                private double CFB_Variable;

                private NinjaTrader.NinjaScript.Indicators.Jurik_Research. JRC_CFB JRC_CFB1;
                private NinjaTrader.NinjaScript.Indicators.Jurik_Research. JRC_RSX JRC_RSX1;


                protected override void OnStateChange()
                {
                if (State == State.SetDefaults)
                {
                Description = @"";
                Name = "DynaRSXMarker";
                Calculate = Calculate.OnBarClose;
                IsOverlay = true;
                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;
                CFB_Period = 8;
                Over = 30;
                Under = -30;
                LowerLimit = 6;
                CFB_Variable = 6;


                }
                else if (State == State.Configure)
                {

                }
                else if (State == State.DataLoaded)
                {
                JRC_CFB1 = JRC_CFB(Close, Convert.ToInt32(CFB_Period), 48, 24);
                JRC_RSX1 = JRC_RSX(Close, CFB_Variable, 30, -30);
                }
                }

                protected override void OnBarUpdate()
                {
                if (BarsInProgress != 0)
                return;

                if (CurrentBars[0] < 2)
                return;

                // Set 1
                if (JRC_CFB1[0] <= LowerLimit)
                {
                CFB_Variable = LowerLimit;
                }

                else
                {
                CFB_Variable = JRC_CFB1[0];
                }

                // Set 3
                if ((JRC_RSX1[2] < JRC_RSX1[1])
                && (JRC_RSX1[1] > JRC_RSX1[0])
                && (JRC_RSX1[0] > Over))
                {
                Draw.ArrowDown(this, @"DynamicRSXMarker Arrow down_1"+CurrentBar, false, 0, (High[0] + (5 * TickSize)) , Brushes.Red);
                Alert(@"DynamicRSXMarker_1", Priority.Medium, @"DynRSX_Sell", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.Transparent, Brushes.OrangeRed);
                }

                // Set 4
                if ((JRC_RSX1[2] > JRC_RSX1[1])
                && (JRC_RSX1[1] < JRC_RSX1[0])
                && (JRC_RSX1[0] < Over))
                {
                Draw.ArrowUp(this, @"DynamicRSXMarker Arrow up_1"+CurrentBar, false, 0, (Low[0] + (-5 * TickSize)) , Brushes.Lime);
                Alert(@"DynamicRSXMarker_1", Priority.Medium, @"DynRSX_Buy", @"C:\Program Files (x86)\ATAS\sounds\B9.wav", 5, Brushes.Transparent, Brushes.Lime);
                }
                }

                Comment


                  #9
                  Hello Balage0922,

                  From the description it is not clear what you were doing that was causing the error and what the change was that you made, could you highlight the specific line you changed to avoid the error?

                  Object reference not set to an instance of an object means that something was null while it was being used, this was potentially the order you had defined the items.

                  I look forward to being of further assistance.


                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hi Jesse,
                    I added the line
                    • CFB_Variable = 6; to State == State.SetDefaults
                    Before that, the errormesage pointed to "RSX_len" being 0 which is the indicator length that I am trying to define with the "CFB_Variable".
                    What is not clear to me why this variable is not being calculated as per Set 1.

                    Thanks in advance!

                    Comment


                      #11
                      Hello Balage0922,

                      Thank you for your post.

                      To clarify, you first had seen an error relating to the value of RSX_len being 0, was that something similar to the value cannot be used because it is not within the minimum or maximum?

                      If the overall problem is related to passing the series/parameters to one of the indicators, or to make it dynamic you could move the indicator assignment from State.DataLoaded into OnBarUpdate.

                      The following two lines would just move to the beginning of OnBarUpdate:

                      Code:
                      protected override void OnBarUpdate()
                      {
                      if (BarsInProgress != 0) 
                      return;
                      
                      if (CurrentBars[0] < 2)
                      return;
                      ​​​​​​​
                          JRC_CFB1 = JRC_CFB(Close, Convert.ToInt32(CFB_Period), 48, 24);
                          JRC_RSX1 = JRC_RSX(Close, CFB_Variable, 30, -30);
                      }
                      I look forward to being of further assistance.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Great! Yes it makes sense now.... since the CFB value has to be calculated on each bar, the logic has to be under onbarupdate.
                        Thanks a lot Jesse, have a good day!
                        B.

                        Comment


                          #13
                          Originally posted by Balage0922 View Post
                          if (State == State.SetDefaults)
                          {
                          Description = @"Uses RSX to mark momentum divergences on chart,";
                          Name = "RSXDivergenceMarker";
                          Calculate = Calculate.OnBarClose;
                          IsOverlay = true;
                          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;
                          RSX_Length = 15;
                          Over = 30;
                          OverD = 30;
                          OverD2 = 30;
                          Under = -30;
                          UnderD = -30;
                          UnderD2 = -30;
                          MarkerOffset = 5;
                          MarkerOffsetD2 = 5;
                          BarsLookback = 40;
                          MarkerOffsetNegative = -5;
                          MarkerOffsetNegativeD2 = -5;
                          Hello Balage0922,
                          thank you for your posts showing your two scripts. The first one of which I am trying to replicate. The second one I don't quite understand what it is doing.
                          In the first one it appears that your oscillator ranges between -50 +50, (Overs = +30 and Unders = - 30). Is it correct? Do you always use the same levels 30 and -30 for all three Overs and three Unders.


                          Earlier on I tried to find divergences with indicator divergenceinputseries NT8 (posted on the indicator sharing section) but if I select RSI as its input series, it does not show anything on the chart. Did you perhaps tried it and have the same issue with divergenceinputserires NT8?
                          Thank you.
                          Last edited by guidoisot; 06-25-2019, 11:18 AM.

                          Comment


                            #14
                            Hi guidoisot,
                            Sorry for my late reply, I just saw your post. The oscillator I am using is from Jurik Research, most of the time it oscillates between -100 and +100 but it is not restricted.
                            I am using certain indicator levels (I think you are referring to these) that reset the divergence variables if crossed. For example if RSX crossed below -30, then the variables that store divergence price/indicator values are being reset and only momentum reversals will be drawn, no bearish divergence markers will be drawn.
                            Best regards,

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by helpwanted, Today, 03:06 AM
                            1 response
                            8 views
                            0 likes
                            Last Post sarafuenonly123  
                            Started by Brevo, Today, 01:45 AM
                            0 responses
                            7 views
                            0 likes
                            Last Post Brevo
                            by Brevo
                             
                            Started by aussugardefender, Today, 01:07 AM
                            0 responses
                            5 views
                            0 likes
                            Last Post aussugardefender  
                            Started by pvincent, 06-23-2022, 12:53 PM
                            14 responses
                            242 views
                            0 likes
                            Last Post Nyman
                            by Nyman
                             
                            Started by TraderG23, 12-08-2023, 07:56 AM
                            9 responses
                            385 views
                            1 like
                            Last Post Gavini
                            by Gavini
                             
                            Working...
                            X