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 GussJ, 03-04-2020, 03:11 PM
            16 responses
            3,281 views
            0 likes
            Last Post Leafcutter  
            Started by WHICKED, Today, 12:45 PM
            2 responses
            19 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Started by Tim-c, Today, 02:10 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Taddypole, Today, 02:47 PM
            0 responses
            5 views
            0 likes
            Last Post Taddypole  
            Started by chbruno, 04-24-2024, 04:10 PM
            4 responses
            53 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Working...
            X