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 helpwanted, Today, 03:06 AM
            1 response
            12 views
            0 likes
            Last Post sarafuenonly123  
            Started by Brevo, Today, 01:45 AM
            0 responses
            9 views
            0 likes
            Last Post Brevo
            by Brevo
             
            Started by aussugardefender, Today, 01:07 AM
            0 responses
            5 views
            0 likes
            Last Post aussugardefender  
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            242 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            9 responses
            387 views
            1 like
            Last Post Gavini
            by Gavini
             
            Working...
            X