Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-Instrument Exit Trigger

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

    Multi-Instrument Exit Trigger

    I'm running several instruments at the same time. When a profit target is reached would like to change a condition from "false" to "true".
    Unfortunately this doesn't work... any thoughts? Thanks

    if (Positions[0].GetProfitLoss(Closes[0][0], PerformanceUnit.Currency)
    + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency)
    + Positions[2].GetProfitLoss(Closes[2][0], PerformanceUnit.Currency)
    + Positions[3].GetProfitLoss(Closes[3][0], PerformanceUnit.Currency)
    + Positions[4].GetProfitLoss(Closes[4][0], PerformanceUnit.Currency) > 1000


    && ProfitLimit == false
    )
    {
    ProfitLimit = true;
    }

    #2
    Hello John833,

    What does this value evaluate as?

    Make a print of this.

    Print(Positions[0].GetProfitLoss(Closes[0][0], PerformanceUnit.Currency)
    + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency)
    + Positions[2].GetProfitLoss(Closes[2][0], PerformanceUnit.Currency)
    + Positions[3].GetProfitLoss(Closes[3][0], PerformanceUnit.Currency)
    + Positions[4].GetProfitLoss(Closes[4][0], PerformanceUnit.Currency));

    What does this print as when you are expecting the condition to be true?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by John833 View Post
      I'm running several instruments at the same time. When a profit target is reached would like to change a condition from "false" to "true".
      Unfortunately this doesn't work... any thoughts? Thanks

      if (Positions[0].GetProfitLoss(Closes[0][0], PerformanceUnit.Currency)
      + Positions[1].GetProfitLoss(Closes[1][0], PerformanceUnit.Currency)
      + Positions[2].GetProfitLoss(Closes[2][0], PerformanceUnit.Currency)
      + Positions[3].GetProfitLoss(Closes[3][0], PerformanceUnit.Currency)
      + Positions[4].GetProfitLoss(Closes[4][0], PerformanceUnit.Currency) > 1000


      && ProfitLimit == false
      )
      {
      ProfitLimit = true;
      }
      What exactly does the clause "doesn't work" mean in your context? What are you expecting to see, and what are you seeing that does not look correct?

      Comment


        #4
        Hi NinjaTrader_ChelseaB & koganam
        I've made a print, the output window shows the unrealised p/l of the positions held.
        When the unrealised p/l reaches over $1000 then ProfitLimit should be 'true'.

        The problem I have is as soon as Position[0] has a position, ProfitLimit becomes true immediately before the p/l has reached $1000.

        So I have either a problem elsewhere in my code OR there is something wrong with the code below?

        Comment


          #5
          Hello John833,

          What is coming out from that print?

          Do you have other code that sets the ProfitLimit bool that you have not shared with us?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hi NinjaTrader_ChelseaB

            Managed to sort out the problem(s), I had errors in Initialise and some poor code constructions.

            Thanks & regards!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            566 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            547 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            548 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X