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

OrderFlowDelta Dataseries

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

    OrderFlowDelta Dataseries

    Hello,

    for having OrderFlowCumulativeDelta working correctly one has to add "OrderFlowCumulativeDelta1.Update(OrderFlowCumulat iveDelta1.BarsArray[2].Count - 1, 1);"

    Does this have to be BarsArray[1] or can it be also BarsArray[2]?

    If it can be BarsArray[2] then I dont need to change all dataseries and barsreferrer in the script.

    I have now suddenly "Error on calling OnBarupdate... Index was outside the bounds of the array". If this is caused by what I ask above I dont need to investigate further.

    Thank you!
    Tony


    #2
    Hello tonynt,

    Thank you for your post.

    You would need to use the BarsArray related to the added 1-tick series in your script. If the 1-tick series is added first, you would need to use BarsArray[1]. If the 1-tick series is the second added series in your script, you would need to use BarsArray[2].

    When updating the secondary 1-tick series of the hosted script to make sure the values we get in BarsInProgress == 0 are in sync, you would need to ensure you are using a BarsInProgress check. For example, if the added 1-tick series is the second added series in your script, you would need to check if BarsInProgress == 2 followed by updating the secondary 1-tick series of the hosted script to make sure it is in sync with BarsInProgress 0.

    OrderFlowCumulativeDelta - https://ninjatrader.com/support/help...ive_delta2.htm

    The error message you are receiving means that you are accessing a bar that has not processed yet. A CurrentBars check would need to be added to your script to ensure that there are enough bars for all added series in your script. See the help guide link below for more information about CurrentBars.

    CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
    Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      thank you for your reply. Yes I have
      if (BarsInProgress == 2) {OrderFlowCumulativeDelta1.Update(OrderFlowCumulat i veDelta1.BarsArray[2].Count - 1, 1);}

      I work long time with CurrentBar and CurrentBars[] eg to assign the barnumber of entry to an int. But I have no idea what you mean with "currentbars check". Or do you mean " if ( CurrentBars[0] < 8 || CurrentBars[1] < 8 || CurrentBars[2] < 8) return;?

      For testing purposes: whatever script I take and change the snippet from 1st paragraph here from BIP==1 to BIP2 I get the error-message in logtab. (of course in state-configure I have the corresponding dataseries with 1 Tick)

      I have a small sample here. I removed really everything from my script! There is no logic for trading to debug. Only few lines with use of OFDelta.

      Thank you!
      Tony
      Attached Files
      Last edited by tonynt; 02-25-2021, 09:03 AM.

      Comment


        #4
        Hello tonynt,

        Thank you for that information.

        I see that your script is using a CurrentBars check to ensure there are enough bars.

        After further investigation, I have found that the 1 Tick series must be the first added series in the script. Then you would reference the added series using a BarsInProgress == 1 check and using BarsArray[1] when updating the indicator.

        Please see the attached example script that demonstrates using the OrderFlowCumulativeDelta indicator in a NinjaScript strategy with more than one secondary series added.

        The example script adds a 1 Tick NQ 03-21 data series and an 8 Range MNQ 03-21 data series in State.Configure. Then, we instantiate the OrderFlowCumulativeDelta indicators in State.DataLoaded. In OnBarUpdate() we use a CurrentBars check to make sure there are enough bars being processed. Next, a BarsInProgress == 0 check is done and we print the DeltaClose. Following that we check if BarsInProgress == 1 (our added 1 Tick series) and update the secondary series of the hosted indicator to make sure the values we get in BarsInProgress == 0 are in sync.

        Let us know if we may assist further.
        Attached Files
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          thank you for you reply. dont need the sample, This is working as I wrote. My question was referring accurately if it can be another dataseries than BIP1.
          But I have another question now. After I read the code of this sample in NinjaScriptEditor I closed the editor and there appeared the attached message? Why?
          (this appears often and I have now idea why. so I´m happy that it occurs now with your sample to get a reply about this)

          Thank you!
          Tony
          Attached Files

          Comment


            #6
            Hello tonynt,

            Thank you for your note.

            If we have two added series in a script with the 1-tick series added second, such as:

            Code:
            else if (State == State.Configure)
                        {
                            AddDataSeries(null, BarsPeriodType.Range, 8);
                            AddDataSeries(null, BarsPeriodType.Tick, 1);
                        }
            then we would need to use :

            Code:
            else if (BarsInProgress == 2)  // This is the code example from the help guide, it runs when the 1 tick series calls OnBarUpdate and is needed to sync the values.
                        {
                              // We have to update the secondary series of the hosted indicator to make sure the values we get in BarsInProgress == 0 are in sync
                              OrderFlowCumulativeDelta1.Update (OrderFlowCumulativeDelta1.BarsArray[1].Count - 1, 1);
                              OrderFlowCumulativeDelta2.Update(O rderFlowCumulativeDelta2.BarsArray[1].Count - 1, 1);
            
                        }
            The above indexes for BarsArray[1].Count and the last 1 index should stay as 1. This is because in the Order Flow Cumulative Delta indicator, BarsInProgress 1 is the single tick series, but in the strategy, BarsInProgress 2 is the single tick series.

            See the attached example.

            Regarding your inquiry about the Unhandled exception error, this would indicate that an object in one of your indicators or strategies is returning null. Do you see any error messages in the Log tab of the Control Center when this occurs? If so, what does the error message report?

            Do you receive and compile errors in the NinjaScript Editor window after clicking the compile button? If so, what do these report?

            ​​​​​​​I look forward to further assisting.
            Attached Files
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Hello,

              thank you for your reply. I was clear about this and as you replied in #4 "I have found that the 1 Tick series must be the first added series in the script" I changed all [x] in my scripts.

              Now you give in "Code" another solution where the added 1 Tick dataseries is not the first added series.

              I´m confused now. Can you please clearify.

              Thank you!
              Tony

              Comment


                #8
                Hello tonynt,

                Thank you for your note.

                It was my understanding at first that the 1 Tick series needed to be added first in the script. However, after further testing, I see that the 1 Tick series does not have to be added first.

                If the 1 Tick series is added second in the script. You would check if BarsInProgress == 2 for the second added series in the strategy. Then, we use a BarsArray[1] when updating the indicator because the OF Cumulative Delta indicator itself has a single added series of 1-Tick.

                See the example in my previous reply for how this is accomplished.

                Let us know if we may assist further.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Hello,

                  thank you for your reply. Still do not understand why inside the bracket of BIP2 it is BIP1 to sync the values when its inside BIP1 to sync with BIP1 in case of first added dataseries. However I change it in the meantime and I continue with 1st added dataseries as this works for long time.

                  Referring the error message I can reply that in the log tab there is the same message as the screenshot. Is there any chance to find out which script is causing this? Can it be from another script that has not been opened in the editor (as the message appears when closing the editor, I do not recall now if it appeared with compiling)

                  Thank you!
                  Tony

                  Comment


                    #10
                    Hello tonynt,

                    Thank you for your note.

                    The example strategy's code contains two added series, an 8 Range series, and a 1 Tick series. The 1 Tick series in the strategy is needed to run the OF Cumulative Delta indicator in the strategy as stated in the help guide's example code, "A 1 tick data series must be added to the OnStateChange() as this indicator runs off of tick data". This would make the 1 Tick series of the strategy be BarsInProgress 2.

                    The Order Flow Cumulative Delta's code contains a single added 1 Tick series that the indicator references. This series is BarsInProgress 1 inside the indicator itself.

                    When we have to update the secondary series of the hosted script (the strategy) we must check if BarsInProgress == 2 since this is the 1 Tick series in the strategy. We then use BarsArray[1] inside of the indicators .Update method because the indicator itself must reference its own 1 Tick series (BarsInProgress 1).

                    Yes, the error message could be coming from any script in the NinjaScript Editor window. You would need to open a New > NinjaScript Editor window, open any indicator or strategy, and click the compile button to see which script the error could be coming from.

                    Let us know if you have further questions.







                    Brandon H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by JonesJoker, 04-22-2024, 12:23 PM
                    8 responses
                    41 views
                    0 likes
                    Last Post JonesJoker  
                    Started by timko, Today, 06:45 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post timko
                    by timko
                     
                    Started by Waxavi, 04-19-2024, 02:10 AM
                    2 responses
                    37 views
                    0 likes
                    Last Post poeds
                    by poeds
                     
                    Started by chbruno, Yesterday, 04:10 PM
                    1 response
                    44 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by Max238, Today, 01:28 AM
                    1 response
                    25 views
                    0 likes
                    Last Post CactusMan  
                    Working...
                    X