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

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 r68cervera, Today, 05:29 AM
    0 responses
    2 views
    0 likes
    Last Post r68cervera  
    Started by geddyisodin, Today, 05:20 AM
    0 responses
    3 views
    0 likes
    Last Post geddyisodin  
    Started by JonesJoker, 04-22-2024, 12:23 PM
    6 responses
    35 views
    0 likes
    Last Post JonesJoker  
    Started by GussJ, 03-04-2020, 03:11 PM
    12 responses
    3,239 views
    0 likes
    Last Post Leafcutter  
    Started by AveryFlynn, Today, 04:57 AM
    0 responses
    6 views
    0 likes
    Last Post AveryFlynn  
    Working...
    X