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

are variables created in separate instance for each indicator

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

    are variables created in separate instance for each indicator

    I am not C# guy too much, and have a simple question. lets say, i have Addon (of my methods), where in is:


    private static int LastBarNum;
    public static bool Check(int currentBar){
    bool IsNew = LastBarNum != currentBar; LastBarNum = currentBar; return IsNew;
    }


    so, if i use this addon in first indicator (which is attached to chart) and it gets/sets (according my coded logic) and I attach second instance of indicator on the chart, will the second instance and first instance of indicators will interfere with each other (re-writing the same variable from their own logic)?

    or they will open "my-addon" in their own separate instance, thus the variable will be dedicated to their instances?

    maybe i have expressed correctly what i meant..
    Last edited by ttodua; 09-18-2017, 01:56 AM.

    #2
    Hello selnomeria,

    When we add indicators to strategies and other indicators we can either reference the indicator through a method that does the calculation for that instance, or we create a new instance of that indicator. This new instance assures that the calling NinjaScript will get a unique value.

    AddOns get created along side the platform and are not unique to each calling NinjaScript. When you use static variables within this space, it will be shared between any calling NinjaScript.

    If you have any additional questions, please don't hesitate to ask.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello selnomeria,
      ...
      How can I achieve to create a new instance of addon for each indicator ?


      SMTH_TYPE myaddon = new SMTH_TYPE()

      or ?
      cant you give any hints how to achieve what i wanted?
      thanks so much.

      Comment


        #4
        Hello selnomeria,

        Adding instances of an AddOn to an indicator or strategy escapes the intended design for NinjaScripts. Due to the aforementioned complications of sharing methods and variables between multiple NinjaScripts which write to the same space, we do not advise to use AddOn's for this purpose.

        If you want to have some variable unique to an indicator, we advise to create that variable within that specific indicator.

        You are welcome to experiment using any C# technique you wish while writing NinjaScripts, however the level of support that we may provide will be limited to the intended use of NinjaScripts.

        If there is anything I can do to provide further assistance, please let me know.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NRITV, Today, 01:15 PM
        2 responses
        8 views
        0 likes
        Last Post NRITV
        by NRITV
         
        Started by frankthearm, Today, 09:08 AM
        7 responses
        31 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by maybeimnotrader, Yesterday, 05:46 PM
        5 responses
        26 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by quantismo, Yesterday, 05:13 PM
        2 responses
        19 views
        0 likes
        Last Post quantismo  
        Started by adeelshahzad, Today, 03:54 AM
        5 responses
        33 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X