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

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 hdge4u, 04-29-2024, 12:23 PM
          5 responses
          28 views
          0 likes
          Last Post MisterTee  
          Started by llanqui, 01-25-2024, 06:15 PM
          9 responses
          64 views
          0 likes
          Last Post MisterTee  
          Started by tradingnasdaqprueba, 05-07-2024, 03:42 AM
          16 responses
          65 views
          0 likes
          Last Post tradingnasdaqprueba  
          Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
          55 responses
          5,463 views
          0 likes
          Last Post BartMan
          by BartMan
           
          Started by DawnTreader, 05-08-2024, 05:58 PM
          16 responses
          52 views
          0 likes
          Last Post DawnTreader  
          Working...
          X