Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"ExitLong" error when closing position Unmanaged

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

    "ExitLong" error when closing position Unmanaged

    "ExitLong" error when closing position Unmanaged

    Hello good morning.

    Thanks for reading me in advance!

    I have a problem and I am not finding clear information or examples to solve my next problem for my strategy.

    Before I closed my positions at the end of "X" hour with the order

    ExitLong(6, @"END LONG", "");

    Now I get 1 message "Where it is not possible to use ExitLong"

    ninjatrader message:

    Strategy 'XEL': Error on calling 'OnBarUpdate' method on bar 81077: Strategy 'XEL >> /251737744': Method 'ExitLong' can't be called on unmanaged strategies.

    Thanks again for reading me...!!!

    And sorry for the inconvenience, I hope someone can help me please.

    Code:
    if ((Times[0][0].TimeOfDay > HORA_END.TimeOfDay) && (TRADING_RUN_OFF == true))
        {
    
            if (Position.MarketPosition == MarketPosition.Long)
            {
    
                ExitLong(6, @"END LONG", "");
    
            }
    
            if (Position.MarketPosition == MarketPosition.Short) Print("SEARCH CODE");
    
            TRADING_RUN_OFF = false;
        }    ​

    #2
    Hello kliberthtrading20231107,

    Thank you for your post.

    ExitLong() cannot be used with the Unmanaged Approach.

    Unmanaged Approach - https://ninjatrader.com/support/help...d_approach.htm

    To exit a position by using the Unmanaged Approach, you need to use SubmitOrderUnmanaged() that submits an order in the opposite direction of your current position to exit that position.

    SubmitOrderUnmanaged() -https://ninjatrader.com/support/help...runmanaged.htm

    Make sure you check for a position first, since unlike the Managed Approach, the SubmitOrderUnmanaged() method will not be check to see if you're in a position before executing.

    Please see this forum post below which has a sample script demonstrating using the Unmanaged Approach:

    https://forum.ninjatrader.com/forum/...50#post1132250

    If you have any other questions, please let us know.

    Comment


      #3
      thank you

      This recommendation helped me solve my need.

      "To exit a position by using the Unmanaged Approach, you need to use SubmitOrderUnmanaged() that submits an order in the opposite direction of your current position to exit that position."

      The solution code was:​

      Code:
      if ((Times[0][0].TimeOfDay > HORA_FIN.TimeOfDay) && (TRADING_RUN_OFF == true))
          {
              if (Position.MarketPosition == MarketPosition.Long)
              {            
      
                  SubmitOrderUnmanaged(
                  0,                                               //selectedBarsInProgress,
                  OrderAction.Sell,                       //orderAction,
                  OrderType.Market,                     //orderType,
                  CANTIDAD_CONTRATOS,        //quantity,
                  0,                                                //limitPrice,
                  0,                                                //stopPrice,
                  oco,                                            //oco,
                  "Long limit entry 1");                  //signalName,
      
              }
              if (Position.MarketPosition == MarketPosition.Short)
              {    
      
                  SubmitOrderUnmanaged(
                  0,                                                           //selectedBarsInProgress,
                  OrderAction.Buy,                                   //orderAction,
                  OrderType.Market,                                //orderType,
                  CANTIDAD_CONTRATOS,                   //quantity,
                  0,                                                           //limitPrice,
                  0,                                                           //stopPrice,
                  oco,                                                       //oco,
                  "Short limit entry 1");
      
              }
      
              TRADING_RUN_OFF = false;
          }​

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      79 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X