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

EnterLongLimit does not execute

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

    EnterLongLimit does not execute

    in a simple MA crossover,

    if ((GetCurrentBid() >=SMA[0]))
    {

    EnterLongLimit(GetCurrentBid(),"LONG");
    }



    Draw.ArrowUp(this, @"SMABuy" + CurrentBars[0].ToString(), true, 0, GetCurrentBid(0), Brushes.Lime);

    I see the arrows drawn but no executions...

    also, I tried to force an execution by putting in this, thinking that on the next onBarUpdate if the order is not filled, and thus position still flat, i'll send a market order.

    Both ways does not show any executions


    if (Position.MarketPosition == MarketPosition.Flat)
    {
    EnterLong();
    }
    Last edited by Boonfly8; 07-14-2018, 07:04 PM.

    #2
    Hello Boonfly8,

    Use TraceOrders and print the order object in OnOrderUpdate() to find out what is happening with the order.

    Its likely the order is being automatically cancelled due the liveUntilCancelled not being used (which defaults to false) or is used and is set to false and the bar the order was placed closed and the order was not filled.

    With TraceOrders set to true in State.Configure and the order object printed in OnOrderUpdate what is the output that appears in the output window?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      I have been searching the forums/NT Help guide for liveUntilCancelled and I can't seem to find much information. The only thing that was mentioned was that it is used for limit orders and that if it doesn't get executed on bar close, it will cancel.

      I will try to debug with the suggestions you mentioned but in the meantime can you point to me some documentation about this field.

      Also to note, is that I am using the above code for historical and if prices are only updated when the bar closes and like you mentioned, the bar the order was placed closed and the order was not filled.

      Comment


        #4
        Hello Boonfly8,

        Always debug the script using prints to get more information about what is happening to further address the behavior.

        The help guide mentions isLiveUntilCancelled on managed approach order methods that can sit at a working or accepted state:
        "isLiveUntilCancelled - The order will NOT expire at the end of a bar, but instead remain live until the CancelOrder() method is called or its time in force is reached."

        Below is a public link to the help guide on EnterLongLimit().


        By default an order that does not use the liveUntilCancelled bool will have this set to false on the order. If the order is not resubmitted on the next bar using the same signal name and liveUntilCancelled is false, the order will cancel when the submission bar closes and the new bar starts.

        However, if the order is resubmitted on the new bar using the same signal name, then instead of being cancelled the order will remain alive and the order id will be retained.
        If the submission price is different, a pending change will also be called and the Order.OrderState will be OrderState.PendingChange > then Working/Accepted instead of OrderState.Cancelled and the order will be moved.

        For example, to place an order that will not close at the end of the bar:

        EnterLongLimit(0, true, 1, Low[0], "long1");
        EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)

        Below is a link to an example script that keeps an order alive by resubmitting it using a condition and a variable.


        And a link to an example script that keeps an exit order alive by using liveUntilCancelled (ProfitChaseStopTrailExitOrdersExample_NT8.zip).



        A small tip, the TimeInForce (Day or GTC) will be how the brokerage / exchange servers handles if the order will cancel at the end of the day. isLiveUntilCancelled however, is an internal NinjaScript Strategy option that will cause NinjaTrader to cancel the order if it has not been filled when the current bar closes.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I will give that a try, Thanks Chelsea!

          Comment


            #6
            Hello Chelsea,

            Just to clarify your response and to get a better understanding of the order handling process of NT8, when you quote:

            "isLiveUntilCancelled - The order will NOT expire at the end of a bar, but instead remain live until the CancelOrder() method is called or its time in force is reached."

            to my understanding, this would be the following sequence of events per that quote,

            using the above example below and using calculate.onEachTick where each subsequent event is a new OnBarUpdate() iteration,

            if ((GetCurrentBid() >=SMA[0]))
            {

            EnterLongLimit(GetCurrentBid(),"LONG");
            }

            Event 1. if the condition met, NT places a bid at the current bid say 100.00
            Event 2 if the market ticked up and the bid was not filled at100.00, the order would remain at 100.00 unless in the code was a CancelOrder() method called. If none exists, the order will remain at the "stale" price of 100.00

            What happens to the order if the update cycle on Event 2 condition is no longer true? For example, the current bid no longer is above the SMA? Will the order still remain at 100.00 forever?

            What happens to the order if the update cycle on Event 2 condition still exist? Will NT send a new order to buy one tick higher at the new bid if the market ticked up one tick between an OnBarUpdate() iteration?

            Comment


              #7
              Hello Boonfly8,

              With the example you provided isLiveUntilCancelled will be false. When isLiveUntilCancelled is not used, it defaults to false.

              EnterLongLimit(GetCurrentBid(),"LONG");

              This means that because the order did not fill, the order would be cancelled when the bar it is submitted on closes and the order is not resubmitted.

              If the order was submitted with isLiveUntilCancelled as true, the order would remain working when the bar closes.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_ChelseaB View Post
                Hello Boonfly8,

                With the example you provided isLiveUntilCancelled will be false. When isLiveUntilCancelled is not used, it defaults to false.

                EnterLongLimit(GetCurrentBid(),"LONG");

                This means that because the order did not fill, the order would be cancelled when the bar it is submitted on closes and the order is not resubmitted.

                If the order was submitted with isLiveUntilCancelled as true, the order would remain working when the bar closes.
                Yes, let us assume isLiveUntilCancelled is true. My question is...then what happens to that order if not other logic is put in the code? Please refer to my question above as I have provided a few scenarios that I think it is important to consider.

                Event 1. if the condition met, NT places a bid at the current bid say 100.00
                Event 2 if the market ticked up and the bid was not filled at100.00, the order would remain at 100.00 unless in the code was a CancelOrder() method called. If none exists, the order will remain at the "stale" price of 100.00

                What happens to the order if the update cycle on Event 2 condition is no longer true? For example, the current bid no longer is above the SMA? Will the order still remain at 100.00 forever?

                What happens to the order if the update cycle on Event 2 condition still exist? Will NT send a new order to buy one tick higher at the new bid if the market ticked up one tick between an OnBarUpdate() iteration?

                Comment


                  #9
                  Hello Boonfly8,

                  EnterLongLimit(0, true, 1, Low[0] - 5 * TickSize, "entry");
                  EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

                  With an order that has isLiveUntilCancelled set to true, the order remains working on the next bar even if it is not resubmitted.

                  No new order will be submitted.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_ChelseaB View Post
                    Hello Boonfly8,

                    EnterLongLimit(0, true, 1, Low[0] - 5 * TickSize, "entry");
                    EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

                    With an order that has isLiveUntilCancelled set to true, the order remains working on the next bar even if it is not resubmitted.

                    No new order will be submitted.
                    I tried using EnterLongLimit(GetCurrentBid(),"LONG");

                    However, it will not execute unless I have isLiveUntilCancelled is set to true. But you said that it doesn't have to be set to true. What method is there that we can use to send limit orders without having that bool set to true?

                    Comment


                      #11
                      Hello Boonfly8,

                      When you mention "But you said that it doesn't have to be set to true.", I'm not quite sure what you are referring to. Is this from a post in this thread?

                      You can choose to resubmit an order on each new bar to keep it alive if you don't want to use isLiveUntilCancelled.

                      There isn't a method for this (if you are referring to a method as a function). You just resubmit it on the new bar.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        "With the example you provided isLiveUntilCancelled will be false. When isLiveUntilCancelled is not used, it defaults to false."

                        EnterLongLimit(GetCurrentBid(),"LONG");

                        This means that because the order did not fill, the order would be cancelled when the bar it is submitted on closes and the order is not resubmitted.

                        If the order was submitted with isLiveUntilCancelled as true, the order would remain working when the bar closes.

                        The problem is that if one wants to use EnterLongLimit() and specify a price based on a condition such as if CurrentBid() >= SMA, the condition will go in and out of validity based on how the market moves and where the SMA is. When I tried to use EnterLongLimit(GetCurrentBid(),"LONG"), I did not get any executions and that is why this thread exists. Then you suggested that we have to use isLiveUntilCancelled. But I do not want to keep that order at the same price all the time if the condition goes to false on the next update. I would much rather send a limit order when the condition is true, cancel it at the end of the bar(or tick if using calculate on tick), then see if the condition is true on the next OnBarUpdate(). And to do that, I did EnterLongLimit(GetCurrentBid(),"LONG"), just try to get long at the current bid when the condition is true, but that does not work unless I set isLiveUntilCancelled....

                        is there a way for EnterLongLimit() to send limit orders, cancel them at the end of the bar, and resend if the condition is true again without having to set isLiveUntilCancelled to true? Because I don't want that order to sit blindly there if the condition is no longer true on subsequent OnBarUpdates()

                        Comment


                          #13
                          Hello Boonfly8,

                          It is true, that if isLiveUntilCancelled is not used in the overload parameters, then it is false.

                          I'm not understanding where you are getting the information that isLiveUntilCancelled does not need to be used. Are you assuming that isLiveUntilCancelled will be true if it is not used?

                          Yes, isLiveUntilCancelled does not have to be used. If it is not used, then it is false. Meaning the order will be cancelled if the bar closes.

                          Can you clarify what you mean when you mention "But you said that it doesn't have to be set to true."
                          What do you think this means?


                          When you mention "is there a way for EnterLongLimit() to send limit orders, cancel them at the end of the bar, and resend if the condition is true again without having to set isLiveUntilCancelled to true?"

                          Sure, have isLiveUntilCancelled be false or don't use it. Don't re-submit the order on the new bar so it is cancelled. Then 2 bars later submit the order again.

                          But I don't quite understand. Why would you allow an order to cancel if you are planning to resubmit it again? Why not just allow it to keep working?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by NinjaTrader_ChelseaB View Post
                            Hello Boonfly8,

                            It is true, that if isLiveUntilCancelled is not used in the overload parameters, then it is false.

                            I'm not understanding where you are getting the information that isLiveUntilCancelled does not need to be used. Are you assuming that isLiveUntilCancelled will be true if it is not used?

                            Yes, isLiveUntilCancelled does not have to be used. If it is not used, then it is false. Meaning the order will be cancelled if the bar closes.

                            Can you clarify what you mean when you mention "But you said that it doesn't have to be set to true."
                            What do you think this means?


                            When you mention "is there a way for EnterLongLimit() to send limit orders, cancel them at the end of the bar, and resend if the condition is true again without having to set isLiveUntilCancelled to true?"

                            Sure, have isLiveUntilCancelled be false or don't use it. Don't re-submit the order on the new bar so it is cancelled. Then 2 bars later submit the order again.

                            But I don't quite understand. Why would you allow an order to cancel if you are planning to resubmit it again? Why not just allow it to keep working?
                            because in the meantime, the indicators would have updated and the condition to enter a trade may not be true. If we resubmit, it might be at a better or worse price.

                            I think we are confusing each other. All I want to do is that when the (GetCurrentBid() >=SMA[0]), send a limit order to buy at the current bid. If it is not filled in the same tick, then cancel it and wait for the next OnBarUpdate to see if the condition is true again, then resubmit at the price then.

                            When using EnterLongLimit(), do we have to set IsLiveUntilCancelled to true to be able to send out limit orders? Because that is the problem. Unless I set it to true, I don't see any executions on the chart. However, I do not want those order to remain in the market indefinitely or until timeinforce kicks in
                            Last edited by Boonfly8; 07-19-2018, 07:25 AM.

                            Comment


                              #15
                              Hello Boonfly8,

                              Ok, so specifically, you want to place an order when a condition is true, and if its not filled in 1 single tick, then cancel the order and wait for the submission bar to close. After the submission bar closes, are you wanting to check the condition again or do you want to wait for the bar after to close?

                              So the script will need intra-bar granularity of 1 tick so that you can cancel the order if it is not filled in 1 single tick.

                              The order would be placed when BarsInProgress is 0, and then you would need to make sure it is accepted / working on the next tick and cancel it if it did not fill in BarsInProgress 1.

                              In this case, since you are cancelling after 1 tick you would be cancelling the order before the submission bar closes, so it wouldn't matter if you use isLiveUntilCancelled or not.

                              The example below assumes that the entry condition would be checked again after the primary bar closes.

                              Code:
                              private Order myEntry;
                              
                              protected override void OnStateChange()
                              {
                              if (State == State.Configure)
                              {
                              	AddDataSeries(BarsPeriodType.Tick, 1);
                              }
                              }
                              
                              protected override void OnBarUpdate()
                              {
                              // when the primary bar closes check the conditions for an entry
                              if (BarsInProgress == 0 && myEntry == null /* && conditions to enter order */)
                              {
                              	EnterLongLimit(1, false, 1, GetCurrentAsk() - TickSize, "entry");
                              }
                              // on the first tick after the order begins working cancel the order
                              else if (BarsInProgress == 1 && myEntry != null && myEntry.OrderState == OrderState.Working)
                              {
                              	CancelOrder(myEntry);
                              }
                              }
                              
                              protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string comment)
                              {
                              Print(string.Format("{0} | {1}", Times[1][0], order.ToString() ));
                              
                              // assign the order to a variable to use with CancelOrder in OnBarUpdate
                              if (order.Name == "entry" && myEntry == null)
                              	myEntry = order;
                              
                              // if the entry is filled or cancelled reset to null to allow for a new entry when a primary bar closes.
                              if (myEntry != null && (myEntry.OrderState == OrderState.Filled || myEntry.OrderState == OrderState.Cancelled))
                              	myEntry = null;
                              }
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DanielSanMartin, Yesterday, 02:37 PM
                              2 responses
                              13 views
                              0 likes
                              Last Post DanielSanMartin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              4 responses
                              12 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by terofs, Today, 04:18 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by nandhumca, Today, 03:41 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post nandhumca  
                              Started by The_Sec, Today, 03:37 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post The_Sec
                              by The_Sec
                               
                              Working...
                              X