Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Closing position issue.

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

    Closing position issue.

    Hello, NT Support.

    I'm developing a strategy and take it slow, step by step so that wouldn't have any issues. But I'm having an issue at the very first step

    The strategy uses additional series of 1 min candles and main series of Daily candles (built from those 1m Candles in the moment of importing data). The instrument is 6E - Euro FX futures on CME (or alternatively the same applies for EURUSD spot).

    So I started with just the long signal (enterLongStop on the level of pattern breakout) and tried to close position at the end of the same daily candle (exactly for that I added 1 min candles, so that I could apply Exit on close = true when setting up backtesting in GUI; so there's no code in strategy (for now) that uses update of 1 min candles, all the code is under
    if (BarsInProgress == 0){}.

    So the issue is:
    In many cases I have exit happened BEFORE entry.

    Here's sample of executions tab from strategy:
    Click image for larger version

Name:	executions.PNG
Views:	1
Size:	17.4 KB
ID:	898356
    One thing I noticed here is that IDs of orders look to be right (0 for entry, 1 for exit), but again you can still see that exit happened earlier.

    And here's the chart where you can see the same issue:
    Click image for larger version

Name:	chart.PNG
Views:	1
Size:	2.6 KB
ID:	898357

    I'm wondering if I'm doing something wrong, and how at all is that possible? Looks like some dangerous bug...

    Thanks for your help beforehand.

    #2
    Hi danilam, thanks for the post - ExitOnClose would be an intra-day only property - so even adding the bars series here would not help unfortunately, you would really need to execute the trades on the 1 minute series to be able to get access to the lower then daily timestamps to process orders in the correct sequence.

    Comment


      #3
      Hello,
      I'm looking to doing someting like damilan: I want enter in the market in the begin of the bar by setting an EnterLongLimit or EnterShortLimit order on the end of the previous bar and exit on the end of the same bar. But I don't know how exit.

      protectedoverridevoid Initialize()
      {
      CalculateOnBarClose =
      true;
      }
      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      // Condition set 1
      if (Open[0] < Close[0])
      {
      EnterLongLimit(1, High[
      0] + 1 * TickSize, "");
      }
      }

      Is there a way to handle this exit ?

      Thanks for now.

      Michel

      Comment


        #4
        Michel, you could simply exit on the next bar then by checking BarsSinceEntry, but if you would like to exit before the bar actually closes - then add a finer series to get access to even finer timestamps then your main bar ( for example if you trade 5 min, you can add a 10 sec bar to exit then 10 seconds before the main bar close ).

        Another option is to exit on the FirstTickOfBar, which is essentially the closing tick of the bar, since NT is an event based framework.

        Comment


          #5
          Thank you very much!

          Comment


            #6
            Hello, Bertrand. Thanks for your advice.
            I've tried to implement closing position manually through 1min series by:

            if (BarsInProgress == 1)
            {
            // Close position at the end of daily bar
            if (Times[1][0] == Times[0][0])
            {
            ExitLong();
            Print("Daily: " + Times[0][0] + "; 1m: " + Times[1][0]);
            }
            }

            and also have set ExitOnClose = false in code.

            But the problem sill persists. On the very first trade we got exit earlier than entry:
            Click image for larger version

Name:	executions.PNG
Views:	1
Size:	6.8 KB
ID:	865001

            I tried to understand the problem (maybe I was using dates/times wrongly?) and for that added that line: Print("Daily: " + Times[0][0] + "; 1m: " + Times[1][0]);

            However, I don't see any problems there, dates/times match:
            (including the first trade)
            start
            Daily: 2/2/2000 11:00:00; 1m: 2/2/2000 11:00:00
            Daily: 2/9/2000 11:00:00; 1m: 2/9/2000 11:00:00
            Daily: 2/15/2000 11:00:00; 1m: 2/15/2000 11:00:00
            Daily: 2/18/2000 11:00:00; 1m: 2/18/2000 11:00:00
            Daily: 2/24/2000 11:00:00; 1m: 2/24/2000 11:00:00
            Daily: 2/25/2000 11:00:00; 1m: 2/25/2000 11:00:00
            Daily: 3/1/2000 11:00:00; 1m: 3/1/2000 11:00:00
            Daily: 3/2/2000 11:00:00; 1m: 3/2/2000 11:00:00
            Daily: 3/22/2000 10:00:00; 1m: 3/22/2000 10:00:00
            Daily: 4/4/2000 9:00:00; 1m: 4/4/2000 9:00:00
            Daily: 4/5/2000 9:00:00; 1m: 4/5/2000 9:00:00
            Daily: 4/6/2000 9:00:00; 1m: 4/6/2000 9:00:00
            Daily: 4/7/2000 9:00:00; 1m: 4/7/2000 9:00:00
            Daily: 4/11/2000 9:00:00; 1m: 4/11/2000 9:00:00
            Daily: 4/19/2000 9:00:00; 1m: 4/19/2000 9:00:00
            Daily: 4/20/2000 9:00:00; 1m: 4/20/2000 9:00:00
            Daily: 5/5/2000 9:00:00; 1m: 5/5/2000 9:00:00
            Daily: 5/9/2000 9:00:00; 1m: 5/9/2000 9:00:00
            etc.

            If possible I'd like to know what causes the issue and how do you think I can properly close position at the End of the higher TF candle.

            Things would be much easier if we'd had simple command to exit on the close of current bar.

            Thanks.

            Comment


              #7
              danilam, this would unfortunately not work, as you detect the times are equal, you're already acting too late here for an intraday exit as desired, you would need to exit for example at 1614 on the 1 min series so the day's session is not closed yet.

              Comment


                #8
                I changed closing condition to

                if (Times[1][0] >= Times[0][0].AddMinutes(-5))

                and there's still an issue. The position is closed before it's opened. 1 day before to be exact. Is that alright?

                Comment


                  #9
                  danilam, would you mind if I tested with your exact script on my end here? You can contact me directly at support at ninjatrader dot com

                  Thanks,

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  663 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  376 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  110 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  575 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  580 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X