Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitLong problem in Strategy

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

    ExitLong problem in Strategy

    I am trying to create a customized protective stop to exit Long trade positions. I am entering the trade manually (outside of the strategy), but trying to exit using the strategy. I only Enable the strategy when I have a Flat position. I have used two lines of code to sync the strategy with the account. My problem is the ExitLong instruction does not exit my long position (it does not change my trade quantity in the account, or in the strategy). The Print instructions show that account and strategy agree on the Position & Quantity. Is it possible to use a strategy for exits only? Any suggestions would be very helpful and much appreciated.

    I have tried ExitLong in both of the following ways:
    ExitLong(PositionAccount.Quantity);
    ExitLong(Position.Quantity);

    Here is a snippet of my code:
    --------------------------------------------------------------------------------------------------------------------------------
    Position.Quantity = PositionAccount.Quantity; // sync the strategy quantity to the account quantity
    Position.MarketPosition = PositionAccount.MarketPosition; // sync the strategy (Long, Short, Flat), to the account (Long, Short, Flat)


    if(PositionAccount.MarketPosition == MarketPosition.Long) // account has an existing Long position
    {
    Print(" ");
    Print("Account Used is: " + Account);
    Print("Account " + PositionAccount.MarketPosition.ToString() + " " + PositionAccount.Quantity.ToString() );
    Print("Strategy " + Position.MarketPosition.ToString() + " " + Position.Quantity.ToString() );

    longProtectiveStopLevel = ((Low[1]) - (1 * TickSize));
    Draw.Line(this, "tagLongProtectiveStopLine + activeBar", true, 1, longProtectiveStopLevel, 0, longProtectiveStopLevel, Brushes.Yellow, (DashStyleHelper.Solid), 5, true);

    if(Close[0] <= longProtectiveStopLevel)
    {
    Print("Close Long Positions Here " );
    ExitLong(PositionAccount.Quantity);
    RemoveDrawObject("tagLongProtectiveStopLine + activeBar");
    }
    }

    #2
    Hello goodknight777,

    The strategy functions like ExitLong are used to exit strategy submitted orders, strategies in general are not intended for the use case you described. To do what you are asking it would be best to use an indicator and the addon framework.

    An indicator is suggested so you don't have strategy methods and properties available which won't work with the manually submitted orders or manually created positions.

    The addon framework can be used to find an account, example here: https://ninjatrader.com/support/help...ount_class.htm

    Once you locate an account you can loop through the positions just like you are doing now and find open orders as well.




    To exit the position you can submit an exit order:



    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    93 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    152 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    80 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    53 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    65 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X