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

Got Longs right... Shorts won't work?

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

    Got Longs right... Shorts won't work?

    Okay well we finally figured this out. Shout out to j2algotrader.com and John for helping with this.

    When attempting to close all contracts at once the value needs to be set to 0. When left as default it would sometimes close all and sometimes not. Which was where the headache was coming from. I feel stupid after we finally found it but we did.

    Thanks to everyone who helped with my issue I appreciate everyone's times.​
    Last edited by RyanCathcart; 07-09-2023, 06:20 PM.

    #2
    Hello RyanCathcart,

    Thank you for your post.

    The first step I would suggest to debug and better understand your script is to enable TraceOrders in State.SetDefaults (or, if you are using the Strategy Builder, enable it via the checkbox on the Default Properties screen). For more information about TraceOrders:


    Next, check both the NinjaScript Output window as well as the Log tab of the Control Center for information regarding orders submitted by your strategy as well as any error messages that might offer a clue as to why the strategy is not behaving as you'd expect for short orders.

    Additionally, if only 1 contract is open at a time and additional contracts aren't being added, this may have to do with your selection for "Entries per direction" or "Entry Handling" in your strategy properties. These properties may also be set programmatically in State.SetDefaults or State.Configure:You could try adjusting these properties and then test your strategy to observe the behavior and see if it changes to what you are expecting.

    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      I found it... I had my close position signaled backwards. Was using same setup as my longs so it was triggering every time with the sell order.

      On another note when it closes position even for a profit the on screen display is "buy to cover" is that normal?

      Thanks for your help

      Comment


        #4
        And I am lost again....
        Shorts are now taking multiple trades like they are supposed to. I just watched in real time on my sim 30+ futures contracts were open, Hits the target for close shorts condition and it says "buy to cover" and some how ends up with 8 contracts in a long. (The trade was over 1000 green)
        For my longs side this never happens, just hits the target and closes all contracts.

        I am currently running a test on the shorts with a low take profit to see if it closes correctly in this case. (edited) And this hit the "profit target" and closed all 6 contracts.

        Like I said I am new to this. I don't even know what I am looking for.

        Thanks to all who may have insight on this.
        Last edited by RyanCathcart; 07-06-2023, 05:15 AM.

        Comment


          #5
          Hello RyanCathcart,

          Thank you for your reply.

          As a rule of thumb, when closing a long position the action is "Sell" and when closing a short position the action is "Buy to cover." This is normal and expected behavior. You mentioned that the target is hit to close shorts, yet you end up with 8 contracts in a long. What type of exit is your target to close shorts? Are you also calling ExitShort() in the strategy? This could potentially result in an unwanted position. When using the Managed Approach, there are internal order handling rules to prevent unwanted positions, though the rules do not apply to market orders like ExitLong() and ExitShort(). The rules may be found in the help guide here:It could be that your target order is already exiting the position, or you are entering in the opposite direction which also automatically reverses a position. This is noted in the help guide, "Entry() methods will reverse the position automatically. For example if you are in a 1 contract long position and now call EnterShort() -> you will see 2 executions, one to close the prior long position and the other to get you into the desired 1 contract short position."

          Please review your script for any market orders, such as ExitShort() or EnterLong(), at the time your target hits to close the short positions. This may help to narrow down the behavior and modify your script as needed.

          Otherwise, you could consider enabling TraceOrders as previously mentioned to see which order methods are being processed which should also help to narrow down the cause of the behavior and better understand the actions of your strategy.

          Thank you for your time and patience.
          Emily C.NinjaTrader Customer Service

          Comment


            #6
            Okay well we finally figured this out. Shout out to j2algotrader.com and John for helping with this.

            When attempting to close all contracts at once the value needs to be set to 0. When left as default it would sometimes close all and sometimes not. Which was where the headache was coming from. I feel stupid after we finally found it but we did.

            Thanks to everyone who helped with my issue I appreciate everyone's times.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,406 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by Shai Samuel, 07-02-2022, 02:46 PM
            4 responses
            98 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by DJ888, Yesterday, 10:57 PM
            0 responses
            8 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by MacDad, 02-25-2024, 11:48 PM
            7 responses
            160 views
            0 likes
            Last Post loganjarosz123  
            Started by Belfortbucks, Yesterday, 09:29 PM
            0 responses
            9 views
            0 likes
            Last Post Belfortbucks  
            Working...
            X