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

EnterLong/ExitShort in 1 Trade

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

    EnterLong/ExitShort in 1 Trade

    Greetings,

    I have a simple 2-SMA crossover system in which you are in 100% of the time, either long or short. My question is, when a crossover occurs, instead of triggering 2 separate orders to exit 1 position and enter the opposite, how can I enter the opposite at double the quantity, effectively taking the opposite position and closing the previous position without having to send 2 separate orders and double the commissions?
    Thank you,
    hbmiles2000

    #2
    hbmiles2000, the Enter() methods of the managed mode would always automatically reverse for you, that's what you see here - in the unmanaged mode you could simply SubmitOrder() the needed qty to reverse in one order.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand- thanks; so in the managed mode, just use an enter into the opposite position with more quantity than the previous position and perform no exits - that should work?
      Thx,
      hbmiles2000

      Comment


        #4
        That would work in the unmanaged mode, but in managed you would still see the closing position order then for one you currently have before submitting the reverse order.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Bertrand- I have used the code below (example for long side - opposite for short side). When I backtest, the results show a heavy number of one type of position (i.e. long vs. short), when they should be even. The variable x is to determine if this is the first trade, in which only the specified number of contracts will be entered. Once x>0, the amount of contracts is double in the opposite direction.
          if(x==0) {
          entryOrder = SubmitOrder(
          0, OrderAction.Buy, OrderType.Market, Contracts, 0, 0, "", "");
          x=x+
          1;
          }
          if (x>0) {
          entryOrder = SubmitOrder(
          0, OrderAction.Buy, OrderType.Market,(Contracts*2), 0, 0, "", "");

          x=x+
          1;

          Comment


            #6
            hbmiles2000, you would need to debug your code and order placement to see if the qty's fit as you expect, please keep in mind that you're in the unmanaged mode here so there would be limited signal tracking done, it would literally submit the exact order you program into SubmitOrder(). You also want to take care the IOrders are nullified as needed.
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by rocketman7, Today, 02:12 AM
            5 responses
            23 views
            0 likes
            Last Post rocketman7  
            Started by trilliantrader, 04-18-2024, 08:16 AM
            7 responses
            28 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by samish18, 04-17-2024, 08:57 AM
            17 responses
            66 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by briansaul, Today, 05:31 AM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by PaulMohn, Today, 03:49 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X