Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling a variable from another indicator

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

    Calling a variable from another indicator

    Hi,


    Is it possible to declare a variable which can be accessed from another indicator ?
    Lets say I have int movingAvgPeriod =5;

    I'd like this variable to be accessed from another indicator.
    I thought that I could simply declare it like this:

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public int movingAvgPeriod =5;
    However, I cant called on int movingAvgPeriod =5; from another indicator.
    Any ideas on this one ?

    Thanks
    AK

    #2
    Hello,

    You could declare a Static class in an Addon which could then be accessed by indicators.

    There is a sample of using a static class in the following post: http://ninjatrader.com/support/forum...24&postcount=3

    I would also suggest reading about the static subject from MSDN to fully understand this topic.

    I look forward to being of further assistance.

    Comment


      #3
      Thanks Jesse,

      Can you kindly explain what this TestShareData script demonstrates ?
      I see it outputs 100 for every bar, but I dont understand how it illustrates how 2 indicator scripts can share a set of variables; i also dont see a reference to 'static' in the test script; I see this :

      Code:
      protected override void OnBarUpdate()
      		{
      			NinjaTrader.NinjaScript.AddOns.SharedData.TestDouble = 100;
      			Print(NinjaTrader.NinjaScript.AddOns.SharedData.TestDouble);
      		}
      I have a script called IndicatorA;
      it has a set of variables:
      movingAvg 60 (or instance)

      I'd like to called movingAvg from another script; IndicatorB

      Comment


        #4
        Hello,

        The sample contains 3 scripts, you would need to view all 3 to understand this sample. Also, you should review the Static MSDN link in the prior post to really understand C# wise what static means and is for.

        In this sample, the Indicator sets a variable and then also Prints that variable.

        The Strategy also Prints the same variable which the indicator sets.

        The Addon is where the variable is defined which both the strategy and indicator can access. There is nothing more to the sample other than the Syntax which you can view, you are accessing a variable from the Addon which contains a static class. Both the strategy and indicator access this variable. You could have two indicators that do this instead of a strategy and indicator.

        Please let me know if I may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        597 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        343 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        556 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        555 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X