Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Global Variables

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

    Global Variables

    I am using public partial class GlobalVariable : Indicator
    to exchange data between indicators and charts.

    All methods from that GlobalVariable indicator are static and I am using the IObserver pattern.


    Here is my code structure :

    Indicator 1 sends data to GlobalVariable :

    Code:
    ChartControl.Dispatcher.InvokeAsync((Action)(() =>
    {
     NinjaTrader.NinjaScript.Indicator.GlobalVariable.SetData(xxx);
    
    }));
    Indicator 2 receives data from GlobalVariable :

    Code:
    public void GetData(xxx)
    That method is part of IObserver interface I have created.

    Multiple markets and indicators use these class at the same time.

    It works fine. Is this code structure makes sense or could be problematic.

    On a few PC I get the following error : Attempted to read or write protected memory.
    I have no way to know if it could come from that Global Variable pattern or from other code

    #2
    Hello blar58,

    Making an indicator that extends the indicator class is not supported by NinjaTrader Support to do.

    This thread will remain open for any community members that would like to assist.

    I do, however, have an example of sharing data between scripts using a custom static class in a custom namespace.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      hi, i am writing partly because i can't understand what's been said. i believe i have a simple version of this problem: i have a variable (Period) that i wish to use in several indicators and when i change the variable in one place it changes in all the indicators. what is the proper way to do that? thanx david

      Comment


        #4
        Chelsea,
        I have a Question about using this for NT7. Would your code currently in file MySharedAddon (NT8vers) be placed in an NT7 File Called UserDefinedMethods.cs in the Indicator directory and the indicator and Strategy code just be downgraded to NT7 from the NT8 versions you posted.

        thanks

        Comment


          #5
          The OP code does not extend the Indicator class. It extends a class, (or creates a new class), that inherits from Indicator, just like all other indicators.
          Last edited by koganam; 06-24-2017, 12:27 PM.

          Comment


            #6
            Originally posted by daij1944 View Post
            hi, i am writing partly because i can't understand what's been said. i believe i have a simple version of this problem: i have a variable (Period) that i wish to use in several indicators and when i change the variable in one place it changes in all the indicators. what is the proper way to do that? thanx david
            Use a static variable in a static class. Refer to the Microsoft c# documentation on the matter.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            368 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            571 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X