Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Normalizing of Ninja Trader Indicators

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

    Normalizing of Ninja Trader Indicators

    Hello,
    I am currently trying to Normalize the Linear Regression Intercept Indicator. I have created a custom Indicator and used the Script Editor however, I keep getting a blank Plot. Any help would be appreciated. I am trying to get it to plot "NormLinRegINtercept". Thank you.

    protected override void OnBarUpdate()
    {
    double ba = LinRegIntercept(20)[0];
    double bb = MIN(LinRegIntercept(20),256)[0];
    double bc = MAX(LinRegIntercept(20),256)[0];
    var bd = bc-bb;
    double NormLinRegIntercept = (ba-bb)/bd;
    NormLinRegIntercept = new Series<double>(NormLinRegIntercept);
    }

    #2
    These lines of code are confusing and should not compile.

    Code:
    // you are assigning a value to a double.  Its also a local variable so it will definitely not show up in a plot.
    double NormLinRegIntercept = (ba-bb)/bd;  
    
    // now you are reassigning it a new type. I am surprised this compiles.  If it does it might mean that you
    // also have a property or member variable of type Series<double>.  You are creating a new series with
    // every bar update with this line.  This series doesn't accept  a double as a parameter so both
    // NormLinRegIntercept must be referring to some other property or member variable outside the scope
    // of OnBarUpdate that is of type Series<double>
    NormLinRegIntercept = new Series<double>(NormLinRegIntercept);
    In the configure state of OnStateChange() you need to call AddPlot, if a call isn't already there. Its common pattern to then have a property for the indicator as follows

    Code:
    [Browsable(false)] // Makes sure it doens't show up in the properties window
    [XmlIngore] // Makes sure it doesn't get saved
    public Series<double> NormLinRegIntercept
    {
        get { return Values[0]; }
    }
    This code may already exist in your class if you generated it from the editor in NinjaTrader.

    Finally your code should look like this

    Code:
    protected override void OnBarUpdate()
    {
        var ba = LinRegIntercept(20)[0];
        var bb = MIN(LinRegIntercept(20),256)[0];
        var bc = MAX(LinRegIntercept(20),256)[0];
    
        var denominator = bc - bb;
        if(denominator != 0)
        {
            NormLinRegIntercept[0] = (ba - bb)/denominator;
        }
        else
        {
             // best value (or no value) for when its 0
        }
    }
    Last edited by ntbone; 05-16-2022, 05:03 PM.

    Comment


      #3
      Originally posted by ntbone View Post

      Finally your code should look like this

      Code:
      protected override void OnBarUpdate()
      {
      double ba = LinRegIntercept(20)[0];
      double bb = MIN(LinRegIntercept(20),256)[0];
      double bc = MAX(LinRegIntercept(20),256)[0];
      NormLinRegIntercept[0] = (ba - bb)/bd;
      }
      I assume you mean:

      protected override void OnBarUpdate()
      {
      double ba = LinRegIntercept(20)[0];
      double bb = MIN(LinRegIntercept(20),256)[0];
      double bc = MAX(LinRegIntercept(20),256)[0];
      double bd = bc-bb;
      NormLinRegIntercept[0] = (ba - bb)/bd;
      }

      or omit the red line and instead:

      NormLinRegIntercept[0] = (ba - bb)/(bc-bb);
      eDanny
      NinjaTrader Ecosystem Vendor - Integrity Traders

      Comment


        #4
        Oops. Yes, I revised my post due to missing the line.
        Last edited by ntbone; 05-16-2022, 05:04 PM.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        24 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        20 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        14 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        11 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        41 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X