Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Some orders are not closed at the end of day (ExitOnClose)

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

    Some orders are not closed at the end of day (ExitOnClose)

    Hello,

    I'm backtesting a strategy and have ExitOnClose set to true. However, some orders are not closed at the end of the day and live through the end of the session and are closed the next day (or sometimes live even longer). I have tested the strategy on 10-min TF so there can be a maximum of 84 bars each day. Some orders have, however, 150, 232 or even more. Please see the attached screenshot.

    The parameter ExitOnCloseSeconds seems to be ignored (doesn't have any influence on the backtest) and so is the TimeInForce parameter. The result is always the same.

    I'm using the Managed approach, entering Market orders in the OnBarUpdate() method and then attaching Exit limit orders as PTs and Exit stop orders as SLs in the OnExecution() method. The limit and stop orders are canceled at the end of the session but sometimes the market order lives longer.

    How is this possible? What am I missing? I'm really desperate because I don't know what's going on and the strategy is completely unusable because of this.

    Please help!
    Thanks
    Attached Files

    #2
    Hello,

    Could you post a simplified version of the strategy that replicates the problem so that I may test on my end?

    Located in (MY)Documents\NinjaTrader 7\bin\Custom\Strategy

    Which data provider have you obtained your historical data from?

    I know you said you're testing the TF 10 min and I want to verify this as the image shows FGBL as the last selected (I know this does not mean it was the instrument backtested)
    LanceNinjaTrader Customer Service

    Comment


      #3
      Thank you for your fast response! Sorry, I meant 10-min time frame, not the TF market. I'm testing on FGBL as you have correctly noticed. The historical data comes from CQG demo.

      EDIT: I seem to have found the problem, although I don't know why it doesn't work.
      I enter the market with two contracts using the method EnterLong(2, orderName). Then, upon execution of this order, I place two profit targets, each with 1 contract, using ExitLongLimit(0, true, 1, ptPrice1, ptName1, orderName) and ExitLongLimit(0, true, 1, ptPrice2, ptName2, orderName). At the same time I set a stop-loss with 2 contracts to close the position by calling ExitLongStop(0, true, 2, slPrice, slName, orderName). Please notice that the fromEntrySignal parameter is always the orderName.

      I would expect that if the SL is hit, both the PTs are canceled (which seems to work according to the trace). And then I would expect that if the first PT is hit, the SL order would be reduced to 1 contract, and when the second PT is hit, the SL would be canceled and the position closed. But this doesn't seem to work and I think this causes the problem.

      Why it doesn't work and what would be the correct approach?

      Thank you very much!
      Last edited by Equilibrix; 04-22-2013, 04:14 PM.

      Comment


        #4
        Hello,

        In this situation you would want to enter and scale out using different signal names (2 total).

        That way you would be able to tie your stops (even if at the same price) to the correct target.

        Please let me know if I can be of further assistance.
        LanceNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X