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

Repeating EnterLongLimit in Realtime

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

    Repeating EnterLongLimit in Realtime

    I'm testing a simple strategy with EnterLongLimit (isLiveUntilCancelled = true) which works fine on historical bars but in realtime "Long Limit Entry" keeps shifting right each time a new bar arrives. I realise I may need to provide more but just checking if this is an easy fix?

    #2
    Hello dibDab

    That would be correct, isLiveUntilCancelled prevents orders from cancelling if not filled. If the order did not fill then it would continue as the bars do. Are you expecting the order to have cancelled after 1 bar?

    JesseNinjaTrader Customer Service

    Comment


      #3
      I think you've answered my question, thank you.

      I was expecting the "Enter Long Limit" to stay on the bar it was created but I understand it will keep stepping right until executed?

      Comment


        #4
        Hello dibDab,

        Right, only a filled order would be displayed on a specific bar and not move. Open orders are not associated with a specific bar because its not filled yet and has no specific time for a fill yet. Once that order fills it would be marked on the bar where the fill happened based on the time of the orders fill.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Looks like I'm doing something incorrect ...

          I EnterLongLimit(sLiveUntilCancelled = true) and historically that works ok and I get OnExecutionUpdate to confirm as expected.

          but in real-time it moves along another few bars and then gets executed on a bar whose OHLC is above the displayed limit.

          do I still need to cancel the EnterLongLimit after execution?​

          using PlayBack also seems to work ok but I get execution on same price but on the previous bar?
          Last edited by dibDab; 10-26-2022, 06:34 AM.

          Comment


            #6
            Hello dibDab,

            OnExecutionUpdate would only be called once that limit order fills.

            In historical data you are using only the OHLC of the bar series for fills using the historical fill engine which may work differently that realtime orders. Realtime orders are using live data to fill. When using limit orders the price is guaranteed, but the filling of the order is not. Limit orders will be executed only if the price meets the order qualifications.

            In realtime if the order has not filled you should see that the order just remains working and if bars close the order marker would continue to progress along and show up until filled.

            You wouldn't need to cancel the order after execution, you actually can't cancel an already executed order because it has filled and that would cause an error. You would only need to cancel the order if it has not filled yet and you no longer want the order to exist.

            Playback is also a realtime mode using the sim fill engine, you should see similar results as you do in realtime when playing forward. I am not sure what you mean that you get an execution on the same price but on the previous bar. The working order should show up and remain working until filled. once filled that order has a filled timestamp, depending on the time it filled it will show up on a specific bar.





            JesseNinjaTrader Customer Service

            Comment


              #7
              thanks. Getting there slowly.

              Trying to setup something simple (see below) so I can watch in realtime

              if the limitPrice < market, don't see anything and if limiPrice is hit then I see my problem?

              protected override void OnBarUpdate()
              {
              double limitPrice = 3867;

              if (IsFirstTickOfBar)
              ++elapsedBars;

              if (Count - 2 == CurrentBar && entryCnt == 0)
              {
              ++entryCnt;
              elapsedBars = 0;
              EnterLongLimit(0, true, 1, limitPrice, "Long Limit");
              }

              if (elapsedBars >= 5)
              ExitLong("Long Limit");
              }




              Last edited by dibDab; 10-26-2022, 08:46 AM.

              Comment


                #8
                Hello dibDab,

                I am not certain what problem you are seeing to advise further. If you can provide a screenshot of what you are referring to that would help.

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  just tried again and it looks ok, the signals are not moving to the right, so I'm definitely missing something here?

                  Comment


                    #10
                    Hello dibDab,

                    I don't understand what you are referring to here, you will need to provide more information such as images describing what you are seeing.

                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Just happened again when price falls to hit the limit, I get this amd the exit on the same bar (not after elapsedBars)...

                      Click image for larger version  Name:	Chart.png Views:	0 Size:	3.2 KB ID:	1220996
                      Last edited by dibDab; 10-26-2022, 09:05 AM.

                      Comment


                        #12
                        still moving to the right

                        Click image for larger version

Name:	chart2.png
Views:	69
Size:	5.3 KB
ID:	1220998

                        Comment


                          #13
                          still moving to the right

                          Click image for larger version

Name:	chart3.png
Views:	69
Size:	7.6 KB
ID:	1221000

                          Comment


                            #14
                            Hello dibDab,

                            The code you had provided earlier is incrementing for every bar so you could have an exit on the same bar as the entry fill. As soon as 5 bars had elapsed it would try to exit on every bar after that. You can use BarsSinceEntry to know how many bars happened since an entry fill: https://ninjatrader.com/support/help...barssinceentry
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              now stopped

                              Click image for larger version

Name:	chart4.png
Views:	73
Size:	13.8 KB
ID:	1221003

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rjm1903, Today, 04:14 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post rjm1903
                              by rjm1903
                               
                              Started by sidlercom80, 04-05-2021, 09:27 AM
                              7 responses
                              176 views
                              0 likes
                              Last Post Unsuitable  
                              Started by Zinger357, Today, 04:08 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Zinger357  
                              Started by sy2023, 09-15-2023, 08:51 PM
                              4 responses
                              248 views
                              0 likes
                              Last Post Crusade12  
                              Started by JosephHansen, Today, 12:35 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post JosephHansen  
                              Working...
                              X