Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Modify input when starting an indicator

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

    Modify input when starting an indicator

    I have an input to an indicator, lets call it Length, that I'd like to modify depending on what the chart period is.

    But I'd also like to allow the user to set it manually if they don't want to use the default. So if they enter 0 in the Length input, it will auto calc. If they put 500, it will make Length 500.

    I can do the check in OnBarUpdate, but only need to do it if they change it so that seems like a lot of unnecessary work.

    Where can I put something like this so that it will only calculate once, but wont change the user input?

    HTML Code:
    if ( Length == 0)   Length = 1000 / BarsPeriod.Value;​
    I've tried a couple places in OnStateChange, but can't seem to get it to work

    thanks

    #2
    Hello cre8able,

    Use a private variable to store the calculated value.

    Check and assign the value in OnStateChange() when State is State.DataLoaded.

    private double useLength;

    In OnStateChange():

    else if (State == State.DataLoaded)
    {
    useLength = Length == 0 ? 1000 / BarsPeriod.Value : Length;
    }

    In OnBarUpdate():

    Print(useLength);



    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    647 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