• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 afoschini, Today, 09:21 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by Leope, Today, 09:37 AM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_RyanS  
    Started by svadukia, Today, 04:38 AM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_PatrickH  
    Started by dmackay41, Today, 12:50 AM
    3 responses
    23 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by ahrt|, Today, 08:37 AM
    2 responses
    10 views
    0 likes
    Last Post ahrt|
    by ahrt|
     
    Working...
    X