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

Backtesting with Limit Orders

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

    Backtesting with Limit Orders

    Hello,

    Using
    NT7
    Strategy Wizard

    I notice the following:

    When I use:
    EnterLongLimit(DefaultQuantity, GetCurrentBid() - 8 * TickSize, "LONG");

    I get many many many Cancel limit orders during backtesting. The back test results are very different too as get less trades.

    But when I add
    EnterLongLimit(0,true,DefaultQuantity, GetCurrentBid() - 8 * TickSize, "LONG");

    I get no more Cancel Limit orders add this. The back test results are very different too as more trades.

    Please explain the difference of which one to use during back testing for more accurate back testing results.

    Please see attachment.

    Thanks for your help.
    Attached Files

    #2
    Hello simple_goodoboy,

    From the help guide:

    EnterLongLimit(int quantity, double limitPrice, string signalName)

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

    liveUntilCancelled
    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 has been reached.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      liveUntilCancelled
      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 has been reached.

      http://ninjatrader.com/support/helpG...rlonglimit.htm
      Thank you,

      So for example.

      liveUntilCancelled set to False

      if bar1 condition for Long Limit Order was TRUE, a limit order is pending.

      if bar2 closes and long limit order is still pending, will that limit order be canceled ?

      Thanks

      Comment


        #4
        Hello simple_goodoboy,

        If the condition is not true on the second bar then yes, that order would be cancelled as liveUntilCancelled is false and the bar the order was live on closed and the order was not resubmitted.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello simple_goodoboy,

          If the condition is not true on the second bar then yes, that order would be cancelled as liveUntilCancelled is false and the bar the order was live on closed and the order was not resubmitted.
          Thank you ChelseaB,

          Thank you,

          What if :

          liveUntilCancelled is set to TRUE

          if bar1 condition for Long Limit Order was TRUE, a limit order is pending.

          Now the a limit order is pending from condition being true on bar1.

          if bar2 closes and the condition is still TRUE, will another limit order be created or the same limit order from bar1 will still be pending?

          Thanks,

          Comment


            #6
            Hello simple_goodoboy,

            The first submitted limit order will still be working due to the liveUntilCancelled being true.

            For a second order to be submitted, this would depend on the settings for EntriesPerDirection and EntryHandling and whether unique signal names are used.

            If EntriesPerDirection is 1 and EntryHandling is AllEntries the second order will be ignored.
            If EntriesPerDirection is 2 the second order will be placed.
            If EntriesPerDirection is 1 and EntryHandling is UniqueEntries and the two orders have the same signal names the second order will be ignored.
            If EntriesPerDirection is 1 and EntryHandling is UniqueEntries and the two orders have different signal names the second order will be placed.

            (edited links changed for NT7)

            Last edited by NinjaTrader_ChelseaB; 03-29-2017, 07:16 AM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello simple_goodoboy,

              The first submitted limit order will still be working due to the liveUntilCancelled being true.

              For a second order to be submitted, this would depend on the settings for EntriesPerDirection and EntryHandling and whether unique signal names are used.

              If EntriesPerDirection is 1 and EntryHandling is AllEntries the second order will be ignored.
              If EntriesPerDirection is 2 the second order will be placed.
              If EntriesPerDirection is 1 and EntryHandling is UniqueEntries and the two orders have the same signal names the second order will be ignored.
              If EntriesPerDirection is 1 and EntryHandling is UniqueEntries and the two orders have different signal names the second order will be placed.


              http://ninjatrader.com/support/helpG...ryhandling.htm

              Thank you so much ChelseaB

              I would like to take one limit order only and hit it pending so I will it how you have it there.

              Do I need to add this logic below in my code AND set the following in the attachment when enabling my strategy to run?

              // If an open position already exists, subsequent EnterLong() calls are ignored.
              protected override void Initialize()
              {
              EntriesPerDirection = 1;
              EntryHandling = EntryHandling.AllEntries;
              }
              Attached Files

              Comment


                #8
                Hello simple_goodoboy,

                Those are the default settings.
                You can choose to add these if you would like but with those particular values it would not cause any change.
                You can also set this in the strategy parameters when running the script.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello simple_goodoboy,

                  Those are the default settings.
                  You can choose to add these if you would like but with those particular values it would not cause any change.
                  You can also set this in the strategy parameters when running the script.
                  Thank you ChelseaB

                  Need help on this concern.

                  1. If I have EntriesPerDirection = 1; and EntryHandling = EntryHandling.AllEntries; and lets say I have a limit order pending or a limit ordered already filled, will the below conditions still execute?

                  For instance if I have the following logic to enter long order

                  if (Close[0]>Open[0])

                  Entrylong;
                  Variable0=1;


                  2. Will Variable0 equal 1 if i am already in a limit order or limit order pending and the if condition execute and is TRUE?

                  3. I am trying to make sure if I am in a position or limit order pending, that variable0 = 1 does not execute.

                  Maybe if I add Position.Market = = Market.Flat it will hold the if condition FALSE while a limit order is open or pending?

                  4. Will Position.Market = = Market.Flat become TRUE or FALSE if a limit order is pending?

                  Thanks

                  Comment


                    #10
                    Originally posted by simple_goodoboy View Post
                    Thank you ChelseaB

                    Need help on this concern.

                    1. If I have EntriesPerDirection = 1; and EntryHandling = EntryHandling.AllEntries; and lets say I have a limit order pending or a limit ordered already filled, will the below conditions still execute?

                    For instance if I have the following logic to enter long order

                    if (Close[0]>Open[0])

                    Entrylong;
                    Variable0=1;


                    2. Will Variable0 equal 1 if i am already in a limit order or limit order pending and the if condition execute and is TRUE?

                    3. I am trying to make sure if I am in a position or limit order pending, that variable0 = 1 does not execute.

                    Maybe if I add Position.Market = = Market.Flat it will hold the if condition FALSE while a limit order is open or pending?

                    4. Will Position.Market = = Market.Flat become TRUE or FALSE if a limit order is pending?

                    Thanks
                    Hello,

                    Can I have some help on the questions above please?

                    Thanks

                    Comment


                      #11
                      Hello simple_goodoboy,

                      This depends on the order. Are you using signal names?

                      If you are not using signal names, the original order will be modified instead of a second order being placed.

                      If using different signal names the second order will be ignored.

                      Either way, If EntriesPerDirection is 1 and EntryHandling is AllEntries there won't be a second order even if that first order hasn't filled.


                      With the exact code you have, there are no brackets surrounding the action block. With this code, Variable0 will always be set to 1 no matter what. It is not in a condition.


                      To see if your order has been placed, save the order object to an IOrder variable. Then before placing check to see if that object is null, or if the OrderState is .Working or .Accepted.



                      When you ask "4. Will Position.Market = = Market.Flat become TRUE or FALSE if a limit order is pending?" this is hard to answer as these two items are not related.

                      I will say no, since if a limit order becomes pending, working, or accepted, this by itself will not cause the position to change.
                      Only order fills can cause the position to change.
                      Chelsea B.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by mmckinnm, Today, 01:34 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post mmckinnm  
                      Started by f.saeidi, Today, 01:32 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post f.saeidi  
                      Started by traderqz, Today, 12:06 AM
                      9 responses
                      16 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by kevinenergy, 02-17-2023, 12:42 PM
                      117 responses
                      2,766 views
                      1 like
                      Last Post jculp
                      by jculp
                       
                      Started by Mongo, Today, 11:05 AM
                      5 responses
                      15 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X