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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X