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

Problem with contract quantity

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

    Problem with contract quantity

    I have a strategy that identifies entry and exit signals as well as dynamically setting the quantity for the order placement. For example:

    int numberOfContracts = accountSupports;
    if (longCondition) {
    EnterLong(numberOfContracts, "")
    }

    The first time this enters a trade, the correct quantity is entered, say 1. The next time it enters a trade, it enters a quantity of 2 even if the value of accountSupports is still only 1. The third time it enters, it will use quantity of 3, despite accountSupports still being 1.

    I have confirmed that the value of numberOfContracts is correct by printing the current value to the output log immediately before calling EnterLong, and despite it being set at 1 on each execution, the quantity for each entry appears to be accumulative.

    I've confirmed this by manually setting the "numberOfContracts" to 1, in which case each subsequent trade quantity goes up by 1, and then setting it to 2, in which case each subsequent trade goes up by 2.

    Is there something that my code needs to handle differently, or is this a bug?

    I would have expected that if I hardcode this value to say 2, that every trade enters a quantity of 2. Any suggestions?

    #2
    Hello poorhatsoap,

    Thank you for writing in and welcome to the NinjaTrader Support Forum!

    I would not expect the quantity for your order entry to increase if numberOfContracts remains at 1. A quantity of 1 should be submitted upon every call of EnterLong().

    Are you testing this on a chart, through the Strategy Analyzer, or the Strategies tab in the Control Center?

    If testing on a chart, please right-click on the chart and select Strategy Performance -> [your strategy name] -> Historical & Real-time. Then, select the Executions tab. What is the order quantity of each Buy execution?

    If testing through the Strategy Analyzer, select the Executions tab after running your test. What is the order quantity of each Buy execution?

    If testing through the Strategies tab, right-click your strategy and select Strategy Performance -> Historical & Real-time. What is the order quantity of each Buy execution?
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply.

      I've set up a debugging strategy to generate test data quickly, and used the same approach for quantity. Please refer to the screen shot attached - in each OnBarUpdate the 'numberOfContracts' is hard coded to 2.

      If I'm misinterpreting the information provided, I'm happy with an explanation, but it seems to me that in any long or short position I'm accumulating more and more contracts during sim testing.
      Attached Files

      Comment


        #4
        Hello poorhatsoap,

        Can you please provide your debugging script so I may take a look at it on my end?

        To export your script do the following:
        1. Click File -> Utilities -> Export NinjaScript
        2. Enter a unique name for the file in the value for 'File name:'
        3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
        4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


        By default your exported file will be in the following location:
        • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


        Below is a link to the help guide on Exporting NinjaScripts.
        http://www.ninjatrader.com/support/h...nt7/export.htm
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          The debug strategy is attached. Thanks for looking into this.

          This strategy will basically alternate between long entry and short entry every 5 bars, with a hardcoded quantity of 2 contracts. Run it on a 1 minute chart against ES/FDAX etc. and hopefully you'll see the issue that I'm reporting. The quantity seems to be all over the place.
          Attached Files
          Last edited by poorhatsoap; 08-11-2016, 11:08 PM.

          Comment


            #6
            Hello poorhatsoap,

            It doesn't look like I'm able to see this behavior on my end when testing on an FDAX 09-16 1 minute chart. The order quantity remains at 2 in all executions.

            I'm not seeing anything in your syntax that would explain the behavior.

            I do want to note that it is not necessary to call ExitLong() before EnterShort() and ExitShort() before EnterLong(). Calling EnterShort() while in a long position will automatically close out of the long position for you and enter short. Alternatively, calling EnterLong() while in a short position will automatically close out of the short position for you and enter long.

            Please follow the instructions below to reset the NinjaTrader database. (This can take long depending on the size of your database file and your system.)
            • Disconnect NinjaTrader from any open connections via File > Disconnect.
            • From the NinjaTrader Control Center window select the menu Tools > Options.
            • Select the 'Data' tab.
            • Press the 'Reset DB' button.
            • Press the 'OK' button.


            The following data will be removed.
            • Historical orders.
            • Historical executions.
            • Historical ATM strategy data.
            • Saved Strategy Analyzer backtest results.


            The following data will be maintained.
            • ATM strategy templates.
            • Historical chart data.


            Once the database has been reset, please test once more. If you're still seeing this behavior occur, please clarify if these order submissions occurred during real-time or historically.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Hi Zachary. Thank you very much for taking the time to look at this. Interestingly, after removing the ExitLong and ExitShort commands and just using the EnterShort and EnterLong commands to automatically cancel the existing positions, the debugging strategy has shown improvement. I've quickly updated my real strategy the same way, and will leave it running overnight - I'm fairly confident that I'll get similar results. I'll post a further update tomorrow.

              Thank you again.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by geddyisodin, Yesterday, 05:20 AM
              8 responses
              49 views
              0 likes
              Last Post geddyisodin  
              Started by DayTradingDEMON, Today, 09:28 AM
              3 responses
              19 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by Stanfillirenfro, Today, 07:23 AM
              9 responses
              23 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by George21, Today, 10:07 AM
              0 responses
              8 views
              0 likes
              Last Post George21  
              Started by navyguy06, Today, 09:28 AM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X