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

Best way to use indicator outside OnBar

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

    Best way to use indicator outside OnBar

    If I want to encapsulate a built in indicator like ATR(20)[0] outside OnBarUpdate so that other methods can have access to it what should I do?

    Assigning it to a variable:

    double ATR20 = ATR(20)[0];

    gives me this error:

    'object reference is required for the nonstatic field, method or property Ninjatrader.Strategy.StrategyATR(int)'

    Thanks as always for your help.

    #2
    Hello,

    That line of code is fine. How are you using the variable ATR20? Please post the code.
    DenNinjaTrader Customer Service

    Comment


      #3
      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
      /// <summary>
      /// Enter the description of your strategy here
      /// </summary>
      [Description("Enter the description of your strategy here")]
      public class ATRTEST : Strategy
      {
      #region Variables
      // Wizard generated variables
      private int myInput0 = 1; // Default setting for MyInput0
      // User defined variables (add any user defined variables below)

      double ATRtest = ATR(20)[0];

      #endregion

      /// <summary>
      /// This method is used to configure the strategy and is called once before any strategy method is called.
      /// </summary>
      protected override void Initialize()
      {
      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      }

      #region Properties
      [Description("")]
      [Category("Parameters")]
      public int MyInput0
      {
      get { return myInput0; }
      set { myInput0 = Math.Max(1, value); }
      }
      #endregion
      }
      }

      Comment


        #4
        Hello,

        I looked at your code really quickly and found one issue right away: you need to put that line of code in question in the OnBarUpdate code block so it is called and updated each time an bar event happens.
        DenNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by inanazsocial, Today, 01:15 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by rocketman7, Today, 02:12 AM
        0 responses
        10 views
        0 likes
        Last Post rocketman7  
        Started by dustydbayer, Today, 01:59 AM
        0 responses
        1 view
        0 likes
        Last Post dustydbayer  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        23 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Working...
        X