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

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 Gerik, Today, 09:40 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by RookieTrader, Today, 09:37 AM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by alifarahani, Today, 09:40 AM
            0 responses
            5 views
            0 likes
            Last Post alifarahani  
            Started by KennyK, 05-29-2017, 02:02 AM
            3 responses
            1,285 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by AttiM, 02-14-2024, 05:20 PM
            11 responses
            186 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X