• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

No suitable method found to override...

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

    No suitable method found to override...

    Hello

    I am trying to code a strategy that woks on Calculate.OnEachTick that submits Short/LongStopMarket orders a few ticks below/above the Stop price and I need to cancel the pending orders before they are executed, in case my condition for triggering the order gets invalidated before triggering the order.

    I found that I have to 'Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.', but I must have left something out, coz I'm getting the error 'No suitable method found to override'.

    I suspect it is because there is nothing in the () after OnOrderUpdate, but I don't quite understand how to fill in these parameters
    (Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)


    My code is like this:

    private Order Short1 = null;
    protected override void OnBarUpdate()
    {
    if (condition true)
    {
    EnterShortStopMarket(Convert.ToInt32(Target1Cont), (GetCurrentBid(0) + (StopOffsetShort * TickSize)) , @"Short1");
    }
    else if (

    (condition false)
    && Order(Short1 = OrderState.TriggerPending))
    {
    CancelOrder(Short1);
    }

    }
    ....

    protected override void OnOrderUpdate()
    {
    if (order.Name == Short1)
    Short1 = order;
    if (Short1 != null
    && Short1 == order)
    if (Short1Order.OrderState == OrderState.Cancelled)
    {
    Short1 = null;
    }

    }

    #2
    Hi itrader46, thanks for your post.

    It seems like this parameter is not evaluating as a double:
    (GetCurrentBid(0) + (StopOffsetShort * TickSize))

    Try casting it to a double and your entry should compile after that.

    e.g.

    (double)(GetCurrentBid(0) + (StopOffsetShort * TickSize))

    If you have any further questions, please let me know.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello

      How do I fill in the OnOrderUpdate if I don't have all the parameters? For instance a LongStopMarket order has no Limit
      Thank you

      Comment


        #4
        Hi itrader46,

        If a stop or limit price is not applicable to an order type, then just enter 0 for that parameter.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Right... so I don't have to enter something like this, which generates a lot of errors (see attachment) Errors.pdf

          "protected override void OnOrderUpdate(Order order, (double)(GetCurrentAsk(0) + (StopOffsetLong * TickSize)), (double)(GetCurrentAsk(0) + (StopOffsetLong * TickSize)), Convert.ToInt32(Target1Cont), int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError) "

          Comment


            #6
            Can you please tell me if the two variants below are equivalent? The second one looks tidier and it's shorter. Basically, I am trying to submit three Stop Limit orders on CalculateOnEachTick a few ticks off the last bid / ask, but cancel it if the condition becomes invalid before triggering, while the orders are in Pending state

            - FIRST

            if (
            // Condition group 1
            entryShort1 == null && (condition))
            {
            EnterShortStopLimit(Convert.ToInt32(Target1Cont), (GetCurrentBid(0) + (StopOffsetShort * TickSize)), (GetCurrentBid(0) + (StopOffsetShort * TickSize)) , @"Short1");

            }

            if (entryShort1.OrderState == OrderState.TriggerPending &&(condition))
            {
            CancelOrder(entryShort1);
            }

            if (entryShort2 == null && (condition))
            {
            EnterShortStopLimit(Convert.ToInt32(Target2Cont), (GetCurrentBid(0) + (StopOffsetShort * TickSize)), (GetCurrentBid(0) + (StopOffsetShort * TickSize)) , @"Short2");
            }

            if (entryShort2.OrderState == OrderState.TriggerPending &&(condition))
            {
            CancelOrder(entryShort2);
            }

            if (entryShort3 == null && (condition))
            {
            EnterShortStopLimit(Convert.ToInt32(Target3Cont), (GetCurrentBid(0) + (StopOffsetShort * TickSize)), (GetCurrentBid(0) + (StopOffsetShort * TickSize)) , @"Short3");
            }

            if (entryShort3.OrderState == OrderState.TriggerPending &&(condition)
            {
            CancelOrder(entryShort3);
            }

            - SECOND

            " if (
            // Condition group 2
            entryLong1 == null
            && entryLong2 == null
            && entryLong3 == null
            && (condition))
            {
            EnterLongStopLimit(Convert.ToInt32(Target1Cont), (GetCurrentAsk(0) + (StopOffsetLong * TickSize)), (GetCurrentAsk(0) + (StopOffsetLong * TickSize)) , @"Long1");
            EnterLongStopLimit(Convert.ToInt32(Target1Cont), (GetCurrentAsk(0) + (StopOffsetLong * TickSize)), (GetCurrentAsk(0) + (StopOffsetLong * TickSize)) , @"Long2");
            EnterLongStopLimit(Convert.ToInt32(Target1Cont), (GetCurrentAsk(0) + (StopOffsetLong * TickSize)), (GetCurrentAsk(0) + (StopOffsetLong * TickSize)) , @"Long3");

            }

            if (entryLong1.OrderState == OrderState.TriggerPending &&(condition))
            {
            CancelOrder(entryLong1);
            }

            if (entryLong2.OrderState == OrderState.TriggerPending &&(condition))
            {
            CancelOrder(entryLong2);
            }

            if (entryLong3.OrderState == OrderState.TriggerPending &&(condition)
            {
            CancelOrder(entryLong3);
            }

            Comment


              #7
              Hi itrader46, thanks for your reply.

              The second implementation looks fine. I'm not sure if this code is running in OnBarUpdate or in OnOrderUpdate, it should be in OnBarUpdate so that it is called on each tick of the market.

              Please let me know if I can assist any further with the strategy, best regards.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                The strategy works, but it doesn't cancel the pending Limit orders when the triggering condition becomes false. Any ideas?

                Comment


                  #9
                  Hi itrader46,

                  Please turn on TraceOrders in your strategy, then run it so that the calculation should run. If the cancelation code is being hit but ignored for some reason, it will show up in the trace orders. Also, use Print statements to see if 1. the cancelation code is actually being reached and 2. The condition is true when expected.
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    ...I'm not sure how to code the print for reaching the cancellation code or checking the condition being true when expected

                    Comment


                      #11
                      Hi itrader46, thanks for your reply.

                      First, you would want to Print these conditions to make sure the entry is working properly.

                      entryLong1 == null
                      && entryLong2 == null
                      && entryLong3 == null
                      && (condition))

                      Then print out the data before the check for trigger pending:

                      Print("Checking entryLong1");
                      Print(entryLong1.OrderState);
                      Print(condition);
                      if (entryLong1.OrderState == OrderState.TriggerPending &&(condition))
                      {
                      Print("Trying to cancel entryLong1");
                      CancelOrder(entryLong1);
                      }
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello

                        Firstly, I would like to thank you for your help

                        Secondly, the prints look a bit weird, as you can see below: the check for the entries was Ok, but when the condition became 0, it was only trying to cancel Short1, then the position was cancelled automatically at the end of bar, while the strategy was still trying to cancel Short1, then an entry for only one order was processed in the opposite direction, followed by an error that disabled the strategy.


                        R = 1
                        04/10/2019 18:39:48 Strategy 'BreakDraft/178974590': Entered internal SubmitOrderManaged() method at 04/10/2019 18:39:48: BarsInProgress=0 Action=SellShort OrderType=StopLimit Quantity=1 LimitPrice=52.42 StopPrice=52.42 SignalName='Short1' FromEntrySignal=''
                        Submitted
                        Checking entryShort2
                        R = 1
                        04/10/2019 18:39:48 Strategy 'BreakDraft/178974590': Entered internal SubmitOrderManaged() method at 04/10/2019 18:39:48: BarsInProgress=0 Action=SellShort OrderType=StopLimit Quantity=1 LimitPrice=52.42 StopPrice=52.42 SignalName='Short2' FromEntrySignal=''
                        Submitted
                        Checking entryShort3
                        R = 1
                        04/10/2019 18:39:48 Strategy 'BreakDraft/178974590': Entered internal SubmitOrderManaged() method at 04/10/2019 18:39:48: BarsInProgress=0 Action=SellShort OrderType=StopLimit Quantity=1 LimitPrice=52.42 StopPrice=52.42 SignalName='Short3' FromEntrySignal=''
                        .
                        .
                        .
                        R = 0
                        Trying to cancel entryShort1
                        04/10/2019 18:40:00 - Flat
                        R = 0
                        Trying to cancel entryShort1
                        04/10/2019 18:40:00 - Flat
                        R = 0
                        Trying to cancel entryShort1
                        04/10/2019 18:40:00 - Flat
                        R = 0
                        Trying to cancel entryShort1
                        04/10/2019 18:41:00 - Flat
                        04/10/2019 18:40:01 Strategy 'BreakDraft/178974590': Cancelled expired order: BarsInProgress=0, orderId='970a95aa69c648b3a5aeedda73998a37' account='Sim101' name='Short1' orderState=Accepted instrument='CL 11-19' orderAction=SellShort orderType='Stop Limit' limitPrice=52.42 stopPrice=52.42 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=10093 time='2019-10-04 18:39:48' gtd='2099-12-01' statementDate='2019-10-04'
                        04/10/2019 18:40:01 Strategy 'BreakDraft/178974590': Cancelled expired order: BarsInProgress=0, orderId='ad3291be1e994f98bfee8dd56d70c5f8' account='Sim101' name='Short2' orderState=Accepted instrument='CL 11-19' orderAction=SellShort orderType='Stop Limit' limitPrice=52.42 stopPrice=52.42 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=10094 time='2019-10-04 18:39:48' gtd='2099-12-01' statementDate='2019-10-04'
                        04/10/2019 18:40:01 Strategy 'BreakDraft/178974590': Cancelled expired order: BarsInProgress=0, orderId='82441f8c69744f92804e54b55a442f4d' account='Sim101' name='Short3' orderState=Accepted instrument='CL 11-19' orderAction=SellShort orderType='Stop Limit' limitPrice=52.42 stopPrice=52.42 quantity=1 tif=Day oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=10095 time='2019-10-04 18:39:48' gtd='2099-12-01' statementDate='2019-10-04'
                        R = 0
                        Trying to cancel entryShort1
                        04/10/2019 18:41:00 - Flat
                        R = 0
                        Trying to cancel entryShort1
                        04/10/2019 18:41:00 - Flat
                        R = 0
                        Trying to cancel entryShort1
                        04/10/2019 18:41:00 - Flat
                        .
                        .
                        .
                        04/10/2019 18:41:00 - Flat
                        04/10/2019 18:41:00 - Flat
                        04/10/2019 18:41:00 - Flat
                        Checking entryLong1
                        S = 0
                        04/10/2019 18:40:39 Strategy 'BreakDraft/178974590': Entered internal SubmitOrderManaged() method at 04/10/2019 18:40:39: BarsInProgress=0 Action=Buy OrderType=StopLimit Quantity=1 LimitPrice=52.64 StopPrice=52.64 SignalName='Long1' FromEntrySignal=''
                        Strategy 'BreakDraft': Error on calling 'OnBarUpdate' method on bar 6696: Object reference not set to an instance of an object.
                        Disabling NinjaScript strategy 'BreakDraft/178974590'

                        Comment


                          #13
                          Hello itrader46, thanks for your reply.

                          The order canceling is by design. You will need to either re-submit the order on every bar or use the special overload that we provide where you can turn on isLiveUntilCancelled.

                          e.g. EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName);

                          Please read this page on the order handling rules in NinjaTrader:
                          https://ninjatrader.com/support/help...d_approach.htm

                          For the Object reference error, you are likely using an Order object or some other object that is not initialized yet (it's null) so you will need to check for null before accessing a property or method of any object. You can also use Visual Studio to set breakpoints and it will break on the line that threw an exception.
                          Chris L.NinjaTrader Customer Service

                          Comment


                            #14
                            OK, but why was the order not getting cancelled?
                            That is the main thing I'm trying to achieve.

                            Comment


                              #15
                              Hello itrader46,

                              There is a State.Filled state that can be checked. Cancel the order using this state. The CancelOrder code is not being reached.

                              e.g.

                              if(MyOrder.OrderState != OrderState.Filled && <condition>)
                              CancelOrder(MyOrder);
                              Chris L.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by chnh1, Yesterday, 11:51 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post chnh1
                              by chnh1
                               
                              Started by Jasper99, Yesterday, 10:29 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post Jasper99  
                              Started by Jasper99, Yesterday, 09:50 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Jasper99  
                              Started by StevenNelson, Yesterday, 05:57 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post StevenNelson  
                              Started by srbdoc, Yesterday, 03:59 PM
                              1 response
                              19 views
                              0 likes
                              Last Post NinjaTrader_EricB  
                              Working...
                              X