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

"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.
    Gaby V.NinjaTrader Customer Service

    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 geddyisodin, 04-25-2024, 05:20 AM
      8 responses
      60 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      4 responses
      3,285 views
      1 like
      Last Post jgualdronc  
      Started by Option Whisperer, Today, 09:55 AM
      0 responses
      5 views
      0 likes
      Last Post Option Whisperer  
      Started by halgo_boulder, 04-20-2024, 08:44 AM
      2 responses
      22 views
      0 likes
      Last Post halgo_boulder  
      Started by mishhh, 05-25-2010, 08:54 AM
      19 responses
      6,189 views
      0 likes
      Last Post rene69851  
      Working...
      X