Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order rejected on a Strategy

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

    Order rejected on a Strategy

    Hi!
    I have a simple strategy on SPY, on a 5 minute timeframe were it Enters a Long position when MACD crosses above MACD(Avg) and Exits the position when the inverse occurs; and also Enters a Short Position when this latter occurs.
    Unfortunately it does the first part of the strategy, but after it has Exit the Long Position it doesn't enters the Short Position and it Rejects me the order.
    What could be going on?
    Thanks!
    Andrés

    #2
    Hello plenamar27,

    Thanks for your post.

    Please send a screenshot of the rejected order error message so we may accurately assist.

    To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.

    Click here for instructions

    Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

    Click here for detailed instruction

    Ultimately, to understand why the script is behaving as it is, such as placing orders or not placing orders 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 being ignored and not being submitted when the condition to place the orders is evaluating as true.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    I look forward to assisting further.
    <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
      Sory, it's been a while, I've been away; I hace Ninja trader linked to my Ameritrade account and on Thinkorswim the message is "Your account is not allowed to create boxed positions".
      So I guess at some point the short and the long position are overlapped.
      Is there any way that I can separate them and avoid this issue.
      Thanks!
      Andrés

      Comment


        #4
        Hello plenamar27,

        Thanks for your note.

        A “boxed Position” basically means that if you are in a position, you would not be able to use an entry order in the opposite direction to close that position. Exit orders would need to be used to close the position.

        For example, if you are in a long position, you will not be able to use a short entry order to exit that long position. You would need to use a long Exit order, such as ExitLong(), to exit that long position.

        You would need to use debugging prints to understand how your strategy is behaving and placing orders. Then, you would need to separate the Long and Short entry/exit order logic in your script to ensure that long positions are not closed by a short entry order. And, that short positions are not closed by a long entry order.

        Note that in NinjaScript, Entry order methods, such as EnterLong()/EnterShort(), will reverse a position. For example, if you are in a position of 3 long and EnterShort() is called, the strategy will close the 3 long positions and then place 3 sell orders so that you end up in a position of 3 short.

        NinjaTrader strategies operate independently from other strategies and your account position. You can run multiple strategies against one account, although your account position will reflect activity from all strategies submitting orders to the account.

        See the forum post linked in post #2 for information about using prints for debugging.

        Let us know if we may assist further.
        <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
          So, for what you are saying I could use "Enter Long" and "Enter Short" only for my strategy?
          Thanks, Andrés

          Comment


            #6
            Hello plenamar27,

            Thanks for your note.

            EnterLong and EnterShort are not the only order entry methods you could use. Any order entry method should be available for you to use.

            You would need to ensure that you are not in a long position when calling your short order entry method. Similarly, you would need to ensure that you are not in a short position when calling your long order entry method.

            Something you could consider is checking the MarketPosition (Position.MarketPosition == MarketPosition.Flat) in your order entry conditions to ensure you are in a flat position before placing an order.

            See this help guide page for more information about Position.MarketPosition: https://ninjatrader.com/support/help...etposition.htm

            Let us know if we may assist further.
            <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
            38 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            124 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            64 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            41 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