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

Order entry one bar later

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

    Order entry one bar later

    As you can see in jpeg attached, I have created a very simple strategy.

    DeltaHigh of a bar > 75, then EntryShortLimit + 4 ticks in next bar
    DeltaLow of a bar < -75, then EntryLongLimit - 4 ticks in next bar

    But orders are launched one bar later instead just the bar after the conditions are met.
    Can somebody please have a look at the strategy file zip and tell me what line of code is wrong?
    Thanks a lot

    Click image for larger version

Name:	17_09_2020_1918.jpg
Views:	496
Size:	202.4 KB
ID:	1118676

    #2
    Hello Impessa,

    Thank you for your post.

    When running a strategy that uses OnBarClose, it is expected to see an execution marker placed on the next bar when an order is submitted. OnBarClose processes the logic after the bar is completely closed. Any actions that occur will be run after the bar is closed at the open of the next bar.

    In your screenshot, we see that an execution marker is placed two bars after you expect the submission to be triggered. We also see that the indicator added to your chart is not what is added in the strategy. Because it is a different indicator, it should not be trusted as something that is triggering logic in the strategy,

    AddChartIndicator should be used to add the indicator that your strategy processes from to the chart. AddChartIndicator may be used as follows to add the indicator to a chart.

    AddChartIndicator(cumulativeDelta);

    To better understand how the script is working, you could add Prints after the order submission logic to check which bar and time the order was submitted at for comparison. For example, the following Print may be used to accomplish this.

    Print("Submitted at bar: " + CurrentBar + " Time submitted: " + Time[0]);

    Additionally, I have attached a screenshot of the results we got after testing the script on our end. The results we are seeing are expected since the execution marker is being placed on the next bar after the order submission takes place.

    Click image for larger version

