Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with User Defined input

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

    Help with User Defined input

    I am trying to be able to select a value for volume in a stragety I am working on. I want to have the background color when volume on the bar exceedes a user definable amount. This script works great but I can not get a user defined value for volume. I have reviewed the help links about user defined input and tried everything I can think of as a can not figure it out. Please tell me what variable will work.

    /// <summary>
    /// Colors the background whenever Volume is greater that 5000 on bar
    /// </summary>
    [Description("Colors the background whenever Volume is greater that 5000 on bar")]
    public class VolumeColor : Strategy
    {
    #region Variables
    // Wizard generated variables
    // User defined variables (add any user defined variables below)
    #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()
    {
    // Condition set 1
    if (Volume[0] > 5000)
    {
    BackColorAll = Color.LemonChiffon;
    }
    }

    #region Properties
    #endregion
    }
    }

    #2
    Hi GaryF,

    Thank you for your post and welcome to the forums!

    You will need to declare the variable and then create a property for the variable.
    Below is a reference sample that outlines exactly how to code this.

    http://www.ninjatrader.com/support/f...ead.php?t=5782

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I reviewed that link and still must be doing something wrong. I get the error message Cannot apply indexing with [] to an expression to type " int" . This is what I tried

      /// <summary>
      /// Volume background with variables.
      /// </summary>
      [Description("Volume background with variables.")]
      public class AAAAE : Strategy
      {
      #region Variables
      // Wizard generated variables
      private int volume = 5000; // Default setting for Volume
      // User defined variables (add any user defined variables below)
      #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()
      {
      // Condition set 1
      if (Volume[0] > 5000)
      {
      BackColor = Color.LemonChiffon;
      }
      }

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

      Comment


        #4
        GaryF,

        Volume is already a reserved name for NinjaScript. I recommend that you rename the variable to something such as myVolume.

        You will then test this in the IF statement as -
        Code:
        if(Volume[0] > myVolume)
        {
        //Do something here
        }
        This tests the current Volume against your user defined input value.

        Let me know if I can be of further assistance.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Million Thanks

          I greatly appreciate the execellent service you and the support team provide.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          648 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X