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

MarketPosition Flat and SetProfitTarget

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

    MarketPosition Flat and SetProfitTarget

    Hey fellas,

    For my strategy, I have it set to execute OnBarClose and have a question about how SetProfitTarget is processed.

    During Bar Update, I've been using MarketPosition.Flat with EnterStopMarket and SetProfitTarget orders and all of that is working fine. However, I noticed that the bar that's processed if the profit target is hit is processed as if it's flat. Shouldn't that bar be processed as if MarketPosition.Long or Short? Meaning the bar after it should be the start of the Flat bar.

    #2
    Hello PN720,

    Thank you for your note.

    Without the code I wouldn’t be able to tell you what’s going on, there are too many variables. Live vs realtime, secondary data series, calculate settings, etc.

    If you’d like to upload a copy of the script I could take a look.

    I would suggest seeing the notes in the following two samples which submit profit targets,

    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi Alan,

      I've attached a very simple script that just enters Long on an EMA crossover with a profit target of 20 ticks out. I'm printing to the Output Window whenever I'm Flat or Long. You'll notice that on the bar that satisfies the profit target, I'm seeing that it's reporting as Flat instead of Long. Shouldn't the next bar be the flat bar?
      Attached Files

      Comment


        #4
        Hello PN720,

        When you call Enterlong your order needs to be submitted to the broker/exchange, filled and returned. This needs to happen before you can call SetProfitTarget, otherwise no PT will be submitted, because NT does not know you are in a position. So it’s likely this is being skipped then never being called again, since on the next OBU you are not flat.

        You should call SetProfitTarget in State.Configure as the example below shows,


        Or follow the approach used in either of the following two examples,
        The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()



        After you’ve made that change, does your strategy behavior work as expected?
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hi Alan,

          I've moved the SetProfitTarget into the Configure section and still see the same thing. Maybe I'm not explaining my problem correctly in that when the profit target is hit, shouldn't the bar that fills the profit target still be considered Long and the bar after it will be considered Flat?
          I've attached what I see on my example where the profit target is hit with the 11:58:51 bar and the Output window reports that I'm flat with that bar.
          Attached Files

          Comment


            #6
            Hello PN720,

            If your profit target is hit on a bar, the position becomes flat on that bar, not the next bar. If we are trading the last 15 minutes of soybeans and our profit target gets filled, our position is flat on that closing bar, not the open of the night session requiring us to have overnight margin.

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Ok, thanks for confirming what I'm seeing as intended behavior.

              I want to take some action on market position flat but exclude that bar when the profit target is hit. Is there an order state or something that I can filter on?

              Comment


                #8
                Hello PN720,

                Yes, you can use BarsSinceExitExecution() to prevent action on the exit bar.

                if(BarsSinceExitExecution() <1) return;


                Please let us know if you need further assistance.
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Worked out perfectly, thanks for your help!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by RubenCazorla, 08-30-2022, 06:36 AM
                  3 responses
                  77 views
                  0 likes
                  Last Post PaulMohn  
                  Started by f.saeidi, Yesterday, 12:14 PM
                  9 responses
                  23 views
                  0 likes
                  Last Post f.saeidi  
                  Started by Tim-c, Today, 03:54 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post Tim-c
                  by Tim-c
                   
                  Started by FrancisMorro, Today, 03:24 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post FrancisMorro  
                  Started by Segwin, 05-07-2018, 02:15 PM
                  10 responses
                  1,772 views
                  0 likes
                  Last Post Leafcutter  
                  Working...
                  X