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

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 rene69851, 05-02-2024, 03:25 PM
            1 response
            20 views
            0 likes
            Last Post rene69851  
            Started by ETFVoyageur, Yesterday, 07:05 PM
            5 responses
            44 views
            0 likes
            Last Post ETFVoyageur  
            Started by jpeep, 08-16-2020, 08:31 AM
            13 responses
            487 views
            0 likes
            Last Post notenufftime  
            Started by realblubb, 04-28-2024, 09:28 AM
            2 responses
            32 views
            0 likes
            Last Post realblubb  
            Started by bmarovets, Today, 06:33 PM
            0 responses
            12 views
            0 likes
            Last Post bmarovets  
            Working...
            X