• 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

Problem with Backtesting

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

    Problem with Backtesting

    Hello guys,

    I ve created a strategy that when the high/low of the candle is broken I enter long or short. While it works perfect in real time when I backtest (with tick replay data) and see the executions I realise that some orders were executed on the Close or Open of the previous candle instead high/low.

    Do you know why that could be happening?


    Thanks

    #2
    Hello Sohal,

    Thank you for the post.

    Without more details on the code being used it would be difficult to say what is happening. Can you tell me how are you currently entering, are you supplying a High price for the order or using the Last price?

    If you have a simple example of the basic syntax required to see the difference, that may explain more of what is happening.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Dear Jesse,

      kindly find attached

      Also What should I add inorder to open only one trade per (cme us index future) session
      Attached Files
      Last edited by Sohal; 05-09-2018, 08:58 AM.

      Comment


        #4
        Hello Sohal,

        Thank you for the reply.

        In this case, I see that the condition does reference the High but in this situation, because a market order is being used, the Close or Last price would be used to fill the order. This can cause a variable fill price because the fill would use whatever the Close price at the time the condition became true was in addition to the historical fill rules. In backtesting this can also be displayed differently due to how backtests operate, you can find some common differences in the following page: https://ninjatrader.com/support/help...lightsub=discr

        I also see that you are calling EnterLong with ExitShort, this would create a problematic situation. Because the Position is not updated yet after calling EnterLong, this can cause incorrect positions.

        Your EnterLong will close any existing open short position and reverse it. Otherwise, it would just enter into that direction. The Exit being called after the entry would be unaware of the EnterLong exiting a short position and would try to again exit the position causing an incorrect reversal. Generally, you would just need to call the Entry method to exit and reverse.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Ok Great problem solved.

          Can you also help me with exiting at session close?

          Would like to exit a bit before session close, which is 23.15 here in Greece so would like to exit around 22:59. Which is the best way to exit ?I have problem with backtest execution. Ive added limit order.

          Kindly advice
          Attached Files

          Comment


            #6
            Hello Sohal,

            Thank you for the reply.

            For a simple exit before the session close with a time limit, that is already built into your strategy you would just need to make sure its enabled and set an amount of time. If you are currently using the Exits shown to exit on close, I would likely suggest to instead try using IsExitOnSessionClose without your limits to see if that works as you want.

            Using the Builder, you can configure this in the "Default Properties" page under "More Properties".

            https://ninjatrader.com/support/help...ightsub=isexit
            https://ninjatrader.com/support/help...oseseconds.htm

            You can also define auto close times for specific instruments in the options menu: https://ninjatrader.com/support/help...sitionFunction


            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Already added exit before the session close. But it executes at the beginning of the candle see attachements.
              Attached Files

              Comment


                #8
                Hello Sohal,

                Thank you for the post.

                If this was from a Backtest, this would be correct for exit on close. There is a note about this in the help guide:
                On historical data, IsExitOnSessionCloseStrategy will cause positions to be exited at the close of the last bar of the session.
                Using a Realtime mode such as Playback or just a realtime connection you would instead see the exit occur the number of seconds before the close. This would be one item which is specifically displayed differently in a backtest due to the difference in how the script is being processed.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Oh I see,

                  Also I can only backtest with data up to may/2017.

                  How can I backtest for longer ?

                  Comment


                    #10
                    Hello Sohal,

                    Thank you for the reply.

                    You would need data that spans back that far. Often data providers will only provide a certain period of time for each data type (Tick, Minute, Daily). Depending on the data being used, the time you can go back will be variable.

                    To acquire more data when the data provider does not have more available you would have the options of recording realtime data as historical. Over time you could accrue more data this way. The other alternative would be to import historical data from another source, NinjaTrader allows text data to be imported:


                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by BrandonT1292, 06-17-2019, 03:03 PM
                    2 responses
                    22 views
                    0 likes
                    Last Post thinarthrill  
                    Started by cbentrikin, Yesterday, 07:46 PM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Marco  
                    Started by dr0832, 01-04-2019, 10:34 AM
                    7 responses
                    142 views
                    0 likes
                    Last Post Lancer
                    by Lancer
                     
                    Started by RedDuke, Yesterday, 06:14 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post RedDuke
                    by RedDuke
                     
                    Started by DariusDeck, Yesterday, 04:22 PM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_Marco  
                    Working...
                    X