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

cant change public properties from external

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

    cant change public properties from external

    i.e. in indi_Ai have:


    [NinjaScriptProperty]
    [Category(.........
    public int EmaPeriod { get; set; }


    Initialize(){
    EmaPeriod = 11;
    ...
    }


    if i call indi_A from strategy initialization like this:


    Initialize(){
    Add ( indi_A(16) );
    }


    when printing the value from Indicator, it still prints 11.

    So, i think, the initialize method in Indicator, sets the value that is not modified in strategy.
    How can i solve that?

    I know that if i use private fields for backing the property, that will solve, like:

    public int EmaPeriod { get {return MYperiod;} set {MYperiod = value;} }
    private int MYperiod = 11;


    however, without backing-field, is that possible?

    #2
    Hello TazoTodua,

    Thanks for opening the thread.

    As noted in the SampleBoolSeries example, it is advised to call Update() within the getter and setter of your exposed variable to ensure that it gets up to date. Since this cannot be done with an auto property, it would be advised to use a backing field.

    For further referencefor other readers, I would like to link your previous thread's with my colleague Jesse on backing fields.

    You may set up a test similar to the own I have attached. Setting or getting BackingFieldUpdate will call Update(), if this is set last in sequence to the other variables, Update() will cause all of those values to be up to date. If line 44 is commented, Update() will not be called, and the exposed variables will not be up-to-date.

    Code:
    Print(CurrentBar %2);
    Indi.AutoProperty = CurrentBar % 2;
    Indi.BackingField = CurrentBar % 2;
    //Indi.BackingFieldUpdate = CurrentBar % 2;
    SampleBoolSeries - https://ninjatrader.com/support/help...alues_that.htm

    Previous thread on backing fields - https://ninjatrader.com/support/foru...d.php?t=108649

    Please let us know if you have any questions.
    Attached Files
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cls71, Today, 04:45 AM
    0 responses
    1 view
    0 likes
    Last Post cls71
    by cls71
     
    Started by mjairg, 07-20-2023, 11:57 PM
    3 responses
    213 views
    1 like
    Last Post PaulMohn  
    Started by TheWhiteDragon, 01-21-2019, 12:44 PM
    4 responses
    544 views
    0 likes
    Last Post PaulMohn  
    Started by GLFX005, Today, 03:23 AM
    0 responses
    3 views
    0 likes
    Last Post GLFX005
    by GLFX005
     
    Started by XXtrader, Yesterday, 11:30 PM
    2 responses
    12 views
    0 likes
    Last Post XXtrader  
    Working...
    X