Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Closing Partial Positions

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

    Closing Partial Positions

    Hello, I'm trying to set profit targets for partial positions based on # of contracts. Below is a section of code that seems to work, but when it puts in the order(and fills just fine) it opens, then immediately closes the profit target. I can't figure out why it simply won't keep it open.

    Code:
    if (queueShortTrade)
    {
    EnterShort(5, "MTF-Short");
    
    //First Profit Target
    ExitShortLimit(2, GetCurrentBid() - 80 * TickSize, "PT1", "MTF-Short");
    Print(GetCurrentAsk() - 80 * TickSize);
    queueShortTrade = false;
    }​
    (BTW if there's a better way to set multiple profit targets, I'm totally open to that, too)

    #2
    Hello alphatango,

    When using the managed approach each quantity you want to scale in and out should be a separate entry order with a unique signal name, and the exit orders should use the from entry signals of those entries.

    Below is a link to an example.


    If you don't want separate entries, then use the unmanaged approach instead of the managed approach so you have full control over the order quantities.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      How do I use .cs files?

      Also that would make sense. I could have the same entry signal say (pardon the syntax):
      EnterLong(1, "Pos1");
      EnterLong(1, "Pos2");
      ...

      [then]
      ExitLongLimit(1, [target calculation], "PT1", "Pos1")
      (and so on).

      Correct?

      Comment


        #4
        I will say that even splitting up the orders doesn't fix the Profit Target exit immediately canceling once the order is put in.

        Comment


          #5
          Hello alphatango,

          To import a NinjaScript into NinjaTrader 8 do the following:
          1. Download the script to your desktop, keep it in the compressed .zip file.
          2. From the Control Center window select Tools -> Import -> NinjaScript Addon
          3. Click the Desktop icon on the left to navigate to the desktop
          4. Select the downloaded .zip file -> then click Open
          5. NinjaTrader will then confirm if the import has been successful.
          Critical *Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.

          Below is a link to the help guide on importing NinjaScripts.
          https://ninjatrader.com/support/help...-us/import.htm

          Once imported, open the Strategy Builder and select ScaleOutBuilder from the Strategy drop-down.


          Also, if you are using Exit methods, these need to be submitted after the entry has filled and the position has been taken. I recommend doing this from OnExecutionUpdate().

          The ProfitCasestopTrailExitOrdersExample linked below has code that demonstrates submitting exit orders when the entry fills in OnExecutionUpdate().



          "I will say that even splitting up the orders doesn't fix the Profit Target exit immediately canceling once the order is put in."

          Enable TraceOrders to see if the order is being ignored or automatically cancelled.

          Below is a link to a support article on using TraceOrders and adding debugging output to understand behavior.


          It's possible that the order is not being re-submitted on each new bar and is being automatically cancelled due to the isLiveUntilCancelled overload parameter as true not being used.
          The TraceOrders output will show the order automatically being cancelled.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            I don't have Import > Ninjascript. I just have Import > Ninjascript Add-On. Is that the same thing?

            Comment


              #7
              Hello alphatango,

              Yes, I did mean Tools > Import > NinjaScript Addon.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              50 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              126 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              69 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              42 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