Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling an Indicator from a Different Indicator

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

    Calling an Indicator from a Different Indicator

    I've attached an Indicator that updates a Series on every tick. This is just a proof of concept so I can understand how to call the Series from another Indicator. Here is the indicator I am using to try to call it:

    Code:
        public class CallBuySell : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "CallBuySell";
                    Calculate                                    = Calculate.OnEachTick;
                    IsOverlay                                    = false;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                    AddPlot(Brushes.Orange, "CloseValue");
                }
            }
            protected override void OnBarUpdate()
            {
                if (CurrentBar < 0 || CurrentBar <= BarsRequiredToPlot)
                    return;            
                CloseValue[0] = SampleBuySellVolume().SjClose[0];
            }
    
            public Series<double> CloseValue
            {
                get { return Values[0]; }
            }
        }
    It just returns an orange line set at 0. What is the proper way to call a non-visual indicator that updates on every tick, from another Indicator? Does the second Indicator need an OnMarketData block? What should the Calculate property be set to on the second Indicator (OnBarClose or OnEachTick)?

    Here is the Non-Visual Indicator:
    SampleBuySellVolume.zip
    Attached Files

    #2
    Hello swcooke,

    Thanks for your post.

    The "Non-Visual Indicator" link does not point to anything. I recreated the posted code and downloaded the attached file. When I run your code I see a line at 0 until real time data is encountered and then the data displays a value that corresponds to the value provide by the non visual indicator code.

    OnMarketData() is a real time event.

    Comment


      #3
      Yes but I have tick replay enabled. Shouldn't this output a value during tick replay?

      I am starting to wonder if I am misunderstanding how this works. For example, I just created a simple Indicator that calls the built in NT indicator BuySellVolume().Sells[0] and I see that only updates in real time. However, if I add BuySellVolume directly to a chart, the values appear historically. How can I call BuySellVolume from another Indicator and get the history I can see it has?

      Here is the revised code of my simple Indicator calling the built in NT Indicator BuySellVolume. Not getting history when I add my Indicator to a chart:

      Code:
          public class CallBuySell : Indicator
          {
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Indicator here.";
                      Name                                        = "CallBuySell";
                      Calculate                                    = Calculate.OnEachTick;
                      IsOverlay                                    = false;
                      DisplayInDataBox                            = true;
                      DrawOnPricePanel                            = true;
                      DrawHorizontalGridLines                        = true;
                      DrawVerticalGridLines                        = true;
                      PaintPriceMarkers                            = true;
                      ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                      //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                      //See Help Guide for additional information.
                      IsSuspendedWhileInactive                    = true;
                      AddPlot(Brushes.Orange, "CloseValue");
                  }
              }
              protected override void OnBarUpdate()
              {
                  if (CurrentBar < 0 || CurrentBar <= BarsRequiredToPlot)
                      return;            
                  CloseValue[0] = BuySellVolume().Sells[0];
              }
      
              public Series<double> CloseValue
              {
                  get { return Values[0]; }
              }
          }
      Last edited by swcooke; 02-10-2020, 12:05 PM.

      Comment


        #4
        Hello swcooke,

        Thanks for your reply.

        To use Tick Replay there are certain requirements as advised in the help guide here: https://ninjatrader.com/support/help...ick_replay.htm

        Look at the example shown in the section, "Calling a Tick Replay indicator from another Indicator or Strategy".

        Basically you will need to create a private instance and then the key is initializing it in State.Dataloaded. From the help guide, "ensures that the hosting indicator or strategy is aware of the requirements to process Tick Replay during its State.Historical mode and helps to ensure that the hosted indicator calculates as designed up to its current bar using Tick Replay."

        Here is what I tested with:

        Code:
        {
            public class SWcookeTest : Indicator
            {
        [B] SampleBuySellVolume mySBSV = null;[/B]
        
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        Description                                    = @"Enter the description for your new custom Indicator here.";
                        Name                                        = "SWcookeTest";
                        Calculate                                    = Calculate.OnEachTick;
                        IsOverlay                                    = false;
                        DisplayInDataBox                            = true;
                        DrawOnPricePanel                            = true;
                        DrawHorizontalGridLines                        = true;
                        DrawVerticalGridLines                        = true;
                        PaintPriceMarkers                            = true;
                        ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                        //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                        //See Help Guide for additional information.
                        IsSuspendedWhileInactive                    = true;
                        AddPlot(Brushes.Orange, "Test");
                    }
                    else if (State == State.Configure)
                    {
                    }
                    else if (State == State.DataLoaded)
                    {
        [B]mySBSV = SampleBuySellVolume();[/B]
                    }
                }
        
                protected override void OnBarUpdate()
                {
        
                    if (CurrentBar < 0 || CurrentBar <= BarsRequiredToPlot)
                        return; 
        
                     Test[0] = [B]mySBSV.SjClose[0];[/B]
        
                }
        
                #region Properties
        
                [Browsable(false)]
                [XmlIgnore]
                public Series<double> Test
                {
                    get { return Values[0]; }
                }
                #endregion

        Comment


          #5
          Thanks! That's what I was missing!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          649 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          573 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X