Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Having Trouble Backtesting a Strategy

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

    Having Trouble Backtesting a Strategy

    // Unrealized
    if (acct.Positions != null)
    {
    UnRealizedPNL = 0;
    PositionCollection positions = acct.Positions;
    foreach (Position pos in positions)
    {
    UnRealizedPNL = UnRealizedPNL + pos.GetProfitLoss(Close[0], PerformanceUnit.Currency);
    }
    // Condition set 2
    if (UnRealizedPNL >= Profit)
    {
    ExitLong("", "Long");
    ExitShort("", "Short");
    }
    }
    }
    [/CODE]
    Last edited by sampras010; 03-18-2016, 05:18 AM.

    #2
    Hello,
    I would not expect and of the orders to submit as the ES 04-16 is not a valid contract. The ES uses March, June, September, and December contract months.
    Do you receive the same if you use the ES 03-16?
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by sampras010
      I fixed the contract month, but still the same result. Longs are taken for the primary contract, but no shorts in the ES.


      You need to read all of this, especially the last one, " Entering, Exiting and Retrieving Position Information".

      You need a BarsInProgress check for the 1st instrument == 0... You are trying to do everything on BarsInProgress == 2 for ES 03-16.

      I'm surprised your not Long 4 at that point. (8-4)

      Comment


        #4
        Hello,
        Sledge is correct in that you will need to have your Entry conditions for the secondary instrument within BasrsInProgress ==2.
        Please let us know if you receive the same after implementing this.
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          Hello,
          You need to run the ExitShort on BarsInProgress == 2. The code you have now has it trying to exit for BarsInProgress == 0. The reason the strategy closes the short at the session close would be do to select ExitOnClose to True when you apply the strategy.

          You can add the BarsInProgress as an overload for your order using Advnaced Order Handling. Please see the following link on the Advanced Order Handling, specifically working with a Multi Instrument Strategy: http://ninjatrader.com/support/helpG...r_handling.htm

          You could use the following overload for the ExitShort()
          ExitShort(2, quantity, " " , Short);

          You will need to add in the BarsInProgress argument for your entry orders as well so that the profit and loss of the main instrument and the ES 03-16 are not added together.
          Cody B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          576 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          553 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X