Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

managed approach

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

    managed approach

    If I use a managed strategy approach with EnterLongLimit, SetProfitTarget and SetStopLoss, do I need to handle order manageement e.g. cancelling orders, check for partial or zero fills etc.

    How much can I leave to Ninjatrader?

    #2
    Hello dibDab,

    That really depends on what your overall goal is going to involve. The managed approach mainly prevents you from doing conflicting actions and has the signal name/from entry signal system to tie orders together. Using the set methods with a signal name would tie those orders to an entry so they can be submitted when that entry fills. If one of the targets fills it would cancel the opposite order.

    Using EnterLongLimit for the entry can also expire if not filled within one bar, you otherwise need to keep calling the entry for each bar where it should be active until its filled. If you are manually coding you can also use live until cancelled with limit orders to avoid having to call it on each bar until filled. https://ninjatrader.com/support/help...enterlonglimit

    Comment


      #3
      I really appreciate your help, it's first class. It there a preferred way to give feedback?

      Comment


        #4
        Hello dibDab,

        Your post would be enough as we read these comments, I appreciate the feedback.

        Comment


          #5
          I have a couple of items that causing confusion:

          1. if I want to change a profit target or stop loss order, what's the best way to check that it exists or has been cancelled?

          2. If my strategy moves from historical into real time and its not flat, how do I handle a) a trade that I don't want to carry forward and b) one that I do?

          Comment


            #6
            Hello dibDab,

            1). when using the Set methods like SetStopLoss you don't need to check for it, you would just need to call it again. This only applies to manual coding, if you use the strategy builder it works slightly different so changing targets it slightly more involved. In manual coding you can call SetStopLoss again from a condition in OnBarUpdate and if the target exists it will be updated.

            2). Handling not being flat is not necessarily something you need to do but it will affect the start behavior of the strategy. If you have exit conditions or targets then those would work normally to exit the historical position so nothing extra is needed. That won't affect the realtime position it just closes it out and then the strategy can begin working in realtime. If you don't have any exit conditions or targets that will close the position that could affect it starting in realtime. The default start behavior waits until the strategy is flat before starting in realtime.


            Comment


              #7
              excellent thanks.

              Comment


                #8
                are there any sample strategies that use managed code to move from long to short, short to long etc.

                so I can see how long/short limit, profit target and stoploss are coded?

                Comment


                  #9
                  Hello dibDab,

                  The SampleMACrossOver strategy does that. To move from short to long or reverse the position you can simply call the opposite entry order. If you are long and call EnterShort it will close the long position and enter short. The targets are fully managed meaning you don't need any other code to cancel the targets to switch to the opposite entry. As long as you called the Set methods in OnStateChange or you call them before an entry order they will be used for the associated entry order fill.

                  If you are using limit orders for the entry it would be the same. If the limit entry filled and you are in a position then you can call the opposite entry order to reverse. If the entry order had not filled yet then you would need to stop calling that entry order and call the opposite entry order instead. Targets are only submitted upon entry fill so an active entry order has no targets and nothing additional to cancel, it will expire at the OnBarClose event assuming your condition starts calling the opposite entry order on the next bar.
                  Last edited by NinjaTrader_Jesse; 10-17-2022, 11:24 AM.

                  Comment


                    #10
                    do I have this right:

                    when I receive a long signal I SetProfitTarget & SetStopLoss and then myLongOrder = myEnterLongLimit(LiveUntilCancelled)

                    when I receive a short signal I SetProfitTarget & SetStopLoss and then myShortOrder = EnterShortLimit(LiveUntilCancelled)

                    OnBarUpdate if long I update SetProfitTarget & SetStopLoss or if short I update SetProfitTarget & SetStopLoss


                    my limit order may not be filled until several bars later or not filled at all. so

                    if not filled and I switch from long to short I just need to cancel myLongOrder ?

                    if filled and I switch from long to short I need to close myLongOrder ?



                    Last edited by dibDab; 10-18-2022, 06:48 AM.

                    Comment


                      #11
                      Hello dibDab,

                      Yes in that use case if the entry order is not filled you would need to cancel it while using LiveUntilCancelled true.

                      There is a sample of canceling an order here: https://ninjatrader.com/support/help...thod_to_ca.htm

                      When you start working with order objects you also need to use GetRealtimeOrder to transition orders to realtime, that is also shown in the above sample.

                      If the entry filled you don't need to close the position before reversing, just enter into the opposite direction.

                      Comment


                        #12
                        thanks again

                        "When you start working with order objects you also need to use GetRealtimeOrder to transition orders to realtime, that is also shown in the above sample" or can I just let them close and start fresh ones in real time?

                        Comment


                          #13
                          Hello dibDab,

                          You could do that but it would be more work to do that meaning you need to make sure the order is finished before State.Realtime happens. If you try to do anything with an order object once realtime is hit then you would get an error. That method is intended to transition order objects to realtime.

                          Comment


                            #14
                            ok.

                            is there anyway to know if a SetProfittarget or SetStopLoss is active and how do you remove them??

                            Comment


                              #15
                              Hello dibDab,

                              You would have to use the OnOrderUpdate override to find the orders and store them to a variable as the sample already does however you would end up making more logic trying to cancel those before realtime just to resubmit them in realtime. If you look at the cancel order example you can see how GetRealtimeOrder is used to create a seamless flow, you don't have to add additional conditions/actions to cancel targets just because of realtime. You just call that method on the order object like the sample shows to allow the strategy to work both historically and realtime.

                              You can see another example of the logic used for that here: https://ninjatrader.com/support/help...ub=getrealtime


                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, 03-13-2026, 05:17 AM
                              0 responses
                              87 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              151 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              80 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              53 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              62 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X