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 funk10101, Today, 09:43 PM
            0 responses
            0 views
            0 likes
            Last Post funk10101  
            Started by pkefal, 04-11-2024, 07:39 AM
            11 responses
            36 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Yesterday, 08:51 AM
            8 responses
            44 views
            0 likes
            Last Post bill2023  
            Started by yertle, Today, 08:38 AM
            6 responses
            25 views
            0 likes
            Last Post ryjoga
            by ryjoga
             
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            24 views
            0 likes
            Last Post algospoke  
            Working...
            X