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 llanqui, Today, 03:53 AM
      0 responses
      4 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      10 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      14 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      14 views
      0 likes
      Last Post strategist007  
      Working...
      X