Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enter Long with limit offset not working

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

    Enter Long with limit offset not working

    Hello,
    I am trying to make limit entries with my automated strategy.

    I however am having a problem.

    I use the following code: EnterLongLimit(Qty2, Close[0] + LimitOffset, "Order2");

    When the LimitOffset = 0 everything is working ok..(orders being executed as if they are market orders)

    However when I adjust the LimitOffset to -2 ...no entries get executed (neither backtest nor sim mode)

    I am trying this on ES 03-15.

    Any advice will be much appreciated.

    #2
    nikolaalx, from the price action - should the orders then still mostly be filled next bar or would they require more bars working in the market to reach / penetrate that limit price for a fill? With the overload you posted the order will expire after the bar they were placed on if not filled. So you might need to either resubmit them if your entry condition is still valid or you would just use the more advanced overload allowing you to specify liveUntilCancelled as parameter.

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for your response.

      I need to have the order active over the next 10 bars.
      If you can assist me with my code it would be of great help:

      Here is my current one : EnterLongLimit(Qty2, Close[0] + LimitOffset, "Order2");

      Thanks.

      Comment


        #4
        Hello nikolaalx,

        Thank you for your note.

        To keep the order alive (and not cancelled at the end of the bar) use the liveUntilCancelled overload.

        For example;

        private IOrder order2 = null;

        order2 = EnterLongLimit(0, true, Qty2, Close[0] + LimitOffset, "Order2");

        EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)

        http://www.ninjatrader.com/support/h...rlonglimit.htm


        After 10 bars you will need to Cancel the order. You will need to use custom logic to achieve this if you have multiple entry orders. If not, you can use BarsSinceEntry()

        if (BarsSinceEntry() >= 10)
        {
        CancelOrder(order2);
        }

        http://www.ninjatrader.com/support/h...sinceentry.htm

        http://www.ninjatrader.com/support/h...ancelorder.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you very much!

          Everything is clear now.

          I only have a side question in regard to "private IOrder order2 = null;"

          Do I have to execute this before any order? I am assuming that it clears any previous stored attributes to the IOrder data for Order2.

          Sorry for the stupid question.

          Comment


            #6
            Hi nikolaalx,

            The entry order is set to an IOrder variable so that it can be used with CancelOrder which requires an IOrder object.

            You will only need to set the order to an IOrder variable if you will need it later for something. (Such as cancelling it)
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi,
              I am trying to cancel an order in the event if it is not filled within x amount of bars.

              I am using the example provided in the help section and from this thread, where It is advised to record the entries as iOrder variables.

              1. I record the entries in the iOrder as follow:




              private IOrder EnterShort = null;
              private IOrder EnterLong = null;


              2. Then Whenever I make an entry, I record the currentBar as a variable, that I later on use to compare and to determine if the cancel logic is met.


              if (Entry Conditions)

              {
              barNumberOfOrder = CurrentBar;
              EnterLong = EnterLongLimit(0, true, 2 , Close[0] + BuyLimitOffset, "EnterLong");
              SetProfitTarget("EnterLong", CalculationMode.Ticks, ProfitTaker);
              SetStopLoss("EnterLong", CalculationMode.Ticks, StopLoss, false);
              }


              3. And here is the cancellation logic.


              if (CurrentBar == barNumberOfOrder + OrderCancelBars

              {
              CancelOrder(EnterShort);
              CancelOrder(EnterLong);
              }



              This does not seem to work. It seems to prevent all orders to take place.

              Any ideas on how to do this?

              I want to cancel orders that were not filled within a certain number of bars.

              Thanks.

              Comment


                #8
                nikolaalx, do you see any errors in your log tab when this is run? I would expect to see some object reference issues, since you don't check for null when first assigning the IOrder and then not for null when accessing in your CancelOrder call.

                I would also suggest to check for >= instead of == in your

                if (CurrentBar >= barNumberOfOrder + OrderCancelBars
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Hi,
                  I use backtest and can not see any log errors..as far as I know.

                  I also tried with >= and there was no difference in the result.

                  The code in the way I provided it (and also with the >= instead of the ==)basically cancels any future trades from the moment the condition is met.

                  Comment


                    #10
                    Hello nikolaalx,

                    Thank you for your response.

                    I would look to the value of OrderCancelBars, and when this is set - in other words what is OrderCancelBars and what are the Entry Conditions that would need to return true in order to set OrderCancelBars?

                    Comment


                      #11
                      Hi,
                      OrderCancelBars is just a integer variable that I have set instead of a fixed number. The idea is to add a "n" amount of bars to the current one and compare to the variable CurrentBar which is set, whenever a new limit order is being initiated (as in being placed, but not filled).

                      I always place limit orders with an offset to the current price, which is why they never get filled immediately...and takes some time.

                      I want to cancel limit orders that were not filled for a "n" amount of bars...which is why I have this whole piece of code.

                      Please let me know what you think.

                      Thank you.
                      Last edited by nikolaalx; 02-03-2015, 03:37 PM.

                      Comment


                        #12
                        Hi nikolaalx,

                        Without knowing if
                        Code:
                        if (CurrentBar == barNumberOfOrder + OrderCancelBars)
                        will evaluate as true I can't be sure that the condition is even being triggered.

                        You can add a print before CancelOrder() is called. Does this print show up?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Here is the exact code that I will use.

                          if (CurrentBar == barNumberOfOrder + OrderCancelBars
                          && Performance.AllTrades.TradesPerformance.Currency.C umProfit != 0
                          && Position.MarketPosition == MarketPosition.Flat
                          )


                          {
                          PrintWithTimeStamp("Cancel Order Works");
                          }


                          I assume I need to test this in market replay/real market mode...instead of backtest right in order for the Print to work?

                          EDITED: I just backtested and nothing gets printed on the chart. Shall I test on live market replay mode?
                          Last edited by nikolaalx; 02-03-2015, 04:11 PM.

                          Comment


                            #14
                            Hello,

                            Prints also work in backtest.

                            Does this print come out when you expect?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              As a matter of fact it does.

                              On every new limit order I added: PrintWithTimeStamp("Order Works");

                              Then if an order is not fulfilled within the next 5 bars, : PrintWithTimeStamp("Cancel Order Works");

                              Here is a log of the output window:

                              1/26/2015 12:10:00 PM Order Works
                              1/26/2015 12:15:00 PM Cancel Order Works
                              1/26/2015 12:32:00 PM Order Works
                              1/26/2015 12:37:00 PM Cancel Order Works

                              If I am thinking in the right direction, the problem is most likely in the execution of the cancellation.

                              I currently use :
                              CancelOrder(EnterShort);
                              CancelOrder(EnterLong);

                              and I record the entry in the iOrder as follow:

                              EnterLong = EnterLongLimit(0, true, 2 , Close[0] + BuyLimitOffset, "EnterLong");

                              I also have
                              private IOrder EnterLong = null;

                              before the OBU


                              Please let me know what you think.

                              Thank you,

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by helpwanted, Today, 03:06 AM
                              1 response
                              12 views
                              0 likes
                              Last Post sarafuenonly123  
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              9 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by aussugardefender, Today, 01:07 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post aussugardefender  
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              242 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              9 responses
                              387 views
                              1 like
                              Last Post Gavini
                              by Gavini
                               
                              Working...
                              X