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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      56 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      133 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 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