Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to read Delta from another indicator

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

    How to read Delta from another indicator

    Hi,

    I have a simple indicator that plots delta:


    HTML Code:
    protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    .
                    .
                    AddPlot(new Stroke(Brushes.LawnGreen, 3), PlotStyle.Bar, "BarDelta");
                    AddLine(new Stroke(Brushes.DimGray, DashStyleHelper.Dot, 1), 0, "ZeroLine");
    
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Tick, 1);
                }
                else if (State == State.DataLoaded)
                {
                    cumulativeDelta = OrderFlowCumulativeDelta(CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0);
                }    
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBars[0] < 10 ) return;
    
                if (BarsInProgress == 0)
                {
                }
    
                else if (BarsInProgress == 1)
                {
                    BarDelta[0] = cumulativeDelta.DeltaClose[0] - cumulativeDelta.DeltaOpen[0];
                }            
            }
    
            #region Properties
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> BarDelta
            {
                get { return Values[0]; }
            }
    
            #endregion​

    I am trying to read the exposed BarDelta value from another indicator:

    HTML Code:
            private double ReadValue;
    
            protected override void OnStateChange()
            {
                .
                .
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Tick, 1);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBars[0] < 10 ) return;
    
                if (IsFirstTickOfBar)
                {
                    if (BarsInProgress == 0)
                    {
                        ReadValue = BarDeltaV1()[0];
                        Print ("Current Bar Index: " + CurrentBar.ToString() + "         BarDelta[0]: " + ReadValue.ToString() );
                    }
    
                    else if (BarsInProgress == 1)
                    {
                    }
    
                }            
    
            }​
    There is an error as I am just getting zero values in the printout. I would appreciate any advice on how to read the BarDelta value from the other indicator.

    Thanks so much!

    #2
    Hello Rainmakersg,

    Thank you for your post.

    Are you getting any errors on the Log tab of the Control Center? Does BarDeltaV1 show the BarDelta plot as expected when you add it to a chart, or does it plot 0 for its values? Please provide the output by right-clicking in the NinjaScript Output window, then select Save As, and then attaching the saved .txt file to your reply.

    I look forward to your reply.

    Comment


      #3
      Originally posted by NinjaTrader_Emily View Post
      Hello Rainmakersg,

      Thank you for your post.

      Are you getting any errors on the Log tab of the Control Center? Does BarDeltaV1 show the BarDelta plot as expected when you add it to a chart, or does it plot 0 for its values? Please provide the output by right-clicking in the NinjaScript Output window, then select Save As, and then attaching the saved .txt file to your reply.

      I look forward to your reply.
      Hi Emily,

      Thanks for your reply.

      There are no errors in the log tab of the Control Center when I run both indicators.

      BarDeltaV1 indicator is running fine. It plots the correct delta values, that I double checked with the delta values shown on the delta statistics of a volumetric chart.

      BarDeltaV1 is calculated "on each tick". The receiving indicator, VariableReaderV2, is calculated "on price change".

      I have attached both indicators as well as the output screen (zipped because the txt file is too big, as I run on a 10 second chart to save time)

      Hope you would be able to help me.
      Attached Files
      Last edited by Rainmakersg; 03-30-2023, 10:12 AM.

      Comment


        #4
        Hello Rainmakersg,

        Thank you for your reply.

        I now see what you are referring to; the historical data is processed on bar close, though when you have the reader processing in real-time data it is printing when IsFirstTickOfBar is true. The cumulative delta is set to a bar period, so the volume is accumulated per bar and on the first tick of the bar the delta close minus the delta open is expected to be 0. You could potentially set your reader to print the previous bar's value once the bar has completed:

        ReadValue = BarDeltaV1()[1];

        Print ("Previously completed Bar Index: " + (CurrentBar - 1) + " BarDelta[1]: " + ReadValue);

        This would essentially be the same as setting the reader to calculate OnBarClose instead of OnPriceChange or OnEachTick.

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

        Comment


          #5
          Originally posted by NinjaTrader_Emily View Post
          Hello Rainmakersg,

          Thank you for your reply.

          I now see what you are referring to; the historical data is processed on bar close, though when you have the reader processing in real-time data it is printing when IsFirstTickOfBar is true. The cumulative delta is set to a bar period, so the volume is accumulated per bar and on the first tick of the bar the delta close minus the delta open is expected to be 0. You could potentially set your reader to print the previous bar's value once the bar has completed:

          ReadValue = BarDeltaV1()[1];

          Print ("Previously completed Bar Index: " + (CurrentBar - 1) + " BarDelta[1]: " + ReadValue);

          This would essentially be the same as setting the reader to calculate OnBarClose instead of OnPriceChange or OnEachTick.

          Please let me know if I may be of further assistance.​
          Hi Emily,

          Thanks so much for your reply. Your suggestion is completely logical. I implemented it and the reader indicator does seem to read from the host indicator.

          However, upon closer inspection of the delta values printed in the Output window, they are completely different from the values plotted.

          I would appreciate it if you could assist further.

          Comment


            #6
            Hello Rainmakersg,

            Thank you for your reply.

            Some things to consider that might be affecting the values displayed:
            • I didn't think of this originally, though since the Order Flow Cumulative Delta has to do with volume, it likely needs to calculate On Each Tick. Embedded scripts within a parent script will use the Calculate property of the parent script. Please check that you are using the same Calculate property in both scripts, and you will probably need to set the "reader" script to calculate OnEachTick as well
            • As noted in the help guide page for OnBarUpdate, "Hosted indicators will need to be accessed by the hosting script to ensure OnBarUpdate functionality. This can be done by: 1) Calling Update on the hosted indicator within the host script, 2) Including a plot in the hosted indicator and accessing the plot in the host script, 3) Including a plot in the hosted indicator and adding the indicator to the chart with AddChartIndicator (strategies only)​"
            If you are still getting unexpected results, you may need to take additional debugging steps such as adding different prints. For more tips on debugging your NinjaScripts:Please let us know if we 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
            602 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            347 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
            559 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X