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

Order Ignored Because Stop Price is Above Bar

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

    Order Ignored Because Stop Price is Above Bar

    I know why this error message is usually triggered but in this instance I can't figure out why the code is firing the stop exit order at 11am when the entry doesn't register until 11:26am.

    Attached below are the error and trade confirmation screenshots.

    Click image for larger version  Name:	Error.png Views:	0 Size:	2.5 KB ID:	1160287
    Click image for larger version  Name:	Trade Confirmation.png Views:	0 Size:	2.6 KB ID:	1160289
    Next is the stop exit order code: The error occurs with the "LongentryCeiling"
    Code:
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    #region Longs
    
    #region Ceiling Break
    if (execution.Order.Name == "LongEntryCeiling1" && execution.Order.OrderState == OrderState.Filled)
    {
    LongCeilingEntry = execution.Order;
    }
    
    if (LongCeilingEntry != null && LongCeilingEntry == execution.Order
    && execution.Order.Name == "LongEntryCeiling1" && execution.Order.OrderState == OrderState.Filled)
    {
    exPriceCeiling = execution.Price;
    #region Targets
    largeLongCeilingTarget = exPriceCeiling + ((SLNormalCeiling*TickSize)*TargetMultiplierCeilin g);
    stopLongCeiling1 = exPriceCeiling - (SLNormalCeiling*TickSize);
    stopLongCeiling1a = exPriceCeiling - (NewStopLongCeiling*TickSize);
    #endregion
    
    stopOrderLongEntryCeiling1 = ExitLongStopMarket(2, true, (lotLCeiling*2), stopLongCeiling1,"StopExitLongCeiling1", "LongEntryCeiling1"); //should this be an ExitLongLimit?
    ExitLongMIT(2, true, lotLCeiling, largeLongCeilingTarget, "ExitProfitLongEntryCeiling1R","LongEntryCeiling1" );
    CeilingActive = true;
    }
    #endregion
    #region Basement/Floor1 Break
    if (execution.Order.Name == "LongEntryBasement1" && execution.Order.OrderState == OrderState.Filled)
    {
    LongBasementEntry = execution.Order;
    }
    
    if (LongBasementEntry != null && LongBasementEntry == execution.Order
    && execution.Order.Name == "LongEntryBasement1" && execution.Order.OrderState == OrderState.Filled)
    {
    exPriceBasement = execution.Price;
    #region Targets
    largeLongBasementTarget = exPriceBasement + ((SLNormalBasement*TickSize)*TargetMultiplierBasem ent);
    
    stopLongBasement1 = exPriceBasement - (SLNormalBasement*TickSize);
    stopLongBasement1a = exPriceBasement - (NewStopLongBasement*TickSize);
    #endregion
    
    stopOrderLongEntryBasement1 = ExitLongStopMarket(2, true, (lotLBasement*2), stopLongBasement1,"StopExitLongBasement1", "LongEntryBasement1"); //should this be an ExitLongLimit?
    ExitLongMIT(2, true, lotLBasement, largeLongBasementTarget, "ExitProfitLongEntryBasement1R","LongEntryBasement 1");
    BasementActive = true;
    }
    #endregion
    
    #endregion
    Also an important note is I am running two different Long entries in this one strategy. When I separate the two long entries and run the code as a separate single long entry strategies with the same inputs, the entry price and entry time are the same but the error no longer occurs and the stop exit executes.
    Below screenshot shows this instance.
    Click image for larger version  Name:	Trade2.png Views:	0 Size:	3.6 KB ID:	1160290

    I believe the stop exit code is the exact same in the above instance:
    Code:
    #region Ceiling Break
    if (execution.Order.Name == "LongEntryCeiling1" && execution.Order.OrderState == OrderState.Filled)
    {
    LongCeilingEntry = execution.Order;
    }
    
    if (LongCeilingEntry != null && LongCeilingEntry == execution.Order
    && execution.Order.Name == "LongEntryCeiling1" && execution.Order.OrderState == OrderState.Filled)
    {
    exPriceCeiling = execution.Price;
    #region Targets
    largeLongCeilingTarget = exPriceCeiling + ((SLNormalCeiling*TickSize)*TargetMultiplierCeilin g);
    stopLongCeiling1 = exPriceCeiling - (SLNormalCeiling*TickSize);
    stopLongCeiling1a = exPriceCeiling - (NewStopLongCeiling*TickSize);
    #endregion
    
    stopOrderLongEntryCeiling1 = ExitLongStopMarket(2, true, (lotLCeiling*2), stopLongCeiling1,"StopExitLongCeiling1", "LongEntryCeiling1"); //should this be an ExitLongLimit?
    ExitLongMIT(2, true, lotLCeiling, largeLongCeilingTarget, "ExitProfitLongEntryCeiling1R","");
    CeilingActive = true;
    }
    #endregion

    What could be causing the error when the 2 entries are compiled in one strategy? From my analysis it looks like the timing of the stopexit is the issue. Why would it try to place the stop exit at 11am when the entry isn't filled until 11:26am?


    Thanks.
    Attached Files

    #2
    Hi mlprice, thanks for your post.

    In a backtest there is not intrabar movement, so try setting the strategy to fill orders on a 1 tick series to increase the resolution. In the strategy settings change Order Fill Resolution to High and pick a 1 tick series. Our colleague Jim gave a few examples on how to debug the specific problem "invalid based on the price range of the bar" here:
    https://ninjatrader.com/support/foru...ge#post1104682

    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chris,

      High Order Fill Resolution wont work because my strategy is already running on a multi series (1 day, 60 minute, and 1 minute)

      Comment


        #4
        Here is the weird part. I ran the prints to show current ask and the stop price for both Strategy A (has logic for 2 entries) and Strategy B (logic for a single entry)

        Strategy A Output
        Click image for larger version  Name:	testoutput.png Views:	0 Size:	5.1 KB ID:	1160411
        Strategy B Output
        Click image for larger version  Name:	no error.png Views:	0 Size:	2.8 KB ID:	1160412

        The question is why is there no error for Strategy B?

        Edit:

        Here is the output including the execution price of the OnExecutionUpdate order.
        Click image for larger version  Name:	Screenshot 2021-06-17 142526.png Views:	0 Size:	6.7 KB ID:	1160420


        Would the best fix be to change the timeseries from 1 minute to 1 tick?
        But still why is there no error in Strategy B?

        Thanks
        Last edited by mlprice12; 06-17-2021, 01:29 PM.

        Comment


          #5
          Hi mlprice, thanks for your reply.

          There is something wrong with the call you are making for the ExitLongStopMarket order. I would recommend making a reduced strategy that focuses on submitting this order properly then once that has been established then it can be added into the strategy as the stop price. In the previous ticket about this error, the user was not inputting a correct stop price for the order. Im not able to tell what your stop prices are because they are in variables.

          Best regards,
          -ChrisL
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            Thanks Chris,

            Please see my edit and I did exactly what you said.

            Here is the output for the reduced strategy with no error.
            Click image for larger version  Name:	no error.png Views:	0 Size:	3.3 KB ID:	1160427

            Here is the output for the larger strategy with error. All code is same.
            Click image for larger version  Name:	Screenshot 2021-06-17 142526.png Views:	0 Size:	6.7 KB ID:	1160428

            Code in larger stratgy
            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
            {
            #region Longs

            #region Ceiling Break
            if (execution.Order.Name == "LongEntryCeiling1" && execution.Order.OrderState == OrderState.Filled)
            {
            LongCeilingEntry = execution.Order;
            }

            if (LongCeilingEntry != null && LongCeilingEntry == execution.Order
            && execution.Order.Name == "LongEntryCeiling1" && execution.Order.OrderState == OrderState.Filled)
            {
            exPriceCeiling = execution.Price;
            #region Targets
            largeLongCeilingTarget = exPriceCeiling + ((SLNormalCeiling*TickSize)*TargetMultiplierCeilin g);
            stopLongCeiling1 = exPriceCeiling - (SLNormalCeiling*TickSize);
            stopLongCeiling1a = exPriceCeiling - (NewStopLongCeiling*TickSize);
            #endregion
            Print("CeilingBreak Ask" + GetCurrentAsk() + "Time" + Times[2][0]);
            Print("CeilingBreak Execution Price" + exPriceCeiling + "Time" + Times[2][0]);
            Print("CeilingBreak Stop Price" + stopLongCeiling1 + "Time" + Times[2][0]);
            stopOrderLongEntryCeiling1 = ExitLongStopMarket(2, true, (lotLCeiling*2), stopLongCeiling1,"StopExitLongCeiling1", "LongEntryCeiling1");

            ExitLongMIT(2, true, lotLCeiling, largeLongCeilingTarget, "ExitProfitLongEntryCeiling1R","LongEntryCeili ng1" );
            CeilingActive = true;
            }
            #endregion
            Code in condensed strategy
            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
            {
            #region Longs

            #region Ceiling Break
            if (execution.Order.Name == "LongEntryCeiling1" && execution.Order.OrderState == OrderState.Filled)
            {
            LongCeilingEntry = execution.Order;
            }

            if (LongCeilingEntry != null && LongCeilingEntry == execution.Order
            && execution.Order.Name == "LongEntryCeiling1" && execution.Order.OrderState == OrderState.Filled)
            {
            exPriceCeiling = execution.Price;
            #region Targets
            largeLongCeilingTarget = exPriceCeiling + ((SLNormalCeiling*TickSize)*TargetMultiplierCeilin g);
            stopLongCeiling1 = exPriceCeiling - (SLNormalCeiling*TickSize);
            stopLongCeiling1a = exPriceCeiling - (NewStopLongCeiling*TickSize);
            #endregion
            Print("CeilingBreak Ask" + GetCurrentAsk() + "Time" + Times[2][0]);
            Print("CeilingBreak Execution Price" + exPriceCeiling + "Time" + Times[2][0]);
            Print("CeilingBreak Stop Price" + stopLongCeiling1 + "Time" + Times[2][0]);
            stopOrderLongEntryCeiling1 = ExitLongStopMarket(2, true, (lotLCeiling*2), stopLongCeiling1,"StopExitLongCeiling1", "LongEntryCeiling1"); //should this be an ExitLongLimit?
            ExitLongMIT(2, true, lotLCeiling, largeLongCeilingTarget, "ExitProfitLongEntryCeiling1R","");
            CeilingActive = true;
            }
            #endregion
            Last edited by mlprice12; 06-17-2021, 01:52 PM.

            Comment


              #7
              Hi mlprice, thanks for your reply.

              Using ExitLongStopMarket works fine when your order is below the bid price, I just tested it in a simple strategy, so the strategy you are posting here must be reduced further to find the issue. I notice you are using the Ask price for the stop price which would result in a rejected order, sell stop market orders must be at or below the bid price. Also using GetCurrentAsk/Bid will only work in real-time mode, for historical bid/ask prices, see the Developing for tick replay page or add a 1 tick bid and ask series to the script.

              Best regards,
              -ChrisL
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Just to be clear I'm only using Print - GetCurrentAsk. Nowhere else is ask or bid logic used.

                The Output data for the condensed version is the exact same as the larger version so the question is why is one producing the error and not the other?

                Here is more output data.
                Click image for larger version  Name:	LargerStrat.png Views:	0 Size:	7.3 KB ID:	1160443

                How is the execution price higher than the candle high?

                If you look in the execution page of the backtest results it shows that the execution actually takes place at 11:26am
                Why is the print data from 11:25?

                Thanks
                Last edited by mlprice12; 06-17-2021, 03:40 PM.

                Comment


                  #9
                  After editing out code to pinpoint the issue I have found that if Entry1"BasementBreakout" has an active stop and target then the error occurs after the entry2 "CeilingBreakout" tries to submit its stop.

                  If Entry1 doesn't have the active stop and target the error doesn't occur. The error still occurs when either Entry1 stop OR Entry1 target is active.
                  This code fires in OnEecutionUpdate.
                  See above for actual code.

                  Here is the output when Entry one doesn't have stop and target code
                  Click image for larger version

Name:	Output without Entry1 Stop and Target.png
Views:	146
Size:	14.7 KB
ID:	1160456

                  Here is the output when Entry1 does have stop and target code
                  Click image for larger version

Name:	Output with Entry1 stop and target.png
Views:	147
Size:	15.3 KB
ID:	1160455

                  Any idea why the Entry1 code is creating this interference with the Entry2 stop?

                  Comment


                    #10
                    Code works perfectly when I change second timeseries to 1 tick from 1 minute and let Entry1 submit its stop and target.

                    The problem is I want to backtest 2 years and 2 months of data so a 1 tick series is too finite.

                    Why does including the Entry1 stop and target only create an error at the 1 minute series?

                    Here is the output when using 1tick series
                    Click image for larger version  Name:	Tick instead of minute.png Views:	0 Size:	15.1 KB ID:	1160460

                    Comment


                      #11
                      Hi mlprice,

                      The historical bar only has the OHLC values of the bar so the stop price you are submitting to the 1 minute series is falling out of range of the bar. We use this backfill algorithm to fill orders on historical bars, so you must go through this algorithm with the bar series you are backtesting on to see where it's getting this price from. The 1 tick series fills properly because it has the full movement of price and this stop price is not falling out of range.

                      Best regards,
                      -ChrisL
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks Chris,

                        I should have clarified my question better. I understand why obviously the tick series works better than the 1 minute series. What I don't understand is why my strategy1 logic works on a 1 minute series without errors but my strategy2 creates an error on the same entry with identical output window data?

                        Comment


                          #13
                          Hi mlprice, thanks for your reply.

                          If there is a difference in the data series added or the BarsInProgress you are submitting the order to that would be the source of the trade rejection. Be sure to note the order the data series are added (which will affect the BarsInProgress index being used) To further investigate it you can make a copy of the strategy that will solely focus on one timestamp and submit an order at that timestamp while running the same stop and target logic. Also running a diff checker on the two scripts can help find differences:
                          https://www.diffchecker.com/ (publicly available link)
                          Chris L.NinjaTrader Customer Service

                          Comment


                            #14
                            Thanks for the further assistance.

                            I'll keep digging.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by ct, 05-07-2023, 12:31 PM
                            6 responses
                            202 views
                            0 likes
                            Last Post wisconsinpat  
                            Started by kaywai, Today, 06:26 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post kaywai
                            by kaywai
                             
                            Started by kevinenergy, 02-17-2023, 12:42 PM
                            118 responses
                            2,778 views
                            1 like
                            Last Post kevinenergy  
                            Started by briansaul, Today, 05:31 AM
                            0 responses
                            9 views
                            0 likes
                            Last Post briansaul  
                            Started by traderqz, Yesterday, 12:06 AM
                            11 responses
                            28 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Working...
                            X