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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X