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

Cummulative delta is not evaluating correcly in strategy

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

    #16
    Thank you.

    I have a question about calculating negative cumulative delta.
    In my logic i have
    For Longs I have this line and if delta is in negative for example -15200Open - 15000Close, will below formula evaluates correctly or not?
    (Deltaclose > Deltaopen)

    However for Shorts i have this line and if delta is in negative for example -15000Open - 15200Close, will below formula evaluates correctly or not?
    (Deltaclose < Deltaopen)

    Also for having cumulative engulfing bar condition, would this be correct?
    (Deltaclose < Deltaopen) && (Deltaclose < Math.Min(DeltaopenPr, DeltaclosePr)) - For Shorts
    (Deltaclose > Deltaopen) && (Deltaclose > Math.Max(DeltaopenPr, DeltaclosePr)) - For Longs

    Please help because I dont think this logic is enough. Thank you
    Last edited by tkaboris; 03-08-2023, 07:38 AM.

    Comment


      #17
      Hello tkaboris,

      Thanks for your note.

      If the Deltaclose value is greater than the Deltaopen value then this condition would be true. Based on your example, if the Deltaopen has a value of -15200 and Deltaclose has a value of -15000, the Deltaclose value would be greater than Deltaopen.

      In your next example, if the Deltaopen has a value of -15000 and the Deltaclose has a value of -15200, the DeltaOpen would have a value that is greater than the Deltaclose.

      Ultimately, to understand if the conditions will evaluate as you are expecting them to, debugging prints must be added to the script (one line above the condition they are being used in) that print out each of the values being used in your condition as previously stated. Note that it would be up to your to come up with the exact logic to accomplish your overall goal.

      This means you should add prints to the script outside of the condition to place an order that prints out 'Deltaclose', 'Deltaopen', 'Math.Min(DeltaopenPr, DeltaclosePr)', and 'Math.Max(DeltaopenPr, DeltaclosePr)' to fully understand how each of these values are processing when the script is run.

      Below is a link to a forum post that demonstrates how to use prints to understand behavior.

      https://ninjatrader.com/support/foru...121#post791121

      Let me know if I may assist further.​
      Brandon H.NinjaTrader Customer Service

      Comment


        #18


        Can someone help me to find out why my strategy is pulling different values for close and open for cumulative delta? Its like it shifts 1 backwards
        I have these in my strategy
        Code:
        Deltaclose = myCumulativeDelta.DeltaClose[0];
                    Deltaopen = myCumulativeDelta.DeltaOpen[0];
                    Deltahigh = myCumulativeDelta.DeltaHigh[0];
                    Deltalow = myCumulativeDelta.DeltaLow[0];​
        and these values below from indicator
        Code:
                        Values[0][0] =  OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaOpen[0];
                        Values[1][0] =  OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaHigh[0];
                        Values[2][0] =  OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaLow[0];
                        Values[3][0] =  OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[0];                                
                        ​
        I think indicator is shifting backwards by 1, Maybe i need to shift this line to +1? how to do that?
        Deltaclose = myCumulativeDelta.DeltaClose[0];
        I tried this but it shifts back even further
        Deltaclose = myCumulativeDelta.DeltaClose[0]+1;
        Click image for larger version  Name:	image.png Views:	0 Size:	1.57 MB ID:	1241534
        Last edited by tkaboris; 03-20-2023, 12:51 PM.

        Comment


          #19
          Hello tkaboris,

          Thanks for your note.

          Please see the attached simple example script that demonstrates plotting the DeltaOpen, DeltaHigh, DeltaLow, and DeltaClose values from the Order Flow Cumulative Delta indicator on a chart.

          We can see in the attached screenshot that the Order Flow Cumulative Delta indicator values match the attached example script's plot values.

          If you test the attached script and compare it to the Order Flow Cumulative Delta indicator, do you see the values matching in the Data Box window?

          To truly know what is causing the issue it would be necessary to use prints and debug by looking at all of the information the script is using for decisions. To find the exact line(s) of code that is causing values in your script to not match up, you would need to reduce the script by commenting out code and debug by adding prints to narrow in on and locate the offending code.

          Note that when identifying an issue, it is extremely important to have extremely simple test scripts and very simple steps to reproduce that only have the bare minimum code necessary to reproduce the behavior without any other code and do not require specific market conditions to reproduce (unless the issue is with specific market conditions).

          See the forum post linked below explaining reducing code and debugging by adding prints to understand behavior.
          https://ninjatrader.com/support/foru...121#post791121

          Let me know if I may assist further.​
          Attached Files
          Brandon H.NinjaTrader Customer Service

          Comment


            #20
            Thank you for response. The problem is that indicator is plotting alright, just like in your example. Thats what i followed. The problem is in my strategy, when I see Prints, I attached above values dont match.
            P.S I was asking the same question in different forum
            Hi i spent whole day yesterday trying to figure out why strategy is printing wrong values on delta close and open. Still cant figure it out. Indicator plots correctly in datawindow and i compare it to other two. Strategy doesnt. Sometimes deltaOpen is matching but deltaclose never in indicator i am plotting these // in

            Comment


              #21
              Hello tkaboris,

              Thanks for your notes.

              I see in the other forum thread you shared that you are calling AddChartIndicator() in State.Configure.

              AddChartIndicator() should be called in State.DataLoaded as seen in the AddChartIndicator help guide page sample code linked below.

              AddChartIndicator(): https://ninjatrader.com/support/help...chartindicator

              I also see in the other forum thread that your strategy uses Calculate.OnBarClose.

              The Order Flow Cumulative Delta indicator uses Calculate.OnEachTick.

              If the strategy uses Calculate.OnBarClose, the strategy will only update at the close of each bar. To have the script calculate logic and plot values intrabar, you should run the script using Calculate.OnEachTick so it matches the Order Flow Cumulative Delta indicator. You could try comparing the strategy using Calculate.OnEachTick to the indicator that uses Calculate.OnEachTick to see if values match between the two.

              Or, you could set the Order Flow Cumulative Delta indicator to use Calculate.OnBarClose and compare it to your strategy that is using Calculate.OnBarClose to see how the values evaluate.

              Note to only direct replies to a single form thread instead of creating multiple forum threads about this same topic. This causes multiple technicians to work the same tickets which may lead to longer response times since each technician would need to find each post to that is related to gather all the information about your inquiry.

              Going forward please direct all replies regarding this inquiry to the forum thread you linked to in post # 20 or to this forum thread.

              Let me know if I may assist further.
              Brandon H.NinjaTrader Customer Service

              Comment


                #22
                hi thank you for response.
                - I did put strategy on tick just to see and it displays even more off. I need my strategy to work on barclose, not tick. I understand cumulative uses tick and i basically need just a last value of a bar for cumulative, i dont need wll ticks. Below screenshot displays last cumulative of a bar and its really off
                - I also placed addchartindicator in data loaded but still open and close are off.
                Code:
                else if (State == State.DataLoaded)
                            {
                                myCumulativeDelta = BounceCumDelta();
                                AddChartIndicator(BounceCumDelta());​
                Click image for larger version

Name:	image.png
Views:	60
Size:	1.39 MB
ID:	1241823

                Comment


                  #23
                  Hello tkaboris,

                  Thanks for your notes.

                  Unfortunately, since the OrderFlow items are not open source, I would not have any details on why it might not line up with the version you are plotting. It is likely that you would need to add a 1-Tick series to the script and run your strategy with Calculate.OnEachTick.

                  That said, I have created a simple test strategy that uses Calculate.OnEachTick, adds a 1-Tick additional data series and prints out the plot values of the example script attached in post # 19. We can see in the attached screenshot that the values are matching between the NinjaTrader Order Flow Cumulative Delta indicator and the custom strategy that is accessing a custom indicator. You could consider comparing this example to your script to see where differences might be.

                  I suggest that you create a very simple example script that contains only the code used to reproduce the issue (all other code is commented out or removed). You could test the very simple test scripts to see exactly how values are evaluating in your logic. You may compare the simple script to a chart window and data box window with no other indicators or strategies added onto the chart to see how that specific indicator or strategy is behaving. Then to find where the offending code might be, you would have to further debug your scripts by reducing code and adding prints.

                  Let me know if I may assist further.
                  Attached Files
                  Brandon H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by jxs_xrj, 01-12-2020, 09:49 AM
                  6 responses
                  3,290 views
                  1 like
                  Last Post jgualdronc  
                  Started by Touch-Ups, Today, 10:36 AM
                  0 responses
                  8 views
                  0 likes
                  Last Post Touch-Ups  
                  Started by geddyisodin, 04-25-2024, 05:20 AM
                  8 responses
                  61 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by Option Whisperer, Today, 09:55 AM
                  0 responses
                  8 views
                  0 likes
                  Last Post Option Whisperer  
                  Started by halgo_boulder, 04-20-2024, 08:44 AM
                  2 responses
                  24 views
                  0 likes
                  Last Post halgo_boulder  
                  Working...
                  X