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

Chart Variable

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

    Chart Variable

    Is there way to have a variable that can be accessed/shared among the indicators on a chart?

    Scenario:
    I have several indicators where I specify a look back period. Currently this is set for each indicator. I was looking for a way to set the value in one place so all the indicators on that chart (not other charts) could access/read the variable/value.

    #2
    Originally posted by ct View Post
    Is there way to have a variable that can be accessed/shared among the indicators on a chart?

    Scenario:
    I have several indicators where I specify a look back period. Currently this is set for each indicator. I was looking for a way to set the value in one place so all the indicators on that chart (not other charts) could access/read the variable/value.
    That depends on what you mean, and your programming abilities.

    Here is one method that you might use:
    1. Create a (master) indicator that publicly exposes the period that you want to set.
      Make sure that you give this indicator a specific name, using this.Name = ... in the Initialize() section, so that you can search on this name.
    2. In your other indicators, cycle through the indicators list, and if the indicator is loaded, then read the variable and set the lookBack period from it, otherwise do nothing.
    3. Load the master indicator onto the chart, along with the other indicators.

    Comment


      #3
      Hello ct,

      Thank you for your post.

      Along with koganam's suggestion you could use a UserDefinedMethod to send the period from one indicator to be used in all indicators. However, there are foreseeable conflicts with multiple indicators trying to set the period and resulting in undesired results.

      UserDefinedMethods: http://www.ninjatrader.com/support/h...ed_methods.htm

      Comment


        #4
        Originally posted by NinjaTrader_PatrickH View Post
        Hello ct,

        Thank you for your post.

        Along with koganam's suggestion you could use a UserDefinedMethod to send the period from one indicator to be used in all indicators. However, there are foreseeable conflicts with multiple indicators trying to set the period and resulting in undesired results.

        UserDefinedMethods: http://www.ninjatrader.com/support/h...ed_methods.htm
        Not unless the variable is declared static, which of course brings along with it, inter alia, the concerns that you have already expressed. It is often best practice to avoid using static variables.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by usazencort, Today, 01:16 AM
        0 responses
        1 view
        0 likes
        Last Post usazencort  
        Started by kaywai, 09-01-2023, 08:44 PM
        5 responses
        603 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        6 responses
        22 views
        0 likes
        Last Post xiinteractive  
        Started by Pattontje, Yesterday, 02:10 PM
        2 responses
        20 views
        0 likes
        Last Post Pattontje  
        Started by flybuzz, 04-21-2024, 04:07 PM
        17 responses
        230 views
        0 likes
        Last Post TradingLoss  
        Working...
        X