Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Closing out Multi Instrument Strategy based on Profit

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

    Closing out Multi Instrument Strategy based on Profit

    Hi I am having some issue with closing out a multi-instrument strategy.

    I would like to close out the position if the sum of both instruments dollar value is >= $30.


    //Enter Long index0 and Short index1

    if (entry logic here)
    {
    EnterLong(0, Positions[0].Quantity, "L1");
    EnterShort(1, Positions[1].Quantity, "S1");
    Print("Long Entry on Primary Instrument (index0)");
    Print("Short Entry on Secondary Instrument (index1)");
    }


    //take profit
    if (Positions[0].GetUnrealizedProfitLoss(PerformanceUnit.Currency, Closes[0][0]) + Positions[1].GetUnrealizedProfitLoss(PerformanceUnit.Currency, Closes[1][0]) >= 30)
    {

    ExitLong(0, Positions[0].Quantity, "exit","L1");
    ExitShort(1, Positions[1].Quantity, "exit","S1");
    }

    #2
    Hello brucelevy,

    Thank you for your note.

    I put your script inside the attached strategy and don't see any issue with the script.

    What is the issue you are having exactly?

    I look forward to your reply.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    53 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    44 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