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

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        44 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        20 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        179 views
        0 likes
        Last Post jeronymite  
        Started by ghoul, Today, 06:02 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Working...
        X