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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    29 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    46 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Working...
    X