Name:	2020-09-17_12-28-09.png
Views:	383
Size:	90.4 KB
ID:	1118697

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

    Comment


      #3
      Hello Brandon

      Thanks for your reply.

      What have you modify in the script you have run for the screenshot?

      The indicator added to my chart, because is "Order Flow Cumulative Delta", the same in the strategy... It`s not a different indicator... I don't understand what you mean...

      Comment


        #4
        Hello Impeesa,

        Thank you for your note.

        The Order Flow Cumulative Delta indicator that is added to your chart is not the same indicator instance that is added in your strategy. Since the indicators are different, the indicator on your chart is not what the strategy is using with its logic. We suggest using AddChartIndicator for adding indicators to the chart so that we know that the indicator on the chart is the same indicator running in the strategy. It is also possible that the indicator on the chart may be using different settings than the indicator in the strategy.

        In the attached script, we used AddChartIndicator(cumulativeDelta) within State.DataLoaded to add the Order Flow Cumulative Delta indicator that is specified in your strategy. We also added Prints after the order submission occurs in order to see at what time and which bar orders are placed.

        Please see the modified example I have attached to see how this is accomplished.

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

        Comment


          #5
          Hello Brandon

          Thank you for the reply, and your patience... I have understood what you mean...

          And I think I know what is the real problem... Let´s go...

          CumulativeDelta included in strategy is surprisingly one bar delay from "Real" CumulativeDelta indicator, as you can see in first screenshot attached...
          In other code, I have changed only indicator, VOL instead of CumulativeDelta, and it works ok. (second screenshot)

          Well, it is something different with CumulativeDelta indicator, so maybe it is necessary run the strategy OnEachTick. Ok, but in this case entries order are launched during the trigger bar, not at close +- N Ticks... What lines do you recomend as a solution?

          Thanks again
          Attached Files
          Last edited by Impeesa; 09-18-2020, 01:52 AM.

          Comment


            #6
            Hello Impeesa,

            Thank you for that information.

            In the attached modified strategy, I have added a bars check for the added series and called cumulativeDelta.Update as shown in the help guide linked below. What this does is update the secondary series of the hosted indicator to make sure the values we get in BarsInProgress == 0 are in sync. Then the strategy was added to the chart and enabled.

            After that, I added the Order Flow Cumulative Delta indicator to the chart with Calculate set to OnEachTick so that it matches our strategy's indicator.

            In the screenshot below, you can see that we are getting matching bars after adding the cumulativeDelta.Update call to the strategy.

            Click image for larger version

Name:	2020-09-18_10-02-53.png
Views:	386
Size:	58.9 KB
ID:	1118846

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

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

            Comment


              #7
              Hello, Brandon

              I have run your script and both CumulativeDelta indicator match. Thanks a lot.

              New problem is that orders are launched during the bar where conditions are triggering and not at close. Please, look at screenshots attached with different issues...

              How can we put the limit order when the trigger bar closes?

              Thanks in advance
              Attached Files

              Comment


                #8
                As you can see, it is important that the strategy runs OnBarClose despite it uses an indicator OnEachTick....

                Many thanks for your help
                Attached Files

                Comment


                  #9
                  Hello Impeesa,

                  Thank you for your note.

                  Orders are being placed on the bar that the conditions are being met because the strategy is set to Calculate OnEachTick. To have the orders placed on the close of a bar when a condition becomes true, you could set the strategy to Calculate OnBarClose. When a strategy is set to OnBarClose, the strategy's indicator will also Calculate OnBarClose.

                  Let us know if we may be of further assistance.
                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Brandon

                    And what about that the order remains more than one bar? Is ther any solution to that?

                    Thanks

                    Comment


                      #11
                      Hello Impeesa,

                      Thank you for your post.

                      Do you mean an order is being canceld after the bar closes?

                      If you want the order to stay alive until canceled use the special overload that we have for all order methods.

                      EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

                      Please see this help guide link for more information - https://ninjatrader.com/es/support/h...rlonglimit.htm

                      Also, here is a help guide about keeping order alive - https://ninjatrader.com/support/help...ders_alive.htm

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

                      Comment


                        #12
                        Hello

                        As you can see in the third chart of post number 7 is just the opposite. I don't want the order to stay alive, but it does.

                        How can we correct that mistake?

                        Comment


                          #13
                          Do you think Is it mandatory using IsFirstTickOfBar whan cumulativeDelta is in a code? And if it is, how can we use it?

                          Screenshot and strategy attached shows that is really simple and no issues come up coding with an indicator as Volume in the example...

                          if ((Close[0] >Close[1])
                          && (VOL1[0] > Vol_Limit))
                          {
                          BarBrush = Brushes.Lime;
                          CandleOutlineBrush = Brushes.Lime;
                          EnterLongLimit(Convert.ToInt32(DefaultQuantity), (Close[0] - (Ticks_Limit * TickSize)) , "");
                          }

                          // Set 2
                          if ((Close[0] < Close[1])
                          && (VOL1[0] > Vol_Limit))
                          {
                          BarBrush = Brushes.Fuchsia;
                          CandleOutlineBrush = Brushes.Fuchsia;
                          EnterShortLimit(Convert.ToInt32(DefaultQuantity), (Close[0] + (Ticks_Limit * TickSize)) , "");
                          }

                          Thans for your attention
                          Attached Files

                          Comment


                            #14
                            Hello Impeesa,

                            Thank you for your inquiry.

                            Using IsFirstTickOfBar is not mandatory when cumulativeDelta is used in your code. What this property does is indicate if the incoming tick is the first tick of a new bar when running a strategy that uses OnEachTick or OnPriceChange.

                            Here is a help guide link about IsFirstTickOfBar for more information - https://ninjatrader.com/support/help...ttickofbar.htm

                            Orders will stay alive as long as the logic of your script allows the order to stay alive. You could set the orders' isLiveUntilCanceled property to false so the order will expire at the end of a bar.

                            Or, you may use a CancelOrder() method within your script to cancel an order. Otherwise, the order will remain alive until its time in force is reached.

                            Please review the SampleCancelOrder script linked here to see how CancelOrder() methods are used - https://ninjatrader.com/support/help...thod_to_ca.htm

                            Here is a help guide link about using the isLiveUntilCanceled property - https://ninjatrader.com/support/help...tlonglimit.htm

                            Also, here is a help guide link about how CancelOrder() methods are used - https://ninjatrader.com/support/help...t8/?cancel.htm

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

                            Comment


                              #15
                              Hello Brandon

                              First of all, thanks a los for your attention and patience... Maybe because of my bad english or as a beginner in programming I am not explaining myself very well...

                              All you have said to me is very helpful and I am learning a lot in this forum. But I still don´t understand why is so different (and for me difficult to run an strategy with cumulativeDelta) with only two conditions:

                              Close[0] > Close [1] or Close[0] < Close [1]
                              DeltaHigh[0] > Limit or DeltaLow<-Limit
                              EnterLongLimit Close[0] -4 ticks or EnterShortLimit Close[0]+4 ticks

                              Using for example Volume indicator is extremely easy and runs ok with

                              Close[0] > Close [1] or Close[0] < Close [1]
                              VOL[0] > Limit
                              EnterLongLimit Close[0] -4 ticks or EnterShortLimit Close[0]+4 ticks

                              Well, let´s see. We have included

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

                              And also
                              }
                              if (BarsInProgress == 1)
                              {
                              cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
                              }

                              How can we code the strategy to submit an order limit +- n ticks from the close of a bar where DeltaHigh>Limit or DeltaLow<-Limit?

                              I suppose that if next bars conditions are not met the order will cancel as normal (as for example in the strategy using Volume instead of cumulativeDelta), and that does not happen in the code you attached in post 6, as you can see in screenshots posted in 7 and 8.

                              I appreciate a lot your help.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by pmachiraju, 11-01-2023, 04:46 AM
                              8 responses
                              148 views
                              0 likes
                              Last Post rehmans
                              by rehmans
                               
                              Started by mattbsea, Today, 05:44 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post mattbsea  
                              Started by RideMe, 04-07-2024, 04:54 PM
                              6 responses
                              33 views
                              0 likes
                              Last Post RideMe
                              by RideMe
                               
                              Started by tkaboris, Today, 05:13 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post tkaboris  
                              Started by GussJ, 03-04-2020, 03:11 PM
                              16 responses
                              3,283 views
                              0 likes
                              Last Post Leafcutter  
                              Working...
                              X