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

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.
    JimNinjaTrader Customer Service

    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.
        JimNinjaTrader Customer Service

        Comment


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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by marcus2300, Yesterday, 10:21 AM
          6 responses
          19 views
          0 likes
          Last Post marcus2300  
          Started by skorpn, Today, 01:28 AM
          0 responses
          8 views
          0 likes
          Last Post skorpn
          by skorpn
           
          Started by ETFVoyageur, Today, 12:52 AM
          0 responses
          6 views
          0 likes
          Last Post ETFVoyageur  
          Started by Board game geek, Yesterday, 02:20 AM
          2 responses
          22 views
          0 likes
          Last Post Board game geek  
          Started by jackiegils, Yesterday, 11:05 PM
          0 responses
          7 views
          0 likes
          Last Post jackiegils  
          Working...
          X