Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position incorrectly exits at specific time

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

    Position incorrectly exits at specific time

    I have a position that is closing every day on the 23:00 bar, which is not what I would expect to be happening.

    Here is an example:

    On 13 June an Entry Order was placed & triggered:
    Output Window
    6/13/2014 9:00:00 AM Entered internal PlaceOrder() method at 6/13/2014 9:00:00 AM: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.4425 SignalName='BreakoutLong' FromEntrySignal=''
    I can not find anywhere in the Output window about the order being closed, but the screenshot of the chart will show that it was and you can see that it closes every trade at the same time following thereafter.

    I do have this area that says, "Cancel the LongEntry order at 22:00 if it is not yet filled."
    Code:
    				// Cancel Entry Orders if not filled by certain time
    				if (ToTime(Time[0]) >= ToTime(removeOrderHr, removeOrderMin,0)
    					&& LongEntry != null)
    				{
    					CancelOrder(LongEntry);
    					LongEntry = null;
    				}
    When I comment this section out it does not change the fact that the order was removed at the same time

    I am attaching the updated code because I am not sure what other areas of the code could possibly be causing these to close like that.

    Additionally, my stop & limit orders are being removed too soon.

    The Output Window says they are being removed at inconsistent times despite the TIF being GTC. I have not written any code to cancel the Stop & Limit orders. Therefore they should not be cancelling unless the Entry Order is hit or when the trade closes out at a profit or a loss.

    Here it says that they were cancelled at 10:00 AM
    6/13/2014 10:00:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00004/Sim101' Name='LongStop' State=Working Instrument='$EURAUD' Action=Sell Limit price=0 Stop price=1.43735 Quantity=0 Strategy='LondonBreakout' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='0812d17565914b98a7426e0d8cb8f65d' Gtd='12/1/2099 12:00:00 AM'
    Here it says that they were cancelled at 2:00 PM:
    6/16/2014 2:00:00 PM Cancelled expired order: BarsInProgress=0: Order='NT-00008/Sim101' Name='LongStop' State=Working Instrument='$EURAUD' Action=Sell Limit price=0 Stop price=1.43805 Quantity=0 Strategy='LondonBreakout' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='1d77a2b5598e447ca68f3f4ab330888c' Gtd='12/1/2099 12:00:00 AM'
    Here it says that they were cancelled at 12:00 PM:
    6/19/2014 12:00:00 PM Cancelled expired order: BarsInProgress=0: Order='NT-00020/Sim101' Name='LongStop' State=Working Instrument='$EURAUD' Action=Sell Limit price=0 Stop price=1.4439 Quantity=0 Strategy='LondonBreakout' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='065670e198d540c1a7a1bec87e237736' Gtd='12/1/2099 12:00:00 AM'
    Thank you very much for your help to point me in the right direction
    Attached Files

    #2
    jg123,

    Thank you for your post.

    For the position exiting everyday, this is because you have ExitOnClose set to true when running the strategy. You can set this false so that the position carries over to the next day and so on.

    The messages you are receiving are from the orders being cancelled at the end of the bar as this the default with the Managed Approach. Unless, the condition is true for the next bar in the back test processing, it will cancel the order which is what you see happening. When you submit these orders you can use the overload property to have these orders live until cancelled.
    http://www.ninjatrader.com/support/h...r_handling.htm
    http://www.ninjatrader.com/support/h...d_approach.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Thank you very much. That was very helpful

      Now it is not taking trades that it should be taking. The Output Window says
      6/16/2014 9:00:00 AM Ignored PlaceOrder() method at 6/16/2014 9:00:00 AM: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.4435'5 SignalName='BreakoutLong' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
      Therefore I have gone in and adjusted the order handling. This is what i have written in my Initialize() section
      Code:
      			EntriesPerDirection = 5;
      			EntryHandling = EntryHandling.AllEntries;
      I do not need 5 entries in one direction, but I put it like that to insure that the testing was not getting limited by too few allowable entries. Unfortunately, this did not fix my problem with only allowing one entry at a time.

      Comment


        #4
        Jg123,

        The ignore message indicates that the condition to submit another entry order was ignored because you are already in a position for that direction. If you only want one position then you would want to EntriesPerDirection = 1;

        Otherwise you can use Position.MarketPosition == MarketPosition.Flat for your entries so that they only submit when you are flat.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Sorry, Cal. I didn't quite make clear what I was asking for.

          I want it to enter a new position if I am already in the position. It is supposed to enter a new position every day, even if it is still in the previous day's position. So I need the order handling to open up to allow for multiple entries in the same direction.

          I have written in the code elsewhere to insure that it is only one trade entered per day so that it will not overfill me. I am attaching the code so that you can see it in case I am thinking through my coding incorrectly.

          Thank you very much for your help!
          Attached Files

          Comment


            #6
            Jg123,

            I tested the script it does indeed scale in the positions, however, I got a OnExecution error that an object was not set to a reference.

            Since, you now adding additional positions you would need to ensure that you are tracking the correct objects and check for Null in the method
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Thanks Cal

              That is really interesting that we are getting something completely different. I did a brand new export when I sent that to you so it is the updated code that I have. I have recompiled it and am sending it again. Also, I am attaching a screenshot showing a trade that should have been placed (The first arrow & circle shown is the one that should have placed....the second one would not have placed as my TrendDirection is set to "Up" currently, so this is just showing on the chart for my personal debugging reference)

              I am also attaching a copy of my Output Window so that you can see that I am not getting that same error message that you are.
              Attached Files

              Comment


                #8
                Jg123,

                Who are you connected to? Displayed in the lower left hand corner of the Control Center

                What are the settings you are applying to your strategy?

                How many days are you loading for the chart?
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Cal View Post
                  Who are you connected to? Displayed in the lower left hand corner of the Control Center
                  Interactive Brokers

                  Originally posted by NinjaTrader_Cal View Post
                  What are the settings you are applying to your strategy?
                  Only Forex
                  For this part of debugging, I am using these settings:
                  6/19/2014 2:00 AM
                  9
                  0
                  Up
                  22
                  0
                  1
                  0.0005

                  Originally posted by NinjaTrader_Cal View Post
                  How many days are you loading for the chart?
                  60 Min Chart with 10 Days loaded

                  Comment


                    #10
                    Jg123,

                    I am not sure why the order is not getting placed, as I am getting different results on my end, which could be do to the time difference between us.

                    My advice would be to place some Print() statements throughout the script and check that your values and conditions are being met.
                    Cal H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    646 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    367 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    108 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    569 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    573 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X