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

OrderFlow Cumulative Delta Bar yielding different values in Indicator vs Strategy

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

    OrderFlow Cumulative Delta Bar yielding different values in Indicator vs Strategy

    Can you please take a look at this indicator and strategy and let me know why I am receiving different values from the OrderFlowCumulativeDelta Indicator when I instantiate it from an indicator vs a strategy?

    The indicator just loads an instance of OrderFlow Cumulative Delta Bars and prints out the values of the current bar. Calculate is set to OnBarClose.
    The strategy just loads an instance of OrderFlow Cumulative Delta Bars and prints out the values of the current bar. Calculate is set to OnBarClose.

    It appears I get the same values from either code when in State.Historical for example:
    Strategy - Bar: 3315 the delta was: 27 the Close was: 8982.25
    Strategy - Bar: 3316 the delta was: 26 the Close was: 8985
    Strategy - Bar: 3317 the delta was: -152 the Close was: 8978.75
    Indicator - Bar: 3315 the delta was: 27 the close was: 8982.25
    Indicator - Bar: 3316 the delta was: 26 the close was: 8985
    Indicator - Bar: 3317 the delta was: -152 the close was: 8978.75


    But as soon as I hit realtime, it starts to return different values:

    Indicator - Bar: 3332 the delta was: -84 the close was: 8964.5
    Strategy - Bar: 3332 the delta was: -41 the Close was: 8964.5
    Indicator - Bar: 3333 the delta was: 128 the close was: 8973.25
    Strategy - Bar: 3333 the delta was: -83 the Close was: 8973.25
    ...
    Indicator - Bar: 3338 the delta was: 96 the close was: 8982
    Strategy - Bar: 3338 the delta was: -177 the Close was: 8982

    Thanks,
    Nick
    Attached Files

    #2
    Hello NickyD,

    Thanks for your post.

    To correctly use Order Flow Cumulative delta, you must add a 1 tick data series as that is what provide the data for the indicator and you must add code to synchronize the data between the 1 tick series and your chart bars. You are missing the synchronizing code.

    Please see the help guide examples on this page: https://ninjatrader.com/support/help...ive_delta2.htm

    The 2nd example would be similar to how you are using the Order Flow indicator (by reference)

    Note: I would think it would be easier for you to call the Order flow indicator directly in your strategy instead of calling an indicator that then calls the order flow indicator.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Wow. Yes, that did it. I have not been doing that in any of my scripts.


      I had usually been doing this all along:

      private OrderFlowCumulativeDelta myCumulativeDeltaBar;

      else if ( State == State.Configure ) {
      AddDataSeries(Data.BarsPeriodType.Tick, 1);
      }

      protected override void OnBarUpdate()
      {

      myCumulativeDeltaBar.Update();

      if ( BarsInProgress != 0 )
      return;

      ..... rest of strategy code....

      }


      I'm not arguing that my code is correct, it doesn't work, I just don't understand how my code above is functionally different than the correct code.

      cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);

      My .Update statement should be invoked on every invocation of OnBarUpdate which will be every event on my primary series and every tick since my secondary series is 1 tick. It seems to me that the indicator should be updating the secondary BarsArray when the OnBarUpdate event is processed in the context of BarsInProgress = 1 ... ? What am I missing?


      Comment


        #4
        Oh... perhaps what I wrote above might have worked. Maybe that's why I wasn't aware of this for so long. However, I confused myself and I don't think my follow up post was describing my code to you was correct.

        In the scenario in my original post, I had an INDICATOR that instantiates the OrderFlowCumulativeDelta because I have further logic to do there before being useful to my strategy, then my STRATEGY was instantiating my custom indicator... so while I had a secondary data series in my strategy, I didn't have one in my custom indicator. That means that I had no synching logic for the OrderFlowCumulativeDelta indicator because the only OnBarUpdate events where I was calling .Update were in my strategy... so it seems the OBU 1 tick event in my strategy was really just calling an indicator that wasn't synching correctly.

        Comment


          #5
          Hello NickyD,

          Thanks for your reply.

          Glad it is working with help guide direction.

          Your Update() code was not in the scripts you posted so I was a bit confused with your reply, thanks for clarifying.

          The help guide provides the example and direction for the synchronizing code which you have successfully implemented and would suggest you continue to use that.
          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,607 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          9 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          19 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          6 views
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          15 views
          0 likes
          Last Post Javierw.ok  
          Working...
          X