Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OrderFlow Cumulative Delta for Bar incorrect

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

    OrderFlow Cumulative Delta for Bar incorrect

    Hi im trying to get the order flow culative delta for the last bar.

    My Code is pretty simple:

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class AaIndicatorTester : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Indicator tester";
    Name = "AaIndicatorTester";
    Calculate = Calculate.OnPriceChange;
    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(new Stroke(Brushes.White, 20), PlotStyle.Bar, "DeltaPlot");
    
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    }
    
    }
    
    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 0)
    {
    if (IsFirstTickOfBar && CurrentBar > 2)
    {
    OrderFlowCumulativeDelta cumulativeDelta = OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0);
    double currentDeltaForBar = cumulativeDelta.DeltaClose[1];
    Print("");
    Print(Time[0]);
    Print(currentDeltaForBar);
    if (currentDeltaForBar > 0)
    {
    PlotBrushes[0][0] = Brushes.Green;
    }
    else
    {
    PlotBrushes[0][0] = Brushes.Red;
    }
    DeltaPlot[0] = currentDeltaForBar;
    }
    
    }
    //else current bars index is 1 then do work on the cumulative delta
    else if (BarsInProgress == 1)
    {
    // We have to update the secondary series of the hosted indicator to make sure the values we get in BarsInProgress == 0 are in sync
    OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0).Update(OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0).BarsArray[1].Count - 1, 1);
    }
    }
    
    #region Properties
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> DeltaPlot
    {
    get { return Values[0]; }
    }
    
    #endregion
    }
    
    }
    However on each new bar I read the last bars cuml volume but the value is always off by about 10% give or take.

    As you can see an example of this in screenshot at the close of 16:43:43 bar the cumulative delta read -92, but my log was -83.

    If I try to run my indicator OnEachTick, the same thing happens.

    Thanks
    ,
    tarik

    #2
    Hello tarikmedjber,

    Thank you for your post.

    I've revised your script a bit so you're not repeatedly calling the Cumulative Delta and made some minor modifications. Running the attached script set to OnEachTick, I'm seeing the indicator return correct values for the prior bar's CumulativeDelta in real time and historical. Do you see the same with this script?

    Thanks in advance; I look forward to assisting you further.
    Attached Files

    Comment


      #3
      Absolutely amazing thank you as always Kate.

      I’m not at the office right now but I’ll try it out when I get in. Thanks again

      Comment


        #4
        Morning Kate,

        That is all working now!

        Thans v much

        Comment


          #5
          Hi again,

          Okay so it is working in the indicator but if I then call the indicator from a strategy, the strategy is receiving incorrect values?

          I've attached the indicator and strategy

          Tarik
          Attached Files

          Comment


            #6
            Hello tarikmedjber,

            Thank you for your reply.

            Try this version - we take the same approach to update the indicator as we do in the indicator itself. I'm seeing this behave in real time after a bar or two how I would expect. Some differences as we transition into real time are to be expected, but once you're there you should see what's returned start to line up correctly.

            Please let us know if we may be of further assistance to you.
            Attached Files

            Comment


              #7
              Thats working great now thanks Kate Damn OrderFlowCumulativeDelta.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              605 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              351 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              105 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              560 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              561 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X