Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Passing hidden values from one indicator to another

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

    Passing hidden values from one indicator to another

    Hello NT,

    I wish to pass a hidden variable from one indicator to another. I am drawing upon the examples given previously in forum, specifically:

    https://ninjatrader.com/support/forum/forum/ninjatrader-7/strategy-development-aa/1045072-retrieving-bool-series-values-created-in-an-indicator-into-a-strategy


    Attached I have a simple pair of indicators (source, sink). Unfortunately, I can't figure out what I am doing wrong. The sink only reads in null values, not what the source is sending.

    Please help!

    Thanks in advance


    Attached Files
    Last edited by pvtrader; 04-03-2022, 11:42 PM.

    #2
    Oops, dug further in the forum posts. If I declare the hidden values in the source as "static" then it works.

    addendum to Source:
    --------------------------------------------------
    private static int testhiddenvalue;
    --------------------------------------------------

    Could someone please explain why this is required and what specifically is going on ?

    Thanks in advance

    Comment


      #3
      Hello pvtrader,

      static is a feature of C#, you can read more about that feature on MSDN. https://docs.microsoft.com/en-us/dot...eywords/static

      Comment


        #4
        Hi Jesse,

        Was hoping for a more detailed answer, why it is necessary.

        Curious, it is not used in the NT example provided for SampleBoolSeries.

        Comment


          #5
          Hello pvtrader,

          Static is a feature of C# and is not specific to NinjaScript which is why that is not documented with NinjaScript. That is a more advanced part of C# and conflicts with how NinjaScript is used so we provide no specific information on that topic. You can research using that and how that works in C# if that works toward your goal but we generally suggest to avoid that in NinjaScript as it often leads to problems.

          Indicators aren't intended to share data in the way that you are trying, if you wanted to share data from indicator A to indicator B you would need to call indicator B from indicator A to complete the chain of how OnBarUpdate is called. That also makes sure they two scripts are in sync. If you use static to share data there is no sync and no expectation of when that value may be set.


          Comment


            #6
            Hi Jesse,

            Thank you for the reply. I get what you are saying, understood.

            But it is a little misleading when you guys provide an example (SampleBoolSeries) within your helpguide.

            P.S. You guys rock, luv your product

            Comment


              #7
              Hello pvtrader,

              Just to clear any confusion, the SampleBoolSeries shows how to make "public" properties which means that other scripts which have an instance to that script can read it. With static there is no instances involved which is why what you tried technically worked.

              The SampleBoolSeries specifically shows how to expose data from one script to another which is not a Plot. When you don't use a Plot and try to access that data from another script it won't be in sync, that sample shows how to use the Update() method to avoid that.

              If the purpose is to pass a variable from one script to anther the easiest way would be the SampleBoolSeries and its ExposedVariable property. The key is calling Update in the property:
              Code:
              public double ExposedVariable
              {
              // We need to call the Update() method to ensure our exposed variable is in up-to-date.
              get { [B]Update();[/B] return exposedVariable; }
              }
              After you have that in the indicator any other indicator or strategy can call tis indicator SampleBoolSeries().ExposedVaraible to get its value.

              Using that approach makes sure the indicators OnBarUpdate is run to calculate the value you are exposing.

              A simple example where static might be used in NinjaScript would be defining a static class in the addon folder which contains constant variables, then other scripts could read that class using its type which has pre defined variables in it.




              Comment


                #8
                Hi Jesse,

                I don't know how I missed the "Update()" which is critical to example given. So, there was nothing wrong with the example the guide provided. My Bad!

                Thanks again!
                Last edited by pvtrader; 04-05-2022, 09:49 AM.

                Comment


                  #9
                  I followed the SampleBoolSeries indicator to a T.
                  I copied everything perfect. Yet it still doesnt work.
                  Its not exposed. But its not a PLOT

                  Heck, the SampleBoolSeries indicator itself is not exposed and it has that update() in the property as Jesse described.
                  You cant even find the SampleBoolSeries indicator itself in strategy builder at all.
                  Can anyone help? Thanks



                  Code:
                    private Series<bool> bearIndication;
                    private Series<bool> bullIndication;
                  
                  
                    private double exposedVariable;
                  
                  In state.configure:
                     bearIndication = new Series<bool>(this);
                    bullIndication = new Series<bool>(this);
                  
                  On bar update:
                  For bullish:
                     bullIndication[0] = (true);
                    bearIndication[0] = (false);
                  
                  For Bearish:
                     bullIndication[0] = (false);
                    bearIndication[0] = (true);
                  
                  
                  For neutral:
                     bullIndication[0] = (false);
                    bearIndication[0] = (false);
                  
                  At the end of OnBarUpdate:
                      exposedVariable = Close[0];
                  
                  In Properties:
                  
                    // Creating public properties that access our internal Series<bool> allows external access to this indicator's Series<bool>
                    public Series<bool> BearIndication
                    {
                    get { return bearIndication; } // Allows our public BearIndication Series<bool> to access and expose our interal bearIndication Series<bool>
                    }
                  
                  
                    public Series<bool> BullIndication
                    { 
                    get { return bullIndication; } // Allows our public BullIndication Series<bool> to access and expose our interal bullIndication Series<bool>
                    }
                  
                    public double [B]ExposedVariable[/B]
                    {
                    // We need to call the Update() method to ensure our exposed variable is in up-to-date.
                  [B]   get { Update(); return exposedVariable; }[/B]
                    }

                  Comment


                    #10
                    If only Plots are 'exposed' for use in Strategy Builder.

                    If the Strategy builder can only work with a plot.
                    It will not work with an exposed double variable.

                    Then why is this SampleBoolSeries indicator available at all?
                    Isnt the indicator misinformation?

                    Why is there not a help file in the Help Guide (there is only one for "Exposing indicator values that are not plots" which references the SampleBoolSeries)
                    Can one be added on the correct way to do it? Thanks

                    Comment


                      #11
                      Hello ezrollin,

                      The Strategy Builder is limited.

                      That example applies to unlocked strategies only.

                      Not all examples work in the Strategy Builder as this is meant for extremely simple scripts. Anything even slightly advanced requires coding by hand.

                      Its not the approach, its the Strategy Builder. Unlock the script and code by hand.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Can there be a section of the Help Guide be dedicated to exposing a variable to the strategy builder? It would only take a few minutes.
                        Its so easy to expose on ThinkOrSwim and it has to be done soooo often for scans and stuff.

                        But on NT, I still havent figured it out and I've had a couple 3 page threads? I dont even know what demo script to trust.
                        I dont know why nobody votes for this.

                        Comment


                          #13
                          Hello ezrollin,

                          Below is a link to a forum post with everything required to expose a value to the Strategy Builder.
                          I'm trying to expose my variables to the strategy builder so everyone can have better use of the WaveTrend indicator (it has a lot of code). Explain this to me like I am 5 because this isnt the first time I've tried to figure it out and hit a wall. What is Series? I know its like an array that stores bars. Why not just call it


                          I will forward your request for this to be added to the help guide.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            That is my thread in which it didnt get resolved.
                            Two other members didnt get a reply. So they didnt figure it out.
                            I'm not sure if yall even knew what I was trying to do. Maybe that was my fault
                            Last edited by ezrollin; 08-30-2022, 08:25 PM.

                            Comment


                              #15
                              Hello ezrollin,

                              A working example was provided.

                              I will continue assisting in the other thread with the null variable / indexing errors.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              662 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              376 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              110 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              580 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X