Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reversing position going beyond available account contract size limit

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

    Reversing position going beyond available account contract size limit

    Suppose my account has a contract size limit of 5. My strategy has 4 contracts per entry. So, on a reversal, it creates an order of 8 contracts breaking the account limit and turns off the strategy.
    I use EnterLong for entry ExitLongStopMarket and ExitLongLimit for oco on the entry.
    EnterShort to reverse the position.

    How do I deal with this situation?

    #2
    Hello admiralpanda,

    Thanks for your notes.

    Are you calling an Exit method and Enter method in the opposite direction on the same bar update?

    Do you use Set methods and Exit methods in the same strategy script?

    Note that Managed Approach Exit methods are not tied together by OCO. If you want to have orders tied by OCO you would need to use the Unmanaged Approach.

    Have you added debugging prints to the script and enabled TraceOrders to understand exactly how the strategy is behaving and placing orders?

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Also, enable TraceOrders which will let us know if any orders are behaving and is a helpful tool for debugging.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.

    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      I don't have Exit and Enter methods in the same bar update. For Reversal I'm aware that the EnterShort or EnterLong in the opposite direction takes care of it.

      I do not use any set methods. I use ExitLongStopMarket and ExitLongLimit after an order is filled.

      Comment


        #4
        Hello admiralpanda,

        Thanks for your notes.

        Did you added debugging prints to the script and enabled TraceOrders to understand how your logic in the script is behaving?

        To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

        Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Also, enable TraceOrders which will let us know if any orders are behaving and is a helpful tool for debugging.

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Yes, I did. That is how I know it there is only one entry that is being processed.
          And this issue is only on reversals. So, if there is a position open with 5 contracts, reversing the position using the managed approach (ex: EnterShort when the existing position is Long) creates an order for 10 contracts in the opposite direction. But the limit on the account is 5 contracts.

          Click image for larger version

Name:	image.png
Views:	80
Size:	27.7 KB
ID:	1298102

          Comment


            #6
            Hello admiralpanda,

            Thanks for your notes.

            This message is an order rejection from your broker or evaluation provider stating you exceeded your maximum limit has been met.

            Please reach out to them directly as to why this order rejection message was triggered on your account to better understand why the message is occurring.

            That said, when you submit an Enter order method to reverse positions the strategy submits an order to close the long position and submits an order to enter a short position.

            If you are 5 Long and you call an Entry method in the opposite direction to reverse positions, it could be counting both the order to close the 5 Long position and the order to enter a short position of 5 Short which would be a total of 10.

            If you modify the strategy to use Exit methods to exit the long position first and then call your EnterShort() method to enter a short position, does the error persist?

            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              I haven't tried that because I read in many posts that doing so causes an overfill.
              Is there no other alternative?

              Comment


                #8
                Hello admiralpanda,

                Thanks for your notes.

                Overfills would occur if you are calling Exit methods and Enter method in the same bar update. Not if you call the Exit method and then submit the Entry order to enter a short position when you are in a flat market position.

                I suggest reaching out to your broker or evaluation provider to ask why this order rejection message was triggered on your account to better understand why the message is occurring.

                In your strategy, modify the script so that you check if you are in a long position (Position.MarketPosition == MarketPosition.Long) and call an Exit method such as ExitLong() to exit the long position. Then create a condition that checks if you are in a flat market position (Position.MarketPosition == MarketPosition.Flat) and call your Enter method to enter a short position.

                I would expect that if you change the strategy to first exit the long position with a quantity of 5 and then submit the Entry order to enter a short position for a quantity of 5, the error will not long occur.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                50 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                126 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                69 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                42 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X