Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to exit at Position.Quantity without specifying a signal

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

    How to exit at Position.Quantity without specifying a signal

    Hi NT8,

    I have about 6 different entry signals "1" "2" ... etc. But I am having trouble ensuring they all exit at once when I trade live with real money. As in, when I run the same strategy on a sim account on the live market, my code works just fine, the script exits all contracts when intended, but with live contracts/money sometimes I end up with contracts still in the market as if that signal did not take the intended exit.

    I can get around this by simply having code that ensures an exit for all contracts for my total position regardless of the signal.

    how would I modify the following to ensure this:

    if (LongExit()
    )
    {
    ExitLongLimit(Convert.ToInt32(Position.Quantity), GetCurrentAsk(0), "", "");
    }


    #2
    Hi Austiner, thanks for posting. The Position.Quantity represents the total position of the strategy. Its not expected for a live strategy to work differently from a simulated strategy. Check the Log tab of the Control Center for any messages from this strategy while you were running it on your live account. Also turn on Trace Orders for the strategy to track each order it takes:


    Kind regards,
    -ChrisL

    Comment


      #3
      Hello Austiner87,

      You can exit a position without using Position.Quantity. I would also check if I'm in a position. For example:

      Code:
      int barsSinceEntry = BarsSinceEntryExecution();
      int barsSinceExit = BarsSinceExitExecution();
      
      // Check if we're still in position.
      if ((barsSinceEntry >= 0 && barsSinceExit < 0) || (SystemPerformance.AllTrades.Count > 0 && barsSinceEntry <= barsSinceExit))
      {
          // Exit Long Position
          ExitLong();
      }
      I hope this is helpful.

      I build useful software systems for financial markets
      Generate automated strategies in NinjaTrader : www.stratgen.io

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      53 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X