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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    52 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    71 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    38 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    99 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    60 views
    0 likes
    Last Post PaulMohn  
    Working...
    X