Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Moving Stop loss SetStopLoss

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

    #16
    Hi ggerstein,

    Is what you're seeing that the order is never submitted or never fills? What is the exact TraceOrders output you're seeing related to it?

    You could check the price of the order using orders tab of control center, or programatically using this technique:
    Ryan M.NinjaTrader Customer Service

    Comment


      #17
      Order is never filled

      Hey,

      I forgot to list one variable in my previous post which is the order name. I use this when calling the entry. Added it in the post just for clarity. The answer to your question is that the stopLoss order is never filled. I am not positive however I am seeing the stop loss order placed. I think what I am seeing is a trace from the setStopLoss method, but it looks like the order is placed, but never filled. Here is an example trace from the strategy. Some of it is just my own trace statements to determine what the values are at a specific bar. I'm attaching an image so you can see the chart and the order occurring. Bars are numbered by the script so the trace below should make more sense with the image. I will try out what you sent me and see if I can make sense of it. Thank you!

      Bar Number 64
      BearSignal
      valid signal = True
      Bear Signal. Modifying Stop Loss before entering to price: 0.9932
      11/28/2011 5:25:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Price Value=0.9932 Currency=0 Simulated=False
      11/28/2011 5:25:00 AM Entered internal PlaceOrder() method at 11/28/2011 5:25:00 AM: BarsInProgress=0 Action=SellShort OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=0.9918 SignalName='filledOrder' FromEntrySignal=''
      Submitting Short Order on Following Bar
      Bar Number: 64
      barHigh: 0.9931
      barLow: 0.9919
      barOpen: 0.9923
      barClose: 0.9919
      Printing Order Information
      - Order User Defined Entry Signal Name:
      - Order Name: filledOrder
      - OrderID: NT-00000
      - Instrument: 6A 12-11 Globex
      - AverageFillPrice: 0
      - OrderType: Stop
      - Quantity: 1
      - OrderState: PendingSubmit
      - LimitPrice: 0
      - StopPrice: 0.9918
      - Time: 11/28/2011 5:25:00 AM
      - TimeInForce: Gtc
      - LiveUntilCancelled: False
      - Order Filled: 0
      - Oco:
      Printing Execution Information
      - Name of Execution: filledOrder
      - ExecutionID: NT-00000
      - Instrument: 6A 12-11 Globex
      - Price: 0.9918
      - MarketPosition: Short
      - Quantity: 1
      - Time: 11/28/2011 5:30:00 AM
      - RealTime: False
      - Commission: 0
      - Order User Defined Entry Signal Name:
      - Executed Order Name: filledOrder
      - Executed Order ID: NT-00000
      Order Postion: Short
      new bar high is lower than currentEntry . Adjusting Stop Loss
      Printing Bar Information
      - barHigh: 0.9911
      - barLow: 0.9905
      - barOpen: 0.991
      - barClose: 0.9909
      - trailingPriceValue: 0.0001
      Updating StopLoss Order in BarUpdate Short Position to price: 0.9912
      Updating currentEntry Order in BarUpdate Long Position to Price: 0.9909
      11/28/2011 5:40:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='filledOrder' Mode=Price Value=0.9912 Currency=0 Simulated=True
      11/28/2011 5:40:00 AM Ignored internal SetStopTarget() method: Type=Stop FromEntrySignal='filledOrder' Mode=Price Value=0.9912 Currency=0 Simulated=True' Reason='Another SetStopTarget() method call has already submitted a stop/target order'
      Order Postion: Short
      new bar high is lower than currentEntry . Adjusting Stop Loss
      Printing Bar Information
      - barHigh: 0.9908
      - barLow: 0.9903
      - barOpen: 0.9908
      - barClose: 0.9905
      - trailingPriceValue: 0.0001
      Updating StopLoss Order in BarUpdate Short Position to price: 0.9909
      Updating currentEntry Order in BarUpdate Long Position to Price: 0.9905
      11/28/2011 5:50:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='filledOrder' Mode=Price Value=0.9909 Currency=0 Simulated=True
      Order Postion: Short
      new bar high is lower than currentEntry . Adjusting Stop Loss
      Printing Bar Information
      - barHigh: 0.9904
      - barLow: 0.9897
      - barOpen: 0.9904
      - barClose: 0.9901
      - trailingPriceValue: 0.0001
      Updating StopLoss Order in BarUpdate Short Position to price: 0.9905
      Updating currentEntry Order in BarUpdate Long Position to Price: 0.9901
      11/28/2011 6:30:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='filledOrder' Mode=Price Value=0.9905 Currency=0 Simulated=True
      Printing Execution Information
      - Name of Execution: Stop loss
      - ExecutionID: NT-00001
      - Instrument: 6A 12-11 Globex
      - Price: 0.9932
      - MarketPosition: Long
      - Quantity: 1
      - Time: 11/28/2011 8:25:00 AM
      - RealTime: False
      - Commission: 0
      - Order User Defined Entry Signal Name:
      - Executed Order Name: Stop loss
      - Executed Order ID: NT-00001
      Modifying Stop Loss back to default stop ticks: 10
      Attached Files

      Comment


        #18
        my question

        Here is my script it doesn´t work well, i want to ask you about it, i want an initial stoploss 6 ticks below the entry and when the position goes 5 ticks up,i want to change the stop 1 tick above the entry point.

        Thanks a lot,

        #region Variables;

        private bool controlOne = true;

        #endregion


        protected override void Initialize()
        {


        SetProfitTarget("", CalculationMode.Ticks, 10);
        SetStopLoss("", CalculationMode.Ticks, 6, true);

        CalculateOnBarClose = true;
        }


        protected override void OnBarUpdate()
        {

        if (Close[0]> Open[0]
        )
        {
        EnterLong(1, "");

        }

        if (High[0] >= Position.AvgPrice + 5* TickSize && controlOne)
        {
        SetStopLoss("", CalculationMode.Price, Position.AvgPrice + 1* TickSize, true);
        controlOne = false;
        }



        //Reset your bool flag when flat.
        if (Position.MarketPosition == MarketPosition.Flat)
        {
        controlOne = true;
        }


        }

        Comment


          #19
          Hi urutrader,

          Welcome to the NT forums. Your code seems to fit with what you describe. What part isn't working the way you expect and where are you using it (real time or backtest)?

          If you want to see the stop order working, change the Simulated property = false.
          SetStopLoss("", CalculationMode.Price, Position.AvgPrice + 1* TickSize, false);
          Ryan M.NinjaTrader Customer Service

          Comment


            #20
            Originally posted by NinjaTrader_RyanM View Post
            Hi urutrader,

            Welcome to the NT forums. Your code seems to fit with what you describe. What part isn't working the way you expect and where are you using it (real time or backtest)?

            If you want to see the stop order working, change the Simulated property = false.
            SetStopLoss("", CalculationMode.Price, Position.AvgPrice + 1* TickSize, false);
            Thank you Ryan, i am using real time; and the part that doesn´t work is the change of the stoploss.
            i will use what you told me,

            Thank you very much.

            Comment


              #21
              Thanks for the reply. Setting simulated = false will help a good bit since you can check the actual value of the stop loss order. When simulated = true, it's not an actual stop order. Instead it submits a market order once last traded price = simulated stop price.
              Last edited by NinjaTrader_RyanM1; 02-24-2012, 02:28 PM.
              Ryan M.NinjaTrader Customer Service

              Comment


                #22
                Dynamic Stop Loss in Market Replay

                Hi, the following code does not update the dynamic stop loss in market replay. I need to keep COBC = True. Even at the end of multiple bars above the tick threshold, the stop loss does not update on the StaticDOM. Any help would be greatly appreciated.

                #region Variables;

                private bool ControlOne = true;

                #endregion

                CalculateOnBarClose = true;
                .......

                if (Position.GetProfitLoss(Open[0], PerformanceUnit.Points) >= 2 && ControlOne)
                {
                SetStopLoss("", CalculationMode.Ticks, Position.GetProfitLoss(Open[0], PerformanceUnit.Points) + 4* TickSize, false);
                ControlOne = false;
                }

                if (Position.GetProfitLoss(Open[0], PerformanceUnit.Points) >= 3 && !ControlOne)
                {
                SetStopLoss("", CalculationMode.Ticks, Position.GetProfitLoss(Open[0], PerformanceUnit.Points) + 6* TickSize, false);
                }

                //Reset bool flag when flat.
                if (Position.MarketPosition == MarketPosition.Flat)
                ControlOne = true;
                {
                SetStopLoss("", CalculationMode.Ticks, OldStopLoss, false);
                }

                Comment


                  #23
                  Welcome to our forums!

                  For strategies add TraceOrders = true to your Initialize() method and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders

                  It may also help to add drawing objects to your chart for signal and condition confirmation - Drawing Objects.
                  MatthewNinjaTrader Product Management

                  Comment


                    #24
                    Moving Stop Loss Order

                    Thanks Matthew that helped & this thread has been extremely helpful.

                    But I want the best of both worlds.

                    Can I enter a position while COBC = True and use this moving stop loss method while making "touches" past the threshold before the current bar is closed? If so, how to implement in code?

                    Comment


                      #25
                      Originally posted by geekodude View Post
                      Thanks Matthew that helped & this thread has been extremely helpful.

                      But I want the best of both worlds.

                      Can I enter a position while COBC = True and use this moving stop loss method while making "touches" past the threshold before the current bar is closed? If so, how to implement in code?
                      In that case, you would use OnMarketData() to monitor and control your stop loss on every tick.

                      Comment


                        #26
                        Moving Stop Loss Order

                        Thanks Koganam. NT help file states OnMarketData() does not work with backtest data. But does it work on Market Replay data?

                        Comment


                          #27
                          Originally posted by geekodude View Post
                          Thanks Koganam. NT help file states OnMarketData() does not work with backtest data. But does it work on Market Replay data?
                          geekodude - Yes, OnMarketData() will be called during market replay playback.
                          Ryan M.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          656 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          371 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          109 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          574 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          579 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X