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

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
    Chris L.NinjaTrader Customer Service

    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 franatas, Today, 07:23 AM
      0 responses
      2 views
      0 likes
      Last Post franatas  
      Started by laocoon, Today, 06:26 AM
      0 responses
      8 views
      0 likes
      Last Post laocoon
      by laocoon
       
      Started by Lance El Camino, 02-28-2024, 06:51 PM
      9 responses
      36 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by philmg, Today, 06:21 AM
      0 responses
      6 views
      0 likes
      Last Post philmg
      by philmg
       
      Started by RookieTrader, Today, 06:16 AM
      0 responses
      5 views
      0 likes
      Last Post RookieTrader  
      Working...
      X