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 LawrenHom, Today, 10:45 PM
    0 responses
    3 views
    0 likes
    Last Post LawrenHom  
    Started by love2code2trade, Yesterday, 01:45 PM
    4 responses
    28 views
    0 likes
    Last Post love2code2trade  
    Started by funk10101, Today, 09:43 PM
    0 responses
    7 views
    0 likes
    Last Post funk10101  
    Started by pkefal, 04-11-2024, 07:39 AM
    11 responses
    37 views
    0 likes
    Last Post jeronymite  
    Started by bill2023, Yesterday, 08:51 AM
    8 responses
    44 views
    0 likes
    Last Post bill2023  
    Working...
    X