Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dynamically changing an indicators parameter

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

    Dynamically changing an indicators parameter

    Dear team,

    I'd like to change the parameter of an indicator from within another indicator's OnBarUpdate(),
    e.g. change the period of the SMA indicator by Ninjascript, determined by some logic of my current indicator, at the completion of each bar,

    What would be the recommended approach ?

    Thank you for your support throughout the year.
    Louis

    #2
    Hello Louis365,

    Thanks for your post.

    You could call the indicator dynamically in OnBarUpdate, modifying the indicator parameters as needed. For example, your hosting script can calculate a value for the Period needed for SMA, and then the hosting script can call the SMA with SMA(YourPeriodVariable)[0] in OnBarUpdate.

    Code:
            protected override void OnBarUpdate()
            {
                int YourPeriodVariable = (CurrentBar % 2 + 1) * 10; // Some value calculated in hosting script
                Print(SMA(YourPeriodVariable)[0]);
            }
    SMA syntax - https://ninjatrader.com/support/help...simple_sma.htm

    Please let me know if I can be of further assistance.

    Comment


      #3
      Thank you Jim.
      Supposed I wanted to change the period of the SMA that has already been called as an indicator to a bar type on a chart; would it be possible to modify the period of the existing instance of that visible SMA indicator by NinjaScript rather than though the UI ?

      Comment


        #4
        Hello Louis365,

        This would not be supported. While it may be possible to search for the indicator in the ChartControl.Indicators collection, it would not be supported to assign a new parameter programmatically.

        You could consider having your parent indicator add a plot for what would be displayed by a child indicator, and then assign the parent's plot value to the output calculated from the called child indicator.

        Code:
        protected override void OnBarUpdate()
        {
            int YourPeriodVariable = (CurrentBar % 2 + 1) * 10; // Some value calculated in hosting script            
            Values[0][0] = SMA(YourPeriodVariable)[0]; // Values[0][0] would need to reflect the plot added in this (parent) indicator    
        }
        I look forward to being of any further assistance.
        Last edited by NinjaTrader_Jim; 12-30-2019, 03:35 PM.

        Comment


          #5
          Thanks for the clarification, Jim.
          Best, Louis

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          672 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          379 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          111 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          577 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          582 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X