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

    Cummulative delta is not evaluating correcly in strategy

    i have orderflow indicator bottom one and it plots correctly. However in my strategy
    when i have following, the bold statement doesnt work, it seems like data from indicator shifts one bar further and currently not evaluating that current close is above previous open
    Close[0] > Open[0]
    && && (Deltaclose > Deltaopen) && Deltaclose > Math.Max(DeltaopenPr1, DeltaclosePr1)

    Deltaclose [0]= (OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[0]);
    DeltaclosePr [0]= (OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[1]);

    In my indicator i have following line

    {
    // We have to update the secondary series of the cached indicator to make sure the values we get in BarsInProgress == 0 are in sync
    OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).Update(OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).BarsArray[1].Count - 1, 1);
    }​​

    Can someone advice?
    IT seems opening correctly in backtesting, but when in market replay its either doesnt open at all or opens not taking cumulative delta into consideration

    Update.
    On second image delta is 2508, delta close and delta signal close point to the same value but it prints different values in Prints
    Below values are from indicactor
    if (BarsInProgress == 0)
    {
    // Print the close of the cumulative delta bar with a delta type of Bid Ask and with a Session period
    Print("Delta Signal Close: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[0] + " " + Time[0]);
    Print("Delta Signal Open: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaOpen[0] + " " + Time[0]);
    Print("Delta Signal High: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaHigh[0] + " " + Time[0]);
    Print("Delta Signal Low: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaLow[0] + " " + Time[0]);
    Print("-----------------");
    Print("Delta Previous Close: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[1] + " " + Time[0]);
    Print("Delta Previous Open: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaOpen[1] + " " + Time[0]);
    Print("Delta Previous High: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaHigh[1] + " " + Time[0]);
    Print("Delta Previous Low: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaLow[1] + " " + Time[0]);
    Print("-----------------");
    Print("Delta Previous2 Close: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[2] + " " + Time[0]);
    Print("Delta Previous2 Open: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaOpen[2] + " " + Time[0]);
    Print("Delta Previous2 High: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaHigh[2] + " " + Time[0]);
    Print("Delta Previous2 Low: " + OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaLow[2] + " " + Time[0]);
    }
    else if (BarsInProgress == 3)
    {
    // We have to update the secondary series of the cached indicator to make sure the values we get in BarsInProgress == 0 are in sync
    OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).Update(OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).BarsArray[3].Count - 1, 1);
    }


    if (BarsInProgress == 0)
    {
    Deltaclose [0]= (OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[0]);
    Deltaopen [0]= (OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaOpen[0]);
    Deltahigh [0]= (OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaHigh[0]);
    Deltalow [0]= (OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaLow[0]);


    Click image for larger version  Name:	image.png Views:	0 Size:	715.0 KB ID:	1237813

    Click image for larger version

Name:	image.png
Views:	138
Size:	1.51 MB
ID:	1237997​​​
    Attached Files
    Last edited by tkaboris; 03-05-2023, 02:16 PM.

    #2
    Hello tkaboris,

    Thanks for your post.

    We are currently researching this inquiry and we will follow up with more information as soon as we are done looking into this inquiry.

    Thanks for your patience; I look forward to assisting further.​
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thank you, i attach ind just in case
      Attached Files

      Comment


        #4
        Hello tkaboris,

        Thanks for your note.

        In the indicator script you shared, I see that you are calling else if (BarsInProgress == 3) but there is only one added data series in the script using AddDataSeries().

        Code:
        else if (BarsInProgress == 3)
        {
        // We have to update the secondary series of the cached indicator to make sure the values we get in BarsInProgress == 0 are in sync
        OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).Update(OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).BarsArray[3].Count - 1, 3);
        }​


        Since there is only one additional data series in the script, this should be changed to BarsInProgress == 1 similar to the sample code on the Order Flow Cumulative Delta help guide page.

        Order Flow Cumulative Delta: https://ninjatrader.com/support/help...ive_delta2.htm

        I have attached a simple example script demonstrating how to print out the current and previous DeltaClose, DeltaOpen, DeltaHigh, and DeltaLow values as well as updating the secondary series of the cached indicator to make sure the values we get in BarsInProgress == 0 are in sync.

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

        Comment


          #5
          NinjaTrader_BrandonH Thank you. I have too much logging of the same thing going on that it makes imposible to debug. Bar hasnt changed but lots of logging coming from cumulative indicator it seems. i havedata sereis of 1 tick in cum delta indicator
          AddDataSeries(Data.BarsPeriodType.Tick, 1);

          Click image for larger version  Name:	image.png Views:	0 Size:	526.4 KB ID:	1238343
          Last edited by tkaboris; 03-07-2023, 09:28 AM.

          Comment


            #6
            I appriciate your help.
            I have cumulative strategy that we worked on and in backtest mode it plots however in live testing and trading it does not open any trades. It opens trade without cumulative filter but with it (&& (Deltaclose < Deltaopen) && (Deltaclose < DeltaclosePr)) it doesnt doesnt. There are no prints and i cant figure out why it doesnt open. Delta indicator was uploaded earlier too.
            Attached Files

            Comment


              #7
              Hello tkaboris,

              Thanks for your note.

              I suggest reducing the number of prints you are using if the number of prints is making it difficult for you to debug. You could comment out some prints and focus on testing one section of prints at a time.

              For example, you could comment out the Previous Delta prints in the script, add the indicator to a chart window and add the Order Flow Cumulative Delta indicator to the chart, let the custom script run for a moment, and then remove the custom indicator from the chart.

              After removing the indicator, you could compare the debugging prints in the Output window to a Data Box when hovering the mouse over certain bars. You would compare the CurrentBar print to the bar index value in the Data Box window and compare the Delta prints in the Output window to the Order Flow Cumulative Delta indicator values in the Data Box for that bar.

              You may do something similar to test the Previous Delta values. Ensure you are printing out the CurrentBar value, compare the CurrentBar print to the bar index in the Data Box window, then hover the mouse over the previous bar and compare the 'Previous Delta' prints to the Order Flow Cumulative Delta values in the Data Box.

              See the attached screenshot.

              In regard to debugging your strategy, I see you have the prints added inside the condition to place the order. If the condition is not becoming true then the prints will not display. You should add the prints one line above the condition to place the order to see how exactly the values are being calculated. A simple example of this could be seen below.

              Code:
              if (longsOn)
              {
                     Print("DeltaClose " + Deltaclose + " " + "DeltaClosePr " + DeltaclosePr);
                     if (TradeType1
                        && emaAngulation > EMAAngulation * TickSize // EMA Angulation is greater then (x)
                        && emaAngulationXBarsBefore > EMAAngulationXBarsBefore * TickSize // EMA Angulation X bars before - angulation not on current bar but 5 bars before for example
                        && Close[1] < Open[1]     // previous bar bearish
                        && Low[0] < Low[1]         // and low of signal bar is lower then previous bar
              //        && Close[0] > slowEMA[0] && Low[0] < slowEMA[0] + AboveEMATicks * TickSize) // and current bar reversed above Slow EMA
                        &&  Low[0] < slowEMA[0] && Close[0] > slowEMA[0] + AboveEMATicks * TickSize
                        && (Deltaclose > Deltaopen) && (Deltaclose > DeltaclosePr)
                        //&& !(Open[1] < High[1] && Close[0] < High[1])
                        )
                        {    
                            entryOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, TradeSize, 0, 0, "", "BT");
                            // if (TradeType1 == true)
                            // {
                            //   Print("------------------");
                            //   Print("Trade34B Long: " + TradeType1 + " " + Time[0] + " " + Close[0] );
                            //   Print("DeltaClose " + Deltaclose + " " + "DeltaClosePr " + DeltaclosePr);
                            //   Print("------------------");    
                            // }
                               return;
                         }
              
               }​
              Please let me know if I may assist further.
              Attached Files
              Last edited by NinjaTrader_BrandonH; 03-07-2023, 11:19 AM.
              Brandon H.NinjaTrader Customer Service

              Comment


                #8
                ok i am working on it, in my cumdelta indicator i wanted to comment out adddata series for 1 tick because it prints too much logging, if I do that indicaotor doesnt display. Is there a way to have cumdelta indicator update only on bar change not on tick? I
                Something is wrong my my idicator then. indicator takes tick values constantly and my strategy is trying to evaluate on bar close..

                Is it easy to change cumdelta indicator from lines to bars?
                Last edited by tkaboris; 03-07-2023, 11:55 AM.

                Comment


                  #9
                  Hello tkaboris,

                  The added 1-Tick series is required to have in the script if you want to use the Order Flow Cumulative Delta indicator.

                  This added 1-Tick series does not mean that the script will process OnBarUpdate() logic on each tick that occurs. If you run the script using Calculate.OnBarClose, the OnBarUpdate() logic will only process logic at the close of each bar.

                  The example script in post # 4 demonstrates this. We can see prints occurring at the close of each bar, not on each tick, and this is because the script uses Calculate.OnBarClose. You could compare that sample script to your script to see where differences might be.

                  "Is it easy to change cumdelta indicator from lines to bars?"

                  The Order Flow Cumulative Delta indicator that comes default with NinjaTrade does display as bars. Please clarify exactly what you are referring to so I may accurately assist.

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

                  Comment


                    #10
                    right. But why my output is displaying on every tick? Please notice same bar only cumulative delta changes and it updates output.

                    I was refering to my custom delta indicator, it uses lines and i was thinking to change it to candle style..

                    I have AddPlot(Brushes.Orange, "Deltaclose");
                    and then changed it to
                    AddPlot(new Stroke(Brushes.Orange), PlotStyle.PriceBox, "Deltaclose");

                    But looks like it not enough
                    Click image for larger version

Name:	image.png
Views:	136
Size:	467.8 KB
ID:	1238573

                    Comment


                      #11
                      Hello tkaboris,

                      Thanks for your note.

                      You may set the PlotStyle parameter when calling AddPlot() to specify what plot style you want the plot to use. To set the plot style to a bar instead of a line, you could use PlotStyle.Bar.

                      For example:

                      AddPlot(new Stroke(Brushes.Orange), PlotStyle.Bar, "DeltaClose");

                      See this help guide page for more information: https://ninjatrader.com/support/help...t8/addplot.htm

                      Please also see the attached script which is a modified version of the sample script from post # 4. This modified script plots the DeltaClose value to a chart with the plot style set to PlotStyle.Bar.

                      Note that the attached sample script updates the plot at the close of each bar since the script is using Calculate.OnBarClose and we are assigning a value to the plot in our BarsInProgress == 0 condition.

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

                      Comment


                        #12
                        Thank you can i please ask you to update to Price.box style? becaus i need to get open and close and previous values for my strategy and bar only uses close

                        I tried this but it doesnt plot anything
                        AddPlot(new Stroke(Brushes.Orange), PlotStyle.PriceBox, "DeltaClose");
                        AddPlot(new Stroke(Brushes.Green), PlotStyle.PriceBox, "DeltaOpen");​
                        and
                        Value[0] = OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[0];
                        Value[0] = OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaOpen[0];

                        Comment


                          #13
                          Hello tkaboris,

                          Thanks for your note.

                          PriceBox is used to simply place a price box on the price scale. No plot lines or bars will be constructed with this PlotStyle.

                          More information about this could be found on this forum thread: https://forum.ninjatrader.com/forum/...45#post1077345

                          If you want to have bars plotted on the chart for the DeltaClose and DeltaOpen values, you would need to use PlotStyle.Bar.

                          The example script attached in post # 11 is a simple example showing how to create a plot that has a bar PlotStyle and assigning a value to the plot. You could create multiple plots using the bar PlotStyle in your script and assign the value you want to each of those plots, such as DeltaClose or DeltaOpen from the Order Flow Cumulative Delta.

                          Since you have multiple plots, you could use Values[0][0] = X to assign a value to the first plot in the script. To assign a value to the second plot in the script, you would use Values[1][0] = X.

                          See the third sample code section on the AddPlot() help guide page which demonstrates how to assign a value to a plot when you have multiple plots in a script.

                          AddPlot(): https://ninjatrader.com/support/help...t8/addplot.htm
                          Values: https://ninjatrader.com/support/help...nt8/values.htm

                          Please let me know if I may assist further.
                          Last edited by NinjaTrader_BrandonH; 03-07-2023, 02:42 PM.
                          Brandon H.NinjaTrader Customer Service

                          Comment


                            #14
                            i see.
                            I added these two lines to your last script
                            Value[0][0] = OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[0];
                            Value[1][0] = OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaOpen[0];​
                            i get error that it cant applyin [] to double

                            also added these
                            AddPlot(new Stroke(Brushes.Orange), PlotStyle.Bar, "DeltaClose");
                            AddPlot(new Stroke(Brushes.Green), PlotStyle.Bar, "DeltaOpen");​
                            Click image for larger version

Name:	image.png
Views:	113
Size:	89.6 KB
ID:	1238617

                            Comment


                              #15
                              Hello tkaboris,

                              Thanks for your note.

                              The plural Values (with an s) would need to be used to assign values to plots when you have multiple plots in your script.

                              An example of using Values could be seen in the third sample code section of the AddPlot() help guide page linked in post # 13. Please review the sample code on this help guide page.

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

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rhyminkevin, Today, 04:58 PM
                              1 response
                              39 views
                              0 likes
                              Last Post Anfedport  
                              Started by iceman2018, Today, 05:07 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post iceman2018  
                              Started by lightsun47, Today, 03:51 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post lightsun47  
                              Started by 00nevest, Today, 02:27 PM
                              1 response
                              14 views
                              0 likes
                              Last Post 00nevest  
                              Started by futtrader, 04-21-2024, 01:50 AM
                              4 responses
                              49 views
                              0 likes
                              Last Post futtrader  
                              Working...
                              X