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

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.
    Brandon H.NinjaTrader Customer Service

    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.
        Brandon H.NinjaTrader Customer Service

        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.
            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by dward123, 01-02-2024, 09:59 PM
            4 responses
            174 views
            0 likes
            Last Post Lancer
            by Lancer
             
            Started by ETFVoyageur, Today, 04:00 PM
            2 responses
            19 views
            0 likes
            Last Post ETFVoyageur  
            Started by AaronKTradingForum, Today, 03:44 PM
            1 response
            8 views
            0 likes
            Last Post AaronKTradingForum  
            Started by Felix Reichert, 04-26-2024, 02:12 PM
            11 responses
            80 views
            0 likes
            Last Post Felix Reichert  
            Started by junkone, 04-28-2024, 02:19 PM
            7 responses
            83 views
            1 like
            Last Post junkone
            by junkone
             
            Working...
            X