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

ignored placeorder() method

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

    ignored placeorder() method

    My strategy reverses at entershortstop and enterlongstop. After backtesting, my strategy took a long at 34.14. An exiting and reversing entershortstop at 34.12 wasn't placed and I can't tell why. It says invalid order price, but the order was to be below my long entry, which would be right. This is happening occasionally throughout my backtest. The log is saying things like the stop was greater than or equal to the close of the current bar. Ive been using a 1 tick range for the data series, with atleast 2 ticks distance for the reversing orders. Also, the days with log errors that an order was ignored, weren't necessarily the days an order was ignored under the trades tab in my strategy analyzer.

    2/18/2016 6:00:13 AM Ignored PlaceOrder() method at 2/18/2016 6:00:13 AM: Action=SellShort OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=34.12 SignalName=shortentry' FromEntrySignal='' Reason='Invalid order price, please see log tab'
    Last edited by sampras010; 03-30-2016, 12:27 PM.

    #2
    Hello sampras010,

    Thank you for your post.

    May we review the strategy used that results in these message? Can you attach a screenshot of the settings used in the Strategy Analyzer as well as the instrument(s) used?

    You can attach your strategy to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your strategy > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.

    Comment


      #3
      Ive been backtesting with CL 4-16.
      Attached Files

      Comment


        #4
        I am seeing this occur on the "longentry" in my testing. As I see it the execution occurs on the bar after the condition is true, so the "longentry" is placed based on the average price of the position plus two ticks which may be too close. And in your case on your side the "shortentry" may be too close as well.

        You may wish to increase the distance from the average price of the position.

        Comment


          #5
          Hello sampras010,

          Set the IOrder objects to null when they have been filled. Likely we are trying to call items on an object that is no longer in use.

          Comment


            #6
            When I try it with the I orders equal to null like this


            protected override void OnExecution(IExecution execution)
            {
            if( longorder == null && execution.Order != null && execution.Order.OrderState == OrderState.Filled && execution.Order.Name == "shortentry" && execution.Order.OrderAction == OrderAction.SellShort )
            {



            longorder = EnterLongStop(0, true, 1, (Position.AvgPrice + 2 * TickSize), "longentry");

            }




            the I orders stop submitting
            Attached Files

            Comment


              #7
              Hello sampras010,

              Set the orders to null when they are filled. For example:
              Code:
              if (execution.Order == longorder && execution.Order.OrderState == OrderSate.Filled)
              longorder == null;

              Comment


                #8
                now the backtest stops after the first trade with the same error message


                **NT** Error on calling 'OnExecution' method for strategy 'experiment/d1e65a7719bc4432baa46f17d3d70ba6': Object reference not set to an instance of an object.

                Comment


                  #9
                  I also tried

                  if (execution.Order != shortorder && execution.Order.OrderState == OrderState.Filled)
                  {
                  shortorder = null;
                  }


                  The backtest completes one day and then the error message

                  Comment


                    #10
                    Originally posted by sampras010 View Post
                    I also tried

                    if (execution.Order != shortorder && execution.Order.OrderState == OrderState.Filled)
                    {
                    shortorder = null;
                    }


                    The backtest completes one day and then the error message
                    You would not set an IOrder to null if it was not the one updating.

                    Can you provide your full script with the added check and setting the Order objects to null?

                    Comment


                      #11
                      Hello sampras010,

                      Thank you for your response.

                      So let's try to break down the OnExecution() part here to get an understanding of what you are trying to do here.

                      What needs to happen in OnExecution()? Why does it need to be performed in OnExecution()?

                      Comment


                        #12
                        Originally posted by sampras010
                        I'm trying to duplicate the ATM's reverse at stop function. So after the first short entry at 6, under onexection I'm waiting for that to get filled, then enter a reversing order 2 ticks above, if that gets filled then enter a reversing order 2 ticks below, it that gets filled then a reversing order 2 ticks above, so on and so forth until a profit threshold is reached then I want to cancel the remaining reversing order, and start again the next day. I would think the reversing orders would have to be under on execution because they would only be placed upon a fill. The final cancel order I feel could take place under onbarupdate, after the threshold condition has been met at the same time the final position is closed, but I haven't been able to get that to work. So I put the cancel order under onexecution under the condition that a sell or buy to cover takes place, since sell or buy to cover appear to have a unique identity in the log only after the profit threshold has been met and final position is closed. All in all the cancel order has been working under onexecution, the strategy is reversing as it should. It's just that in backtesting over a month, trades are only being placed several days or less.
                        Attached is my example of how to do this. Please let me know if you have any questions.
                        Attached Files

                        Comment


                          #13
                          You would reset the gross loss as follows:
                          Code:
                          			if (Bars.FirstBarOfSession)
                          			{
                          				glossStart = priorprofitPerformance.AllTrades.TradesPerformance.GrossLoss;
                                          trades = 0;
                          			}
                          			if(Performance.AllTrades.Count > trades)
                          			{
                          				glossDay = priorprofitPerformance.AllTrades.TradesPerformance.GrossLoss - glossStart;
                          			}
                          How is the trade count increased? You would need to implement that into the code if not done already.

                          To stop the strategy until a new day after a condition is met you would use a bool.
                          For example:
                          Code:
                          if (mybool && mycondition)
                          {
                          //place trades
                          }
                          if (conditiontostop)
                          {
                          mybool = false;
                          }
                          if (Bars.FirstBarOfSession)
                          {
                          mybool = true;
                          }

                          Comment


                            #14
                            sampras010,

                            It would be an accumulating count so you would track it on the first bar and subtract it when need to get the current day's count just as I did with the GrossLoss.

                            Comment


                              #15
                              Finally GOT IT. You've been a great help thanks so much

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Jimmyk, 01-26-2018, 05:19 AM
                              6 responses
                              835 views
                              0 likes
                              Last Post emuns
                              by emuns
                               
                              Started by jxs_xrj, 01-12-2020, 09:49 AM
                              6 responses
                              3,291 views
                              1 like
                              Last Post jgualdronc  
                              Started by Touch-Ups, Today, 10:36 AM
                              0 responses
                              11 views
                              0 likes
                              Last Post Touch-Ups  
                              Started by geddyisodin, 04-25-2024, 05:20 AM
                              11 responses
                              62 views
                              0 likes
                              Last Post halgo_boulder  
                              Started by Option Whisperer, Today, 09:55 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post Option Whisperer  
                              Working...
                              X