Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

code for close position?

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

    code for close position?

    Even tho I sync my auto trader strategy to my live account I still get overfill errors because the auto trader thinks a poaition is open. For example I have the strategy to trade one contract per trade but if I start the strategy mid day with no open orders it will see that it should be in a long position one contract but in reality I have no open position. So when it goes to sell the long position it puts a sell order in to cover the long position then another sell order for the new trade. So I now have two contracts in a short position when I should only have one. This happens when I start the strategy mid day or manually edit orders myself. If I made the strategy close the position before it made a buy or sell order would this solve my issue? I wand the strategy to trade let's say one contract but I want to be able to add or subtract from my position and when it comes order trigger time I would like the strategy to close all contract positions not just one contract how can I do this? Thanks

    #2
    olingerc, please first of all ensure to read those two links below on how the strategy vs account position sync is handled in NinjaTrader, if you just would like to take the first freshly generated entry after starting the strategy up using 'WaitUntilFlat' would be what you seek :





    Thanks,
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks those links did a lot to help clear up my confusion If I understood them correctly. Basically if Im running a strategy and I get disconnected for some reason and I have the check box "Wait until flat" checked with my account synced then on start up it it will cancel any open orders that were previously made and start fresh from a flat position. To me that's a horrible scenario.

      Immediately submit live working orders with account position synced will NOT cancel the orders that the strategy made before lets say a power outage or disconnection. It will basically pick up right where it left off assuming the orders have not changed.


      And If I want to place manual orders "outside" of the strategy I can't have the accounts synced because the strategy will always try to correct the position if its synced.

      If I understood this correctly I want the 2nd option. Thanks


      I hope I have this all right. I will have to play test it out over the next week or so just to make 100% sure it's the way I want.

      Thanks.

      Comment


        #4
        You're welcome, correct those are the two options to start a strategy up for realtime trading use - you can have manual orders executed to the same account as long as the currently held strategy position is present in the account as well, as otherwise resulting position changes executed from the strategy would not resulting in trades taken on your account as you intend to. Should you wish to manually change strategy created orders such as stoplosses or profit targets then using ATM templates in your NinjaScript strategy would be the way to go.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Im having a huge huge issue. I was trading with my strategy live today. I have the Immediately submit live working historical orders box checked and My account is not synced. I started the strategy with the live account while my position was flat in the beginning of the day. A buy signal came along and it fired off buying 2 contracts 1331.50. At this point everything looks normal. It came to a sell signal and the strategy did this It sold 1 contract at 1331.75 and then 1 more at 1331.75 and then sold 2 at 1331.75 to "close position" and then sold 2 more at 1331.75 as the normal sell position.

          My strategy is set up to only submit orders of 2. Why did I get two orders of 1 and then my normal order?

          Here is the simple code:

          // Condition set 1
          if (CrossAbove(EMA(57), SMA(226), 1))
          {
          EnterLong(2, "");
          ExitShort("", "");
          }

          // Condition set 2
          if (CrossBelow(EMA(67), SMA(222), 1))
          {
          ExitLong("", "");
          EnterShort(2, "");
          }
          }
          }



          Clearly I have it set to buy and sell in orders of 2. Why did it sell two single orders of 1 contract, THEN close the position and then enter a short position of 2 like the strategy says. I am so confused here.

          Comment


            #6
            olinger,

            Please see my reply in the new thread you created for this. If you have any further questions, reply back to the new one.
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by MacDad, 02-25-2024, 11:48 PM
            7 responses
            158 views
            0 likes
            Last Post loganjarosz123  
            Started by Belfortbucks, Today, 09:29 PM
            0 responses
            7 views
            0 likes
            Last Post Belfortbucks  
            Started by zstheorist, Today, 07:52 PM
            0 responses
            7 views
            0 likes
            Last Post zstheorist  
            Started by pmachiraju, 11-01-2023, 04:46 AM
            8 responses
            151 views
            0 likes
            Last Post rehmans
            by rehmans
             
            Started by mattbsea, Today, 05:44 PM
            0 responses
            6 views
            0 likes
            Last Post mattbsea  
            Working...
            X