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

Working With SetProfitTarget

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

    Working With SetProfitTarget

    I'm a newbie, so please excuse me if my question is trivial or has been answered many times in the past. Let's say that I want to enter two separate long trades using EnterLong(), both for the same instrument. The first one is associated with a SetProfitTarget() which is set in Initialize(). Both orders however are subject to a general exit condition which is computed in OnBarUpdate() each time for a new bar. If the exit condition is hit before the Profit Target is reached, then both trades are closed. If the Profit Target is reached first, then the first trade will be automatically closed, and the second one remains open until the general exit condition is met. My question is, when the general exit condition is met, if I don't know whether or not the first trade was closed due to the profit target being reached, I would not know whether or not I need to close that trade as well. How do I know whether or not the profit target was reached for the first trade, and that it is therefore no longer an active trade?

    #2
    Hello ronharrow,

    Thanks for your post and welcome to the forums!

    You can always test for your market position at any time.

    if (Position.MarketPosition != MarketPosition.Flat)
    {
    // we are not flat so place exit orders here
    }

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you, but if all goes well with the trade, one of the trades will close out due to the profit target being hit, but the second trade will still be active. When time comes to close that second trade, due to the general exit condition being met, would I do the wrong thing by trying to exit the first trade which has already been closed previously? If I would, then how do I know that that trade has already been closed, and that I should not be trying to close it again?

      Comment


        #4
        Hello ronharrow,

        Thanks for your reply.

        In addition to checking for a marketposition/direction you can also test for quantity: http://ninjatrader.com/support/helpG.../?quantity.htm

        Most exit methods will ignore if a position does not exist.

        Please review the helpguide on managed approach: http://ninjatrader.com/support/helpG...d_approach.htm

        And then check the helpguide on each of the exit methods you are using: http://ninjatrader.com/support/helpG...er_methods.htm
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thanks, will do.

          Comment


            #6
            Originally posted by ronharrow View Post
            I'm a newbie, so please excuse me if my question is trivial or has been answered many times in the past. Let's say that I want to enter two separate long trades using EnterLong(), both for the same instrument. The first one is associated with a SetProfitTarget() which is set in Initialize(). Both orders however are subject to a general exit condition which is computed in OnBarUpdate() each time for a new bar. If the exit condition is hit before the Profit Target is reached, then both trades are closed. If the Profit Target is reached first, then the first trade will be automatically closed, and the second one remains open until the general exit condition is met. My question is, when the general exit condition is met, if I don't know whether or not the first trade was closed due to the profit target being reached, I would not know whether or not I need to close that trade as well. How do I know whether or not the profit target was reached for the first trade, and that it is therefore no longer an active trade?
            Part of the whole point of using managed orders is that you do not need to know this level of detail. When your first trade is closed by exiting at target, its associated Stop Loss order is automatically closed, so the question that you raise is moot.

            Comment


              #7
              Thank you koganam.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bortz, 11-06-2023, 08:04 AM
              47 responses
              1,606 views
              0 likes
              Last Post aligator  
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              9 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              19 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              6 views
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              15 views
              0 likes
              Last Post Javierw.ok  
              Working...
              X