• 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

backtesting discprenency with forward testing

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

    #16
    Jon, then you would need to debug your strategy conditions, simplify as much as possible to get to the root of the issue. It's also very helpful to add visual confirmations that the code triggered trades, so can easily confirm what is working and what is not.
    BertrandNinjaTrader Customer Service

    Comment


      #17
      Originally posted by NinjaTrader_Bertrand View Post
      Jon, then you would need to debug your strategy conditions, simplify as much as possible to get to the root of the issue. It's also very helpful to add visual confirmations that the code triggered trades, so can easily confirm what is working and what is not.
      Bertrand,

      Like I said the only changes I made in my strategy was going from DateTime.Now to Time[0]. With DateTime.Now I was getting 2 trades and all sorts of text written to the output window. Once I ran the backtest on Time[0], I get absolutely nothing - No trades, No output, Nada.

      Comment


        #18
        Yes, you would need to debug then why this is the case for your conditions and how they are affected by the time reference you use - for example if the time stamp granularity offered by the series you run this on does not allow for an evaluation of your conditions it would not trigger (for example time being exactly equal to 93000 on a tick chart likely creates issues)
        BertrandNinjaTrader Customer Service

        Comment


          #19
          Originally posted by NinjaTrader_Bertrand View Post
          Yes, you would need to debug then why this is the case for your conditions and how they are affected by the time reference you use - for example if the time stamp granularity offered by the series you run this on does not allow for an evaluation of your conditions it would not trigger (for example time being exactly equal to 93000 on a tick chart likely creates issues)
          Bertrand-

          this is the code I'm using:
          PHP Code:
          if(Time[0] > DateTime.Parse(endTime))
                          
          ExitAll("End of TradeDate"); 
          Instead of:
          PHP Code:
          if(DateTime.Now DateTime.Parse(endTime))
                          
          ExitAll("End of TradeDate"); 
          I'm running this backtest on a 1 minute bar, so as soon as Time[0] is greater than the endTime (user-supplied variable) it should call ExitAll. This code never gets hit. I suspect there is something wrong with my comparison OR with the Time[0] construct.

          Also, just be clear, NT will NOT be able to support tick-based backtest runs, correct? Because COBC is defaulted to true? Even if I set the timeframe to 1-tick?

          Comment


            #20
            Jon, both Time[0] and DateTime.Now would return DateTime structures, try printing all associated components.

            Do this snippet below work you? endTime is just a user supplied int here, as we're not working with DateTime structures.

            Code:
             protected override void OnBarUpdate()
                    {
            			if (Historical) return;
            			
            			if (ToTime(Time[0]) > endTime)
            				EnterLong();
            			
            			Print(DateTime.Now);
            			Print(Time[0]);
                    }
            Whatever chart you're on - CalculateOnBarClose is true in backtesting. If you then backtest with 1 tick chart as primary chart, you could simulate intrabar fills of course if you also simulate the higher timeframe bar in your code to trigger your trades on.
            BertrandNinjaTrader Customer Service

            Comment


              #21
              Originally posted by NinjaTrader_Bertrand View Post
              Jon, both Time[0] and DateTime.Now would return DateTime structures, try printing all associated components.

              Do this snippet below work you? endTime is just a user supplied int here, as we're not working with DateTime structures.

              Code:
               protected override void OnBarUpdate()
                      {
                          if (Historical) return;
                          
                          if (ToTime(Time[0]) > endTime)
                              EnterLong();
                          
                          Print(DateTime.Now);
                          Print(Time[0]);
                      }
              Whatever chart you're on - CalculateOnBarClose is true in backtesting. If you then backtest with 1 tick chart as primary chart, you could simulate intrabar fills of course if you also simulate the higher timeframe bar in your code to trigger your trades on.
              Bertrand,

              Thanks. That does work for me.

              Thanks again!
              jonmoron

              Comment


                #22
                Bertrand,

                So all this talk about not getting 'intra-bar' fills in NT is hogwash? I've heard many people say that the NT backtester is sub-par because you will not get any intra-bar fills. But if I start a backtest and set the bars to 1-tick, the code will work on each tick, correct (assuming I have tick-data)?

                Also, I seem to still have a problem with comparing time. This is what I want to do. I want to enter the market at a time (say 8:20am) and exit the market at another time (say 3:10pm). Those variables are set by the user. However, what seems to be happening, is after day 1 completes, I never am able to enter the market any other day (at 8:20 am) on a backtest.

                Any suggestions?

                thanks!
                jon

                Comment


                  #23
                  Jon,

                  If you decide to run on a 1 tick series which is extremely taxing on system resources, yes it would be a 1-tick backtest.

                  To enter at 8:20AM you would actually have to have a bar with that exact time as the timestamp of the bar. When you check for something like if (ToTime(Time[0]) == 82000) you are looking for an exact match of the timestamp of the bar versus 8:20AM. If you are using tick data this may not be the case as each bar could have varying timestamps depending on when the tick came in. You would then need to set up an acceptable time range for the timestamps to be within. Note that setting up a range can result in multiple bars being true for the condition.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #24
                    Originally posted by NinjaTrader_Josh View Post
                    Jon,
                    To enter at 8:20AM you would actually have to have a bar with that exact time as the timestamp of the bar. When you check for something like if (ToTime(Time[0]) == 82000) you are looking for an exact match of the timestamp of the bar versus 8:20AM. If you are using tick data this may not be the case as each bar could have varying timestamps depending on when the tick came in. You would then need to set up an acceptable time range for the timestamps to be within. Note that setting up a range can result in multiple bars being true for the condition.
                    Josh,

                    I understand. In fact in my code I check for ToTime(Time[0]) > ToTime(DateTime.Parse("startTime")). startTime is defined as 8:20. I
                    then enter the market. I also check if I've already entered and do not re-enter. This actually works beautifully in forward testing and goes in perfectly and not again after the next tick that comes in at 8:20.

                    In fact the entire strategy works just fine. When the trade-date ends (3:10pm), I do a similar exit-time check and then exit the market (resetting the previous boolean to prepare for the next day entry).

                    However this is when the entry logic is checked (3:11pm is greater than 8:20am) and re-enters. I want to re-enter the market on the NEXT trading day. Does this make sense?

                    thanks!
                    jon

                    Comment


                      #25
                      In essence, is there a way for me to close the strategy for the day and open it up for business the next day?

                      Comment


                        #26
                        Then in addition to your time checks I would add some date checks with ToDay(). http://www.ninjatrader-support.com/H...ide.html?ToDay

                        When the dates change only then can you reenter. Otherwise, don't allow retrading.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #27
                          Originally posted by NinjaTrader_Josh View Post
                          Then in addition to your time checks I would add some date checks with ToDay(). http://www.ninjatrader-support.com/H...ide.html?ToDay

                          When the dates change only then can you reenter. Otherwise, don't allow retrading.
                          Sounds good. I'll try that.

                          thanks!
                          jon

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by henit, 08-24-2019, 09:10 AM
                          3 responses
                          40 views
                          0 likes
                          Last Post guidoisot  
                          Started by zoreanuv, Today, 01:14 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post zoreanuv  
                          Started by profitabletrader306, Today, 12:00 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post profitabletrader306  
                          Started by marcelodelta, Yesterday, 08:28 PM
                          2 responses
                          11 views
                          0 likes
                          Last Post marcelodelta  
                          Started by junkone, Yesterday, 09:06 PM
                          1 response
                          11 views
                          0 likes
                          Last Post NinjaTrader_Marco  
                          Working...
                          X