Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop a strategy if profit goal reached?

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

    #16
    Please try OnExecution().

    Comment


      #17
      OK, but which OrderStatus value tells me when a profit target or stoploss has been executed? Or is there something else that will tell me that?

      Thanks!
      Bryan

      Comment


        #18
        You might consider managing your own stop/targets if you need that level of control: http://www.ninjatrader-support.com/v...ead.php?t=3917

        Comment


          #19
          No, I am already managing my stoploss and profit targets with I just need to know what call or function executes when an order hits a profit target or stoploss -- or otherwise when a working order is closed and the CumProfit property changes. That's when I will open my output file and update my external profit accumulator value.

          Comment


            #20
            OnOrderStatus will be called as stop/target change their status. However, you'll have a hard time to know which order OnOrderStatus is called for (you could check the IOrder.Name) property.

            You only have 100% control by manging stops/targets as per my post below.

            Comment


              #21
              OK, that's not going to work. Then what I'll do is create a double variable that will hold the last Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit value. Whenever that value changes in OnOrderUpdate, I'll call my code to open and write to the output file.

              Thanks,
              Bryan

              Comment


                #22
                Is OnExecution called when a working order hits a profit target or stoploss? Or only when an order becomes Filled?

                Comment


                  #23
                  On each fill of an order.
                  RayNinjaTrader Customer Service

                  Comment


                    #24
                    OK thanks Ray. I assume OnOrderUpdate() is called though when a working order is closed by profit target or stoploss?

                    Comment


                      #25
                      OnOrderUpdate() is called for every order state change for any order generated by a strategy.
                      RayNinjaTrader Customer Service

                      Comment


                        #26
                        Yes, you are correct. And what is the order state for when a filled/working order has been closed? I have these to pick from:

                        OrderState.Accepted Order has been acknowledged by the broker
                        OrderState.Cancelled Order has been cancelled
                        OrderState.Filled Order has been filled
                        OrderState.PartFilled Order has been part filled
                        OrderState.PendingCancel An order cancellation request has been submitted
                        OrderState.PendingChange An order change request has been submitted
                        OrderState.PendingSubmit An order has been submitted
                        OrderState.Rejected An order has been rejected
                        OrderState.Working An order is working at the exchange
                        OrderState.Unknown An unknown order state

                        Comment


                          #27
                          Could be Filled, Cancelled or Rejected, those are terminal states.
                          RayNinjaTrader Customer Service

                          Comment


                            #28
                            Oh OK... I thought "filled" meant when an order is accepted by the broker and becomes 'active' or 'working.' So "filled" is a terminal state of an order that is no longer active any more?

                            What is the state of a stop or limit order when it's no longer pending but becomes an active order then?

                            Comment


                              #29
                              Accepted or Working.
                              RayNinjaTrader Customer Service

                              Comment


                                #30
                                Hey, just wanted to let people know if they are following this thread...

                                Now I understand where to catch my orders so I can update the daily PnL. In OnOrderUpdate(), there are several 'orders' that are filled with one position. When you enter a new limit or stop position, that order is "filled" when it becomes an active order (I assume new market orders are always "filled" right away).

                                Then, if you have a SetProfitTarget and/or SetStopLoss defined in your Initialize() tag, one or two new limit/stop orders are entered automatically. It's these orders being 'filled' (not the original position) that I wanted to capture. So in my OnOrderUpdate() tag, I need to look at order.Name for either "Profit target" or "Stop loss" to know when a position is actually being closed. I didn't realize I needed to ignore the order.Name of the original order (which I called "EnterLong" or "EnterShort" in my case).

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                673 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                379 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                111 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                577 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                582 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X