Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy not entering trade

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

    Strategy not entering trade

    Hi

    I am backtesting a strategy that uses EnterLongStop to enter a trade, and ExitLongStop & ExitLongLimit to manage and exit the trade.

    The strategy works on the whole, but I have one instance where the strategy thinks it has entered a trade (supported by confirmation of order.OrderState = Filled and Position.Quantity = 1 both at 22/03/2013 1:07:07 AM in the output window, however Trace Orders shows an internal PlaceOrder has been entered at 21/03/2013 11:59:36 PM.)

    Also, this entry does not appear on the chart. Additionally, at the end of the day the strategy enters a short trade called "Exit on close" (there are no EnterShorts in my strategy) which I assume is to close out the long it thinks it entered into earlier in the day. This new trade is then closed at the open of the next session.

    I'm not too sure what's happening and I wondered if you could help me work it out? I've attached a snippet of the output window below

    Thanks


    Code:
    Time = 22/03/2013 1:07:07 AM
    CB = 393
    NEW STOP = 1.2917
    21/03/2013 11:59:36 PM Entered internal PlaceOrder() method at 21/03/2013 11:59:36 PM: BarsInProgress=1 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.2920 SignalName='Trade393' FromEntrySignal=''
    trade = 1
    CB = 393
    Time = 22/03/2013 1:07:07 AM
    order.Name = Trade393
    order.OrderState = PendingSubmit
    Position.Quantity = 0
    trade = 1
    Time = 22/03/2013 1:07:07 AM
    order.Name = Trade393
    order.OrderState = Accepted
    Position.Quantity = 0
    trade = 1
    Time = 22/03/2013 1:07:07 AM
    order.Name = Trade393
    order.OrderState = Working
    Position.Quantity = 0
    trade = 1
    Time = 22/03/2013 1:07:07 AM
    order.Name = Trade393
    order.OrderState = Filled
    Position.Quantity = 1
    trade = 1
    Time = 22/03/2013 1:59:56 PM
    order.Name = Exit on close
    order.OrderState = PendingSubmit
    Position.Quantity = 1
    trade = 1
    Time = 22/03/2013 1:59:56 PM
    order.Name = Exit on close
    order.OrderState = Accepted
    Position.Quantity = 1
    trade = 1
    Time = 22/03/2013 1:59:56 PM
    order.Name = Exit on close
    order.OrderState = Working
    Position.Quantity = 1
    trade = 1
    Time = 22/03/2013 1:59:56 PM
    order.Name = Exit on close
    order.OrderState = Filled
    Position.Quantity = 0
    trade = 1

    #2
    Chart

    Here's a picture of the chart. The arrow on the left is where the trade should have entered.
    Attached Files

    Comment


      #3
      Hello yeohass,

      When Backtesting or any Historical data processing on bar types like LineBreak, Renko, Range etc can return results that would not reflect what would happen in the real-time market. When running on Historical Data you just get a snap shot of the bar that printed not each tick that made up that bar.

      The most accurate results for testing your strategy is by using the Market Replay feature inside of NinjaTrader. The link below goes over the Market Replay that you may view.


      If you still want to use backtesting you may want to backtest your strategy with intrabar granularity for better fills, and an example of this can be found at the following thread.
      You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


      For information on the discrepancies between real-time versus backtest please visit the following link:


      The following thread also talks about backtesting with Renko Bar types that you may view for an example.
      Support for the development of custom automated trading strategies using NinjaScript.
      JCNinjaTrader Customer Service

      Comment


        #4
        Hi JC

        Thanks for your response.

        I understand the restrictions of backtesting and how it won't always represent real time trading, however my biggest question would be why the strategy seems to be trying to enter the trade at a time that has already passed -
        manually added time stamp states 22/03/2013 1:07:07 AM, however trace order states 21/03/2013 11:59:36 PM.

        Also, just to let you know, I am entering trades intrabar. My strategy has a 1 tick chart added, and it is on this data that trades are entered.

        Thanks

        Comment


          #5
          Hello yeohass,

          The TraceOrder log is going to be when the Enter() method was called on the bar time, not the orders are filled.

          How are you checking your orders manually?
          JCNinjaTrader Customer Service

          Comment


            #6
            Hi,

            I'm using order.OrderState.

            My print functions start with a timestamp (Time[0]). Please take a look at the output snippet in my first post, in particular line 1 vs line 4. Please also note that CB refers to CurrentBar, and on line 2 this is 393, which is the bar on the range chart that completes at 22/03/2013 1:07:07 AM (the same as the timestamp on line 1). So line 4 (the trace order output) is way out of sync?

            Thanks

            Comment


              #7
              Date range

              The other thing I have noticed, is that this behaviour only occurs when the date range of the test data exceeds the date in question (22/03/2013). If my date range doesn't exceed this date, then the trade occurs how it should.

              Attached are two charts with the same strategy applied,
              the first has a date range of 12/03/2013 - 22/03/2013 and the trade occurs as expected,
              the second has a date range of 14/03/2013 - 24/03/2013 and has the strange behaviour occurring.

              Thanks
              Attached Files

              Comment


                #8
                Hello yeohass,

                I believe the Time differences you see are going to coming from Multi-Series that you are using. So for your output it looks like you are Printing out the Time of the Primary Series as I see the "Time = 22/03/2013 1:07:07 AM" before the TraceOrder log that is being reported. The order seems to be placed using one time line and it is being filled in the time line that you are checking the current bar on.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  Thanks JC. I had a think about what you said, and also about my discovery of the impact of different time ranges.

                  I added Times[0][0] and Times[1][0] as two different printouts, and discovered that Times[1][0] is getting "stuck" at 21/03/2013 11:59:36, while Times[0][0] continues. As my strategy is set to enter the trade on BarsArray[1], this would explain why the TraceOrder is showing the trade trying to enter in the past, and not entering.

                  I thought this might be to do with session templates originally, but I have checked the times, and midnight is not a parameter.

                  Any idea why this behaviour is occurring? I have reloaded historical data, but this has not helped.

                  Thanks

                  Comment


                    #10
                    Hello yeohass,

                    It is hard to say, but the easiest way to be able to visualize this and check the data would be to add the Time Frame to the Chart. To conserve memory NinjaTrader will use the Data Series on a chart rather than building it from scratch via script.
                    JCNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    668 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    377 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    110 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    575 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    580 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